📄 configboxword.java
字号:
// file: ConfigBox.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 javax.swing.plaf.*;public class ConfigBoxWord extends JDialog implements ActionListener, ItemListener, Constants { // --------------------------------------------------- // // declare class member data // // --------------------------------------------------- // data from the parsed text file // Data data = null; // scroll pane to hold all the parameter fields // JScrollPane scroll_pane = null; // panel to hold all the config data fields // to be mounted in a scrollable pane // JPanel config_panel = null; // Button to get values an return to process design box // JButton add_button = null; JButton save_button = null; JButton remove_button = null; JButton cancel_button = null; JButton config_button = null; //Vector of labels and data blocks (text fields, selection blocks, //check boxes, etc..) // Vector enteredData = null; Vector blockType = null; Vector labelReference = null; //Vector of subclass vertices // Vector config_vertices = null; // Type of configuration box // int cfgType = 0; // arc index // int index = 0; // input Block Exist // boolean inputFlag = false; // Max number of subclasses // int max_subclass = 0; // vertex that is being configured // Vertex cfgVertexFocus = null; // WorkArea that allows the return button to do a proper repaint // WorkArea workArea = null; // jlabels used to lable each of the items in the config box // public Vector labels = null; public Vector values = null; // vectors user in a connector box configuration // Vector connBox = null; Vector connLabels = null; Vector connection_order = null; // DiGraph // DiGraph digraph; // JList // JList list = new JList(); // JTextField // JTextField dataField; // JScrollPane // JScrollPane scrollPane; // make this config panel use grid bag layout // GridBagLayout gridbag = new GridBagLayout(); // enum_values // Vector enum_values = new Vector(5,5); // --------------------------------------------------- // // declare class constructors // // --------------------------------------------------- // method: ConfigBox // // arguments: none // returns : none // public ConfigBoxWord(DiGraph parent, Data d, Vertex b, WorkArea area, int type) { // invoke the parent default constructor // //super("Configuration Box"); super(parent,"Configuration Box", true); digraph = parent; index = 0; Point xy = parent.getLocation(); setLocation((int)xy.getX() + 100,(int)xy.getY() + 200); // Set the configuration type // cfgType = type; // Make the passed Data object available globally // data = d; // Initialize the enteredData and labelReference vectors for use // enteredData = new Vector(5,5); labelReference = new Vector(5,5); blockType = new Vector(5,5); // This is the vertex that is being configured // cfgVertexFocus = b; //Create this new panel with gridbag layout // config_panel = new JPanel(); addConfig(); // make reference available globally for work area // workArea = area; //Set the sizes of the scroll pane and configuration panel // int height = 250 + 40; int width = 335 + 55; config_panel.setSize(width,height); config_panel.setMinimumSize(new Dimension(width,height)); config_panel.setPreferredSize(new Dimension(width,height)); config_panel.setMaximumSize(new Dimension(width,height)); // create the appropriate string for the border // String border_title = null; if(cfgType == 0) border_title = new String(b.getVertexName()+" Word List"); else if (cfgType == 1){ border_title = new String("Connector Configuration:"); } // create the border and set the proper font // BorderUIResource.TitledBorderUIResource border = new BorderUIResource.TitledBorderUIResource(border_title); border.setTitleFont(newFont); border.setTitleColor(Color.black); // make the config panel use the proper border // config_panel.setBorder(border); //Add the scroll pane to the frame // this.getContentPane().add(config_panel, BorderLayout.NORTH); } // --------------------------------------------------- // // declare class methods // // --------------------------------------------------- // method: addConfig() // // arguments: none // return: none // // dynamically adds and constrains all objects on the JPanel // public void addConfig() { // Create a panel to hold all other components config_panel.setLayout(gridbag); // add the appropriate input values depending on whether the // vertex being configured in a transform or a connector // if(cfgType == 0) { //addTransformConfig(gridbag); addNodeConfig(gridbag); } else if (cfgType == 1){ addConnectorConfig(gridbag); } // create a button panel to place all buttons on so proper spacing // can be acheived // JPanel button_panel = new JPanel(); button_panel.setLayout(new GridLayout(1,4, 1, 1)); // create the add button and add the appropriate action handler // add_button = new JButton("Add"); button_panel.add(add_button); add_button.addActionListener(this); add_button.setActionCommand("add"); add_button.setFont(newFont); // create the default button and add to subpanel // remove_button = new JButton(" Remove "); button_panel.add(remove_button); remove_button.addActionListener(this); remove_button.setActionCommand("remove"); remove_button.setFont(newFont); // create the save button and add to subpanel // save_button = new JButton("Save"); button_panel.add(save_button); save_button.addActionListener(this); save_button.setActionCommand("save"); save_button.setFont(newFont); // create the help button and add to subpanel // cancel_button = new JButton("Cancel"); button_panel.add(cancel_button); cancel_button.addActionListener(this); cancel_button.setActionCommand("cancel"); cancel_button.setFont(newFont); // place the button panel onto the config panel // constrain(config_panel, button_panel, gridbag, 0, labels.size()+2, GridBagConstraints.REMAINDER,1,1,1, GridBagConstraints.SOUTH); } // method: addConnectorConfig // // arguments: // GridBagLayout gridbag: gridbag layout for config panel // // return : none // // places all the proper input items onto the config panel // for configuring a connector box // public void addConnectorConfig(GridBagLayout gridbag) { // get the number of parents this connector vertex has // int size = cfgVertexFocus.getInDegree(); // create a vector containing the names of all the connector's // parents // labels = new Vector(5,5); // populate the names vector // for(int i=0; i < size; i++) { Vertex vertex_parent = (Vertex)cfgVertexFocus.vertexParents.get(i); String vertex_name = vertex_parent.getVertexName(); labels.add((i + 1) + ":" + vertex_name); } // create a vector of JLabels and JComboBox for use in swapping // connLabels = new Vector(size,1); connBox = new Vector(size,1); connection_order = new Vector(size,1); // populate the vector's for display // for(int i=0; i < labels.size(); i++) { connLabels.add(new JLabel("Position " + (i+1))); connBox.add(new JComboBox(labels)); ((JComboBox)connBox.get(i)).setSelectedIndex(i); ((JComboBox)connBox.get(i)).addItemListener(this); } for(int i=0; i < labels.size(); i++) { // place the label onto the screen // ((JLabel)connLabels.get(i)).setForeground(Color.black); constrain(config_panel,(JLabel)(connLabels.get(i)), gridbag, 0, i, 1, 1, 1, 0, GridBagConstraints.WEST); ((JLabel)connLabels.get(i)).setFont(newFont); labelReference.add((JLabel)connLabels.get(i)); // place the JComboBox on the screen // ((JComboBox)connBox.get(i)).setForeground(Color.black); constrain(config_panel,((JComboBox)connBox.get(i)), gridbag, 1, i, 1, 1, 1, 0, GridBagConstraints.EAST); ((JComboBox)connBox.get(i)).setFont(newFont); // populate a vector to tell me connections made // Integer integer = new Integer(i); connection_order.add(integer); } } // method: addArcConfig // // arguments: // GridBagLayout gridbag: gridbag layout for config panel // // return : none // // places all the proper input items onto the config panel // for configuring any transform // public void addArcConfig(GridBagLayout gridbag) { labels = new Vector(5,5); // create labels to be included in the frame // JLabel weightLabel = new JLabel("Weight: "); weightLabel.setFont(newFont); weightLabel.setForeground(Color.black); labelReference.add(weightLabel); constrain(config_panel,weightLabel, gridbag, 0, 2, 1, 1, 1, 0, GridBagConstraints.WEST); labels.add("Weight"); String tmpw = null; tmpw = (String)digraph.graphArc.weights.get(index); JTextField weightField = null; if(tmpw != null) { weightField = new JTextField(tmpw, 8); } else { weightField = new JTextField("0.0", 8); } weightField.setFont(newFont); weightField.setForeground(Color.black); constrain(config_panel,weightField, gridbag, 3, 2, 1, 1, 1, 0, GridBagConstraints.EAST); enteredData.add(weightField); blockType.add("float"); JLabel epiLabel = new JLabel("Epsilon: "); labels.add("Epsilon"); epiLabel.setFont(newFont); epiLabel.setForeground(Color.black); labelReference.add(epiLabel); constrain(config_panel,epiLabel, gridbag, 0, 3, 1, 1, 1, 0, GridBagConstraints.WEST); // create the check box // boolean value2 = false; String tmpe = null; tmpe = (String)digraph.graphArc.epsilon.get(index); JCheckBox checkBox = null; // instantiate and place chack box on config panel // if(tmpe == "true") { checkBox = new JCheckBox("", true); } else { checkBox = new JCheckBox("", value2); } constrain(config_panel, checkBox, gridbag, 0, 1, 1,1,1,0,GridBagConstraints.EAST); enteredData.add(checkBox); blockType.add("boolean"); } // method: addNodeConfig // // arguments: // GridBagLayout gridbag: gridbag layout for config panel // // return : none // // places all the proper input items onto the config panel // for configuring any node // public void addNodeConfig(GridBagLayout gridbag) { // 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 // labels = new Vector(5,5); Vector types = new Vector(5,5); values = new Vector(5,5); Object obj = null; labels.add(cfgVertexFocus.names.get(0)); types.add(cfgVertexFocus.types.get(0)); if(!cfgVertexFocus.values.isEmpty()) { values.add(cfgVertexFocus.values.get(0)); } // maximum width of any JTextField or JComboBox // will set all to this width once they have been added // int maxwidth = 0; int maxheight = 0; // run through these and add labels and input fields as appropriate // for(int i=0; i < labels.size(); i++) { // add a label for all labels except the images // if(types.get(i).equals("image") == false){ } else { // keep data alligned so changing values is done easily // while holding onto these image files // enteredData.add("image"); labelReference.add("image"); blockType.add("image"); } // add a drop down list for the enumerated values with first // option from file being initially selected // if(types.get(0).equals("enum")){ // retrieve and add all possible values to this list // if(!values.isEmpty()) { String datavar = "" + values.get(0); StringTokenizer tokens = new StringTokenizer(datavar, " "); String xvar = (tokens.nextToken()).trim(); enum_values.add(xvar); while(tokens.hasMoreTokens()) { xvar = (tokens.nextToken()).trim(); enum_values.add(xvar); } } else { // enum_values.add(""); enum_values = new Vector(); } for(int j=0; j < enum_values.size(); j++) { String ww = ""+enum_values.get(j); //model.addElement(enum_values.get(j)); } list = new JList(enum_values); scrollPane = new JScrollPane(); scrollPane.getViewport().add( list );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -