📄 subdigraph.java
字号:
// determine which algorithm fired the event // int action = data.association.indexOf(algorithmstr); // if the action is found in the list of transforms // if (action != -1) { String image_name = null; String image_association= null; String icon_name = null; // tells the program which transform it is looking to match // image_association = algorithmstr; // scans through the association until // it finds the largeIcon key // for(int j=data.association.indexOf(image_association); j <= data.association.lastIndexOf(image_association); j++) { if (j != -1) { if (((String)(data.name.get(j))).equals(ALGORITHM_ICON_BIG)) { // sets the image_name to the value held // in large icon // image_name = (String)data.values.elementAt(j); } if (((String)(data.name.get(j))).equals("iconName")) { // sets the image_name to the value held // in large icon // icon_name = (String)data.values.elementAt(j); } } } // check to see if the file exists. If it does not exist, // use a default image. // if(image_name != null) { File image_file = new File(image_name); if (image_file.exists() == false) image_name = ALGORITHM_DEFAULT; } else { image_name = ALGORITHM_DEFAULT; } // create the vertex for the work area // ImageIcon vertex_icon = new ImageIcon(image_name); Vertex vertex = new Vertex(vertex_icon , ALGORITHM); vertex.setVertexName(algorithmstr); if (algorithmstr.length() > 4) { vertex.setText(algorithmstr.substring(0, 4)); } else { vertex.setText(algorithmstr); } if(algorithmstr.equals("Generator")) { vertex.setText(""); vertex.setVertexImpl(INPUT); } if(algorithmstr.equals("FilterBank")) { vertex.setText("FilB"); } if(icon_name != null) { vertex.setText(icon_name); vertex.setIconName(icon_name); } // to simplify the creation, the data vectors will be // trimmed to only include the transform we're looking // at and saved into these three vectors for use in a // bit // Vector labels = new Vector(5,5); Vector types = new Vector(5,5); Vector values = new Vector(5,5); for(int j=data.association.indexOf(image_association); j <= data.association.lastIndexOf(image_association); j++) { if(j != -1) { labels.add(data.name.get(j)); types.add(data.type.get(j)); values.add(data.values.get(j)); } } // initialize the vertex to the default values for its type // vertex.initializeConfig(labels, values, types, image_association, data); // set the tool tip for the algorithm vertex // vertex.setToolTipText(vertex.association); // attach a mouse motion listener to the vertex // vertex.addMouseListener(this); vertex.addMouseMotionListener(this); // set the current vertex selected // initVertexFocus = vertex; } } // method: removeVertex // // arguments: // Vertex target: (input) vertex to be removed // returns : none // // method that removes the specified vertex from the work area as // well as removing all parent and corresponding children links // public void removeVertex(Vertex target) { // verify that the vertex to be deleted is valid // if (target == null) { return; } // reset the vertex focus // resetVertexFocus(); // get the parents of the traget and all accurances of target // Vector parents = target.getParents(); for (int i=0; i<parents.size(); i++) { if (((Vertex)(parents.elementAt(i))).containsChild(target)) { ((Vertex)(parents.elementAt(i))).removeChild(target); } } // get the children of the traget and all accurances of target // Vector children = target.getChildren(); for (int i=0; i<children.size(); i++) { if (((Vertex)(children).elementAt(i)).containsParent(target)) { ((Vertex)(children.elementAt(i))).removeParent(target); } } // remove the node form the work area // subWorkArea.remove(target); vertices.remove(target); // remove the label from the vector depending on the implementation // coeffLables.remove(target.getText()); // repaint the work area // subWorkArea.repaint(); } // method: cut // // arguments: none // returns : none // // method cuts the current vertex and adds it to the clipboard // public void cut() { // check for a valid vertex // if (currVertexFocus == null) { return; } // clear the current contents of the clipboard // clipboard.removeAllElements(); // add the vertex to the clipboard // clipboard.addElement(currVertexFocus); // remove the vertex // removeVertex(currVertexFocus); // repaint the work area // subWorkArea.repaint(); } // method: copy // // arguments: none // returns : none // // method copies the current vertex and adds it to the clipboard // public void copy() { // check for a valid vertex // if (currVertexFocus == null) { return; } // clear the current contents of the clipboard // clipboard.removeAllElements(); // add the vertex to the clipboard // clipboard.addElement(currVertexFocus); // repaint the work area // subWorkArea.repaint(); } // method: paste // // arguments: none // returns : none // // method pastes the current vertex from the clipboard // public void paste() { // loop through each element in the clipboard and add them back // for(int i=0; i < clipboard.size(); i++) { // create a copy of the vertex and remove all arcs // Vertex vertex = new Vertex((Vertex)clipboard.elementAt(i)); vertex.vertexParents.removeAllElements(); vertex.vertexChildren.removeAllElements(); // attach a mouse motion listener to the vertex // vertex.addMouseListener(this); vertex.addMouseMotionListener(this); // set the font for the vertex // vertex.setFont(newCoeffFont); // set the location of the vertex // Point coordinates = new Point(mouseXloc, mouseYloc); vertex.setLocation(coordinates); // add the element to the data structures // vertices.addElement(vertex); subWorkArea.add(vertex); } // repaint the work area // subWorkArea.repaint(); } // method: clearAllMemory // // arguments: none // returns : none // // method clears out all memory, i.e., vectors and hash tables // public void clearAllMemory() { // reset the maximum number of vertices // maxInputVertices = 0; // reset the vertices // initVertexFocus = null; cfgVertexFocus = null; currVertexFocus = null; vertexParent = null; vertexChild = null; // clear out all vectors // vertices.removeAllElements(); coeffLables.removeAllElements(); clipboard.removeAllElements(); // clear out the work area // subWorkArea.removeAll(); // add the start and term vertices back // initVertices(); } // --------------------------------------------------- // // class required methods // // --------------------------------------------------- // method: mouseClicked // // arguments: // MouseEvent e: (input) event that was fired // return: none // public void mouseClicked(MouseEvent e) { // declare local variables // boolean forwardLink = false; boolean reverseLink = false; Vertex conChild = null; Vertex conParent = null; // did the user click on the subWorkArea with the left mouse button? // if (e.getSource().getClass().getName().equals("SubWorkArea")) { // reset the current focus // currVertexFocus = null; if (SwingUtilities.isLeftMouseButton(e)) { // declare local variables // double smallestDistance = Double.MAX_VALUE; Vertex smallestParent = null; Vertex smallestChild = null; // has the arc deletion option been enabled? // if (enableArcDeletion) { // iterate through all vertices // for (int i=0; i<vertices.size(); i++) { // get the vertex which we will call the parent // Vertex delParent = (Vertex)vertices.elementAt(i); Vector delChildren = delParent.vertexChildren; // get the children associated with the parent // for (int j=0; j<delChildren.size(); j++) { // get a child of the current parent // Vertex delChild = (Vertex)delChildren.elementAt(j); // find the distance to the point of intersection // between the arc and the normal to the arc // Point ploc = delParent.getVertexLocation(); Point cloc = delChild.getVertexLocation(); // get the arc start coordinates // int x1 = ploc.x + (delParent.getVertexWidth() / 2); int y1 = maxHeight - ploc.y + (delParent.getVertexHeight() / 2); // get the arc stop coordinates // int x2 = cloc.x + (delChild.getVertexWidth() / 2); int y2 = maxHeight - cloc.y + (delChild.getVertexHeight() / 2); // get the slope of the line // double m1 = 0.000000001; double dy = (double)(y2-y1); double dx = (double)(x2-x1); if (x2 != x1) { m1 = dy/dx; } double m11 = -1/m1; // get the coordinates of the mouse click // int x = e.getX(); int y = maxHeight - e.getY(); // get the point of intersection // double x0 = ((-m11*x)+y+(m1*x1)-y1)/(m1-m11); double y0 = (m11*x0)-(m11*x)+y; // get the distance from the mouse click to the // point where the norlam intersects the line // double dist = Math.sqrt(Math.abs(((x-x0)*(x-x0))+((y-y0)*(y-y0)))); if (dist < smallestDistance) { smallestDistance = dist; smallestParent = delParent; smallestChild = delChild; } } } // delete the arc that matches the constraints // if (smallestDistance > 0) { if ((smallestParent != null) && (smallestChild != null)) { smallestParent.removeChild(smallestChild); smallestChild.removeParent(smallestParent); } } // reset and repaint // resetVertexFocus(); return; } // is the newly created vertex valid? // if (initVertexFocus != null) { // get the current cursor's location // Point location = e.getPoint(); // retrieve the vertex dimensions // int vertexWidth = initVertexFocus.getVertexWidth(); int vertexHeight = initVertexFocus.getVertexHeight(); // center the vertex around the mouse cursor // location.x = location.x - (vertexWidth / 2); location.y = location.y - (vertexHeight / 2); // set the location of the vertex // initVertexFocus.setLocation(location); // add the vertex to the work area
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -