📄 subdigraph.java
字号:
// subWorkArea.add(initVertexFocus); vertices.add(initVertexFocus); // reset the focus // resetVertexFocus(); return; } } } // did the user click on a vertex with the right mouse button? // if (e.getSource().getClass().getName().equals("Vertex")) { if(SwingUtilities.isRightMouseButton(e)) { // if the user clicked on a vertex reset the arc enables // enableArcInsertion = false; enableArcDeletion = false; // get the vertex that is being referenced // cfgVertexFocus = (Vertex)e.getSource(); // display the popup menu based on the vertex type // popup.show(e.getComponent(), e.getX(), e.getY()); // reset the focus // resetVertexFocus(); return; } } // did the user click on a vertex with the left mouse button? // if (e.getSource().getClass().getName().equals("Vertex")) { if (SwingUtilities.isLeftMouseButton(e)) { // updates the vertex focus to highlight the current parent // updateVertexFocus(e); // exit the method if the vertex child is not instantiated // if (vertexChild == null) { return; } // the input vertices cannot have incoming arcs // if (vertexChild.getVertexImpl() == INPUT) { Toolkit.getDefaultToolkit().beep(); resetVertexFocus(); return; } // check for self loops and exit if it exists // if (vertexChild == vertexParent) { Toolkit.getDefaultToolkit().beep(); resetVertexFocus(); return; } // make sure are drawing is enabled // if (!enableArcInsertion) { resetVertexFocus(); return; } // check for forward and backward edges // if (vertexParent.containsChild(vertexChild)) { forwardLink = true; } if (vertexChild.containsChild(vertexParent)) { reverseLink = true; } // if neither a forward nor backward link exist add // the connector // if (!forwardLink && !reverseLink) { // add the parent from the child lis and vice-versa // vertexParent.addChild(vertexChild); vertexChild.addParent(vertexParent); } // reset the vertex parent and vertex child pointers // resetVertexFocus(); } } // update the work area // subWorkArea.repaint(); } // method: mousePressed // // arguments: // MouseEvent e: (input) event that was fired // return: none // public void mousePressed(MouseEvent e) { // did the user click on a vertex with the left mouse button? // if (e.getSource().getClass().getName().equals("Vertex")) { if (SwingUtilities.isLeftMouseButton(e)) { currVertexFocus = (Vertex)e.getSource(); } } // repaint the work area // subWorkArea.repaint(); } // method: mouseDragged // // arguments: // MouseEvent e: (input) event that was fired // return: none // public void mouseDragged(MouseEvent e) { // declare local variables // int xdelta = 0; int ydelta = 0; int newWidth = 0; int newHeight = 0; boolean forwardLink = false; boolean reverseLink = false; // did the user click on a vertex with the left mouse button? // if (e.getSource().getClass().getName().equals("Vertex")) { if (SwingUtilities.isLeftMouseButton(e)) { // get the current location of the vertex // if (currVertexFocus != null) { // determine the location and width of the vertex // Point loc = currVertexFocus.getVertexLocation(); int vertexWidth = currVertexFocus.getVertexWidth(); int vertexHeight = currVertexFocus.getVertexHeight(); int xloc = (loc.x + e.getX() - (vertexWidth / 2)); int yloc = (loc.y + e.getY() - (vertexHeight / 2)); int xloc1 = loc.x + e.getX() + (vertexWidth / 2); int yloc1 = loc.y + e.getY() + (vertexHeight / 2); // make sure the user does not move the vertex out of // the work area // if ((xloc >= 0) && (yloc >= 0)) { // determine the new width for the work area // if (xloc1 > subWorkArea.getWidth()) { xdelta = xloc1 - subWorkArea.getWidth(); newWidth = subWorkArea.getWidth() + xdelta; } // determine the new height for the work area // if (yloc1 > subWorkArea.getHeight()) { ydelta = yloc1 - subWorkArea.getHeight(); newHeight = subWorkArea.getHeight() + ydelta; } // update the scroll bars of the work area // if ((xloc1 >= subWorkArea.getWidth()) || (yloc1 >= subWorkArea.getHeight())) { // scroll the work area to the new region // Rectangle rect = new Rectangle(xloc, yloc, vertexWidth, vertexHeight); subWorkArea.scrollRectToVisible(rect); // make sure that the width and does not // decrease, i.e., it does not scroll back // if (newWidth <= maxWidth) { newWidth = maxWidth; } else { maxWidth = newWidth; } // make sure that the height and does not // decrease, i.e., it does not scroll back // if (newHeight <= maxHeight) { newHeight = maxHeight; } else { maxHeight = newHeight; } // update client's preferred size because the area // taken up by the work area has gotten larger // subWorkArea.setPreferredSize(new Dimension(newWidth, newHeight)); // let the scroll pane know to update itself // and its corresponding scroll bars // subWorkArea.revalidate(); } // drag the vertex to the location the user specifies // currVertexFocus.setLocation(xloc, yloc); currVertexFocus.updateLocation(xloc, yloc); // repaint the work area // subWorkArea.repaint(); } } // when the arc insertion is enabled // if (enableArcInsertion) { // updates the vertex focus to highlight the current parent // updateVertexFocus(e); // exit the method if the vertex child is not instantiated // if (vertexChild == null) { return; } // the input vertices cannot have incoming arcs // if (vertexChild.getVertexImpl() == INPUT) { Toolkit.getDefaultToolkit().beep(); resetVertexFocus(); return; } // the output vertices cannot have outgoing arcs // if(vertexParent.getVertexImpl() == OUTPUT) { Toolkit.getDefaultToolkit().beep(); resetVertexFocus(); return; } // check for self loops and exit if it exists // if (vertexChild == vertexParent) { Toolkit.getDefaultToolkit().beep(); resetVertexFocus(); return; } // check for forward and backward edges // if (vertexParent.containsChild(vertexChild)) { forwardLink = true; } if (vertexChild.containsChild(vertexParent)) { reverseLink = true; } // if neither a forward nor backward link exist add // the connector // if (!forwardLink && !reverseLink) { // add the parent from the child lis and vice-versa // vertexParent.addChild(vertexChild); vertexChild.addParent(vertexParent); } // reset the vertex parent and vertex child pointers // resetVertexFocus(); } // repaint the work area // subWorkArea.repaint(); } } } // method: mouseReleased // // arguments: // MouseEvent e: (input) event that was fired // return: none // public void mouseReleased(MouseEvent e) { // not implemented } // method: mouseMoved // // arguments: // MouseEvent e: (input) event that was fired // return : none // public void mouseMoved(MouseEvent e) { // update the location of the mouse coordinates // mouseXloc = e.getX(); mouseYloc = e.getY(); } // method: mouseExited // // arguments: // MouseEvent e: (input) event that was fired // return : none // public void mouseExited(MouseEvent e) { // this method is required to be present } // method: mouseEntered // // arguments: // MouseEvent e: (input) event that was fired // return : none // public void mouseEntered(MouseEvent e) { // this method is required to be present } // method: actionPerformed // // arguments: // ActionEvent e: event that was fired // // return : none // // listens for actions taking place on the components // public void actionPerformed(ActionEvent e) { // detremine if the delete option was selected // if (e.getActionCommand().equals(delete)) { removeVertex(cfgVertexFocus); } // determine if the configuration option was selected // else if (e.getActionCommand().equals(ordering)) { // create a new configuration box and display in a new frame // if (cfgVertexFocus != null) { ConfigBoxSub config_box = new ConfigBoxSub(this, data, cfgVertexFocus, subWorkArea, 1); config_box.pack(); config_box.setVisible(true); } } // determine if the configuration option was selected // else if (e.getActionCommand().equals(configuration)) { // create a new configuration box and display in a new frame // if (cfgVertexFocus != null) { ConfigBoxSub config_box = new ConfigBoxSub(this, data, cfgVertexFocus, subWorkArea, 0); config_box.pack(); config_box.setVisible(true); } } // detremine if the update was selected // else if (e.getActionCommand().equals(update)) { // check to see if a vertex with this label exists // if (coeffLables.contains(nameField.getText())) { // display a warning message indicating that you cannot have // two vertices with the same name // JFrame frame = new JFrame("Warning"); JOptionPane.showMessageDialog(frame, "A node with the label " + nameField.getText() + " already exists"); return; } // remove the old and add the new label // coeffLables.remove(cfgVertexFocus.getText()); coeffLables.addElement(nameField.getText()); // update the vertex text with what the user entered // if (nameField.getText().length() > 3) { cfgVertexFocus.setText(nameField.getText().substring(0, 3)); } else { cfgVertexFocus.setText(nameField.getText()); } cfgVertexFocus.setVertexName(nameField.getText()); // remove the frame from the screen // config.setVisible(false); } // detremine if the cancel was selected // else if (e.getActionCommand().equals(cancel)) { // remove the frame from the screen // config.setVisible(false); } // repaint the work area // subWorkArea.repaint(); }}//// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -