📄 digraph.java
字号:
// file: DiGraph.java//// import java libraries//import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import java.util.*;import java.io.*;import java.lang.*;import java.net.*;public class DiGraph extends JFrame implements ActionListener, MouseListener, MouseMotionListener, Constants { // --------------------------------------------------- // // declare class member data // // --------------------------------------------------- // keep track the curren vertex in focus // public Vertex systemVertex = null; public Vertex inVertex = null; public Vertex outVertex = null; public Vertex initVertexFocus = null; public Vertex cfgVertexFocus = null; public Vertex currVertexFocus = null; // differentiate between parent and child // public Vertex vertexParent = null; public Vertex vertexChild = null; // various types of been in the work area // public Vector vertices = null; public Vector coeffLabels = null; public Vector dataLabels = null; // temporary vertex arc parameters // public String tmpepi = null; public String tmpweight = null; // flag that enables insertion and removal of arcs // public boolean enableArcInsertion = false; public boolean enableSelfArcInsertion = false; public boolean enableArcDeletion = false; // flag that determines if input block exists // public boolean inputBlockExist = false; // flag that determines if output block exists // public boolean outputBlockExist = false; // target of the front end for output data type // public String targetStr = null; // input data type // public String inputDataStr = SAMPLED_DATA_STR; // current save status flag // public boolean saveWork = false; // vector of selected vertices // public Vector selectedVertices = null; // clipboard to handle things like cut, copy and paste // public Vector clipboard = null; // hash tables for quick reference // public Hashtable tagToVertex = null; // holds the maximum width and height of the scroller // public int maxWidth = WORKAREA_WIDTH; public int maxHeight = WORKAREA_HEIGHT; // holds the current location of the mouse // public int mouseXloc = 0; public int mouseYloc = 0; public int line_index = 0; // border for the viewport of the scrollpane // public Border border = null; // the label of the vertex that has been selected form the tool bar // public String currVertexLabel= null; // record the maximum number of inputs generated // public int maxInputVertices = 0; // algorithm association for the processes // public Association currAssociation = null; // maximum width and height of the work area // public int loadWidthMax = Integer.MIN_VALUE; public int loadHeightMax = Integer.MIN_VALUE; // input/output block type and impl // public int iotype = -1; public int ioimpl = -1; // varaible name in input block // public String inputVariable = null; // varaible name in output block // public String outputVariable = null; // creates a fram to manipulate the configuration options // public JFrame config = null; // textfields and labels for the connector properties // public JLabel toLabel = null; public JLabel fromLabel = null; public JLabel nameLabel = null; public JTextField toField = null; public JTextField fromField = null; public JTextField nameField = null; // main menu for functionality // public MainMenu mainMenu = null; // work area to drag and drop components // public WorkArea workArea = null; // paramenet file to be written to // public File paramFile = null; // graph file to be written to // public File graphFile = null; // JSGF file to be written to // public File JSGFFile = null; // lmTester file to be tested // public File lmtesterFile = null; // scroll bars for the work area // public JScrollPane scroller = null; // declare the popup menu objects // public JPopupMenu popup = null; public JMenuItem menuItem = null; // default strings for the popup menus // public String ordering = null; public String delete = null; public String expand = null; public String configuration = null; public String label = null; public String apply = null; public String update = null; public String cancel = null; public String saveApprove = null; public String loadApprove = null; // data object for reading the algorithm resource file // public Data data = null; // arc objects for stroring vertex (from), vertex (to), weights, and // epsilon public GraphArc graphArc = null; // wordSymbol // public Vector wordSymbol = null; // wordVertex // public Vector wordVertex = null; // nodeInfo in the digraph // public Vector graphInfo = null; // --------------------------------------------------- // // declare class constructors // // --------------------------------------------------- // method: DiGraph // // arguments: none // returns : none // public DiGraph(String title) { // invoke the parent default constructor // super(title); //instantiate the data class // data = new Data(); // initialize the arc class // graphArc = new GraphArc(); // initialize the vectors data members // vertices = new Vector(100, 50); coeffLabels = new Vector(100, 50); dataLabels = new Vector(100, 50); clipboard = new Vector(10, 10); selectedVertices = new Vector(100, 50); // initialize the hashtables // tagToVertex = new Hashtable(50); // instantiate the process algorithm association // currAssociation = new Association(); // initialize the popup menu strings // ordering = new String("Ordering"); delete = new String("Delete"); configuration = new String("Configuration"); // create the popup menu for the process vertex // popup = new JPopupMenu(); menuItem = new JMenuItem(configuration); menuItem.addActionListener(this); popup.add(menuItem); popup.addSeparator(); menuItem = new JMenuItem(ordering); menuItem.addActionListener(this); popup.add(menuItem); menuItem = new JMenuItem(delete); menuItem.addActionListener(this); popup.add(menuItem); // set the font of the popup menu // popup.setFont(newCoeffFont); // create the menu to control functionality // mainMenu = new MainMenu(this); // create a work area to drag and drop components // workArea = new WorkArea(vertices, this); workArea.addMouseListener(this); workArea.addMouseMotionListener(this); // add scroll panes to the workarea // scroller = new JScrollPane(workArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); // set the dimensions of the scroller // scroller.setPreferredSize(new Dimension(MAX_WIDTH, MAX_HEIGHT)); // add the components // this.getContentPane().add(mainMenu, BorderLayout.NORTH); this.getContentPane().add(scroller, BorderLayout.CENTER); mainMenu.add_components(); // create and initialize input configuration vertex // inVertex = new Vertex("system", ALGORITHM, NONE); inVertex.association = "Audio_Input"; // 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); for(int j=data.association.indexOf(inVertex.association); j <= data.association.lastIndexOf(inVertex.association); 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 // inVertex.initializeConfig(labels2, values2, types2, inVertex.association, data); // create and initialize output configuration vertex // outVertex = new Vertex("system", ALGORITHM, NONE); outVertex.association = "Audio_Output"; // 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 labels3 = new Vector(5,5); Vector types3 = new Vector(5,5); Vector values3 = new Vector(5,5); for(int j=data.association.indexOf(outVertex.association); j <= data.association.lastIndexOf(outVertex.association); j++) { if(j != -1) { labels3.add(data.name.get(j)); types3.add(data.type.get(j)); values3.add(data.values.get(j)); } } // initialize the vertex to the default values for its type // outVertex.initializeConfig(labels3, values3, types3, outVertex.association, data); } // method: resetVertexFocus // // arguments: none // return: none // // resets the parent and child relationships // public void resetVertexFocus() { // reset the parent and child focus // vertexChild = null; vertexParent = null; // reset the current vertex selected // initVertexFocus = null; currVertexFocus = null; // reset the arc enables // enableArcInsertion = false; enableSelfArcInsertion = false; enableArcDeletion = false; // repaint the workarea // workArea.repaint(); } // method: updateVertexFocus // // arguments: // MouseEvent e: (input) input mouse event // return: none // // updates the parent and child relationships // public void updateVertexFocus(MouseEvent e) { // check to make sure that the vertex parent is valid // if (vertexParent == null) { // highligh the current vertex parent // vertexParent = (Vertex)e.getSource(); } // initialize the child if the vertex parent is valid // else { // initialize the child of the connection // vertexChild = (Vertex)e.getSource(); } } // method: createAlgorithm // // arguments: // String algorithmstr: name of the algorithm that fired the event // returns: none // // this method creates an algorithm object // public void createAlgorithm(String algorithmstr) { // 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 = CONTAINER_IMAGE; } else { image_name = CONTAINER_IMAGE; } // 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(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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -