📄 subdigraph.java
字号:
// file: SubDiGraph.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 SubDiGraph extends JFrame implements ActionListener, MouseListener, MouseMotionListener, Constants { // --------------------------------------------------- // // declare class member data // // --------------------------------------------------- // keep track the curren vertex in focus // 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 coeffLables = null; // flag that enables insertion and removal of arcs // public boolean enableArcInsertion = false; public boolean enableArcDeletion = false; // clipboard to handle things like cut, copy and paste // public Vector clipboard = null; // holds the maximum width and height of the scroller // public int maxWidth = 0; public int maxHeight = 0; // holds the current location of the mouse // public int mouseXloc = 0; public int mouseYloc = 0; // the label of the vertex that has been selected from the menu // 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; // creates a frame 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 SubMainMenu subMainMenu = null; // work area to drag and drop components // public SubWorkArea subWorkArea = null; // paramenet file to be written to // public File paramFile = 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 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; public Parser parser = null; // create the start and term nodes // public Vertex START_VERTEX = new Vertex(new ImageIcon(ENTER_IMAGE), ALGORITHM); public Vertex TERM_VERTEX = new Vertex(new ImageIcon(EXIT_IMAGE), ALGORITHM); // --------------------------------------------------- // // declare class constructors // // --------------------------------------------------- // method: SubDiGraph // // arguments: none // returns : none // public SubDiGraph(String title, Vector vec) { // invoke the parent default constructor // super(title); //instantiate the data class // data = new Data(); // run the parser // parser = new Parser(data); // initialize the vectors data members // vertices = vec; coeffLables = new Vector(100, 50); clipboard = new Vector(10, 5); // 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 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 // subMainMenu = new SubMainMenu(this); // create a work area to drag and drop components // subWorkArea = new SubWorkArea(vertices, this); subWorkArea.addMouseListener(this); subWorkArea.addMouseMotionListener(this); // add scroll panes to the subWorkArea // scroller = new JScrollPane(subWorkArea, 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(subMainMenu, BorderLayout.NORTH); this.getContentPane().add(scroller, BorderLayout.CENTER); subMainMenu.add_components(); // add the vertices that were previously created // initVertices(); } // method: initStartVertex // // arguments: none // return: start vertex // // initialize the start vertex // public void initStartVertex() { // set the location of the vertices // START_VERTEX.setLocation(new Point(INIT_START_XLOC, INIT_START_YLOC)); // add mouse motion listeners to the vertices // START_VERTEX.addMouseListener(this); START_VERTEX.addMouseMotionListener(this); // set the dimensions of the vertices // START_VERTEX.setSize(ICON_WIDTH, ICON_HEIGHT); START_VERTEX.setPreferredSize(new Dimension(ICON_WIDTH, ICON_HEIGHT)); START_VERTEX.setMinimumSize(new Dimension(ICON_WIDTH, ICON_HEIGHT)); START_VERTEX.setVertexWidth(ICON_WIDTH); START_VERTEX.setVertexHeight(ICON_HEIGHT); // set the font of the vertices // START_VERTEX.setFont(newCoeffFont); // set the type of the vertex // START_VERTEX.setType(INPUT); // set the vertex papameters // START_VERTEX.association = new String(BUFFER_TAG); START_VERTEX.names = new Vector(); START_VERTEX.types = new Vector(); } // method: initTermVertex // // arguments: none // return: term vertex // // initialize the terminal vertex // public void initTermVertex() { // set the location of the vertices // TERM_VERTEX.setLocation(new Point(INIT_TERM_XLOC, INIT_TERM_YLOC)); // add mouse motion listeners to the vertices // TERM_VERTEX.addMouseListener(this); TERM_VERTEX.addMouseMotionListener(this); // set the dimensions of the vertices // TERM_VERTEX.setSize(ICON_WIDTH, ICON_HEIGHT); TERM_VERTEX.setPreferredSize(new Dimension(ICON_WIDTH, ICON_HEIGHT)); TERM_VERTEX.setMinimumSize(new Dimension(ICON_WIDTH, ICON_HEIGHT)); TERM_VERTEX.setVertexWidth(ICON_WIDTH); TERM_VERTEX.setVertexHeight(ICON_HEIGHT); // set the font of the vertices // TERM_VERTEX.setFont(newCoeffFont); // set the type of the vertex // TERM_VERTEX.setType(OUTPUT); // set the vertex papameters // TERM_VERTEX.association = new String(BUFFER_TAG); TERM_VERTEX.names = new Vector(); TERM_VERTEX.types = new Vector(); } // method: initVertices // // arguments: none // return: none // // resets the parent and child relationships // public void initVertices() { // check if the vector contains any elements // if (vertices.size() == 0) { // initialize the start vertex // initStartVertex(); // initialize the term vertex // initTermVertex(); // add the vertices to the subWorkArea // subWorkArea.add(START_VERTEX); vertices.add(START_VERTEX); subWorkArea.add(TERM_VERTEX); vertices.add(TERM_VERTEX); return; } // add the elements to the subWorkArea // for (int i=0; i < vertices.size(); i++) { // get the current vertex // Vertex vertex = (Vertex)vertices.elementAt(i); // 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); // add the vertex to subWorkArea // subWorkArea.add(vertex); } } // method:closeContainer // // arguments: none // return: none // // hide the container window // public void closeContainer() { // remove the action listeners from the vertices // for (int i=0; i < vertices.size(); i++) { Vertex vertex = (Vertex)vertices.elementAt(i); vertex.removeMouseListener(this); vertex.removeMouseMotionListener(this); } // hide the window // this.setVisible(false); } // 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; enableArcDeletion = false; // repaint the workarea // subWorkArea.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 a algorithm that implements a step of an algorithm // public void createAlgorithm(String algorithmstr) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -