📄 digraph.java
字号:
// 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 (image_name != null) { File image_file = new File(image_name); if (image_file.exists() == false) { image_name = ALGORITHM_SMALL_DEFAULT; } } else { image_name = ALGORITHM_LARGE_DEFAULT; } // create the vertex and add it to the vector // ImageIcon vertex_icon = new ImageIcon(image_name); if(image_association.equals("Generator")) { vertex_icon = new ImageIcon(GENERATOR_IMAGE); } if(image_association.equals("FourierTransform")) { image_name = GUI_PATH +"/lib/images/isip_transform_builder/icons/algorithm_00.gif"; vertex_icon = new ImageIcon(image_name); } Vertex algoVertex = new Vertex(vertex_icon , ALGORITHM); algoVertex.setVertexName(name); if (name.length() > 4) { algoVertex.setText(name.substring(0, 4)); } else { algoVertex.setText(name); } if(image_association.equals("Generator")) { algoVertex.setText("") ; } if(image_association.equals("FilterBank")) { algoVertex.setText("FilB"); } if(icon_name != null) { algoVertex.setText(icon_name); algoVertex.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 labels2 = new Vector(5,5); Vector types2 = new Vector(5,5); Vector values2 = new Vector(5,5); start = data.association.indexOf(image_association); stop = data.association.lastIndexOf(image_association); for(int j=start; j <= stop; j++) { if(j != -1) { labels2.add(data.name.get(j)); types2.add(data.type.get(j)); values2.add(data.values.get(j)); } } // initialize the vertex to the default values for its type // if(image_association.equals("GENERATOR")) { algoVertex.initializeConfigGen(labels2, values2, types2, image_association, data); } else { algoVertex.initializeConfig(labels2, values2, types2, image_association, data); } // return the initialize vertex // return algoVertex; } // 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 // workArea.remove(target); vertices.remove(target); // remove the label from the vector depending on the implementation // if (target.association.equals("AudioFrontEnd")) { iotype = -1; inputBlockExist = false; } else if (target.getVertexImpl() == OUTPUT) { dataLabels.remove(target.getText()); iotype = -1; outputBlockExist = false; dataLabels.remove(OUTPUT_STR); } else { coeffLabels.remove(target.getText()); } // repaint the work area // workArea.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 // workArea.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; } // we cannot copy and paste SAMPLED_DATA and FEATURE // vertices, hence, we check for them here // if ((currVertexFocus.getVertexType() == INPUT) || (currVertexFocus.getVertexType() == OUTPUT)) { JFrame frame = new JFrame("Warning"); JOptionPane.showMessageDialog(frame, "You cannot paste Input or output block"); return; } if (currVertexFocus.association.equals("AudioFrontEnd")) { JFrame frame = new JFrame("Warning"); JOptionPane.showMessageDialog(frame, "You cannot paste Input or output block"); return; } // clear the current contents of the clipboard // clipboard.removeAllElements(); // add the vertex to the clipboard // clipboard.addElement(currVertexFocus); // repaint the work area // workArea.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++) { // get the vertex that we intend to paste // Vertex v = (Vertex)clipboard.elementAt(i); // create a copy of the vertex and remove all arcs // Vertex vertex = new Vertex(v); // remove all parents and children associated with the vertex // 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); // we need create a unique name for the current vertex // if it is of type CUSTOM or CONTAINER // if ((vertex.getVertexType() == CUSTOM) || (vertex.getVertexType() == CONTAINER)) { // when the old name does not exist reuse it // if (!coeffLabels.contains(vertex.getText())) { currVertexLabel = vertex.getText(); } // when the old name exist create a new copy // else { int offset = -1; currVertexLabel = vertex.getText(); while (coeffLabels.contains(currVertexLabel)) { offset++; currVertexLabel = vertex.getText() + offset; } } // set the name of the vertex // if (currVertexLabel.length() > 3) { vertex.setText(currVertexLabel.substring(0, 3)); } else { vertex.setText(currVertexLabel); } vertex.setVertexName(currVertexLabel); coeffLabels.addElement(currVertexLabel); } // add the element to the data structures // vertices.addElement(vertex); workArea.add(vertex); } // repaint the work area // workArea.repaint(); } // method: expandContainer // // arguments: none // returns : none // // method expand the container vertex // public void expandContainer() { // check for validity // if (currVertexFocus == null) { return; } if (currVertexFocus.getVertexType() != CONTAINER) { return; } // declare the sub digraph // String title = new String("CONTAINER"); SubDiGraph subdigraph = new SubDiGraph(title, currVertexFocus.vertexContainer); // resize and set the frame dimensions // subdigraph.pack(); // center the frame to the screen // Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle frameDim = subdigraph.getBounds(); subdigraph.setLocation((screenDim.width - frameDim.width + 100) / 2, (screenDim.height - frameDim.height + 100) / 2); // display the frame // subdigraph.setVisible(true); } // 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; inputBlockExist = false; outputBlockExist = false; // clear out all vectors // vertices.removeAllElements(); coeffLabels.removeAllElements(); dataLabels.removeAllElements(); clipboard.removeAllElements(); selectedVertices.removeAllElements(); // reset the current line index // line_index = 0; // clear out all hash tables // tagToVertex.clear(); // clear out the work area // workArea.removeAll(); } // method: write // // arguments: none // return : none // // writes the sof file // public void write() { // declare local variables // FileOutputStream fout = null; PrintWriter file = null; String line = null; // reset the save flag to indicate the obvious // saveWork = false; // open the selected file for writing // try { // initialize the variables // line = new String(); // initialize the file output stream // fout = new FileOutputStream(paramFile); file = new PrintWriter(fout); // write the file header // file.println(HEADER_TAG_00); file.println(HEADER_TAG_01); file.println(); // write the system configuration parameters // writeSystem(file); file.println(); // write the vertex data // for (int i=0; i < vertices.size(); i++) { // get the current vertex // Vertex vertex = (Vertex)vertices.elementAt(i); // write the data data if the vertex is a data // if ((vertex.getVertexType() == INPUT) || (vertex.getVertexType() == OUTPUT) || (vertex.getVertexType() == CUSTOM)) { // write the data tag // line = ALGO_TAG + " " + vertices.indexOf(vertex) + " @"; file.println(line); // write the data's location // Point point = vertex.getLocation(); file.println(LOCATION_KEY + " " + point.x + " " + point.y); // write the name tag // line = " name = " + BUFFER_TAG + ";"; file.println(line); // write the variable tag // if (vertex.getVertexType() == CUSTOM) { line = " variable = " + vertex.getVertexName() + ";"; file.println(line); } else if (vertex.getVertexType() == OUTPUT ) { line = " variable = " + "Output" + ";"; file.println(line); } else { line = " variable = " + inputVariable + ";"; file.println(line); } // write the implementation // if (vertex.getVertexImpl() == INPUT) { line = " type = " + INPUT_STR + ";"; file.println(line); file.println(); } else if (vertex.getVertexImpl() == OUTPUT) { line = " type = " + OUTPUT_STR + ";"; file.println(line); file.println(); } else { line = " type = " + INTERNAL_STR + ";"; file.println(line); file.println(); } } } // write the algorithm data if the vertex is a container // for (int i=0; i < vertices.size(); i++) { // get the current vertex // Vertex vertex = (Vertex)vertices.elementAt(i); if (vertex.getVertexType() == CONTAINER) { // write the container tag // int containerTag = vertices.indexOf(vertex);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -