📄 configboxin.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 ConfigBoxIn 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 save_button = null; JButton cancel_button = null; JButton default_button = null; JButton help_button = null; JButton config_button = null; //Vector to store information for determing subclass // Vector subparamInfo = new Vector(5,5); //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; // Max number of subclasses // int max_subclass = 0; // Max number of subparam // int max_subparam = 0; // parameter button // Vertex buttonParam = null; // 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; // vectors user in a connector box configuration // Vector connBox = null; Vector connLabels = null; Vector connection_order = null; SubConfigBoxParam class_config_panel = null; // --------------------------------------------------- // // declare class constructors // // --------------------------------------------------- // method: ConfigBox // // arguments: none // returns : none // public ConfigBoxIn(DiGraph parent, Data d, Vertex b, WorkArea area, int type) { // invoke the parent default constructor // super(parent,"Configuration Box", true); 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 = labelReference.size() * 25; int width = 335 + 55; if (cfgType == 1) { height = labelReference.size() * 25 + 75; 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(cfgVertexFocus.association + " Configuration:"); */ border_title = new String("Input" + " Configuration:"); } 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() { // make this config panel use grid bag layout // GridBagLayout gridbag = new GridBagLayout(); 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); } else if (cfgType == 1){ addConnectorConfig(gridbag); } JPanel button_panel = new JPanel(); if( max_subparam > 0) { // create a button panel to place all buttons on so proper spacing // can be acheived // button_panel.setLayout(new GridLayout(1,4, 1, 1)); // create the configure button and add the appropriate action handler // config_button = new JButton("Configure"); button_panel.add(config_button); config_button.addActionListener(this); config_button.setActionCommand("param"); config_button.setFont(newFont); // create the return button and add the appropriate action handler // save_button = new JButton("Save"); button_panel.add(save_button); save_button.addActionListener(this); save_button.setActionCommand("update"); save_button.setFont(newFont); // create the cancel 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); // create the help button and add to subpanel // help_button = new JButton("Help"); button_panel.add(help_button); help_button.addActionListener(this); help_button.setActionCommand("help"); help_button.setFont(newFont); } else { // create a button panel to place all buttons on so proper spacing // can be acheived // button_panel.setLayout(new GridLayout(1,4, 1, 1)); // create the return button and add the appropriate action handler // save_button = new JButton("Save"); button_panel.add(save_button); save_button.addActionListener(this); save_button.setActionCommand("update"); save_button.setFont(newFont); // create the cancel 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); // create the default button and add to subpanel // default_button = new JButton(" Default "); button_panel.add(default_button); default_button.addActionListener(this); default_button.setActionCommand("default"); default_button.setFont(newFont); // create the help button and add to subpanel // help_button = new JButton("Help"); button_panel.add(help_button); help_button.addActionListener(this); help_button.setActionCommand("help"); help_button.setFont(newFont); } // place the button panel onto the config panel // constrain(config_panel, button_panel, gridbag, 0, labels.size()+1, 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: addTransformConfig // // 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 addTransformConfig(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); Vector values = new Vector(5,5); String transform = cfgVertexFocus.association; int subclassIndex = 0; int subcparamIndex = 0; for(int j=data.association.indexOf(transform); j <= data.association.lastIndexOf(transform); j++) { if(j != -1) { labels.add(data.name.get(j)); types.add(data.type.get(j)); values.add(data.values.get(j)); } } // calculate the total number of subclasses // for(int i =0; i < types.size(); i++){ if(types.get(i).equals("class")) max_subclass++; } cfgVertexFocus.max_subclass = max_subclass; // calculate the total number of subparams // for(int i =0; i < types.size(); i++){ if(types.get(i).equals("param")) max_subparam++; } // 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){ String configLabel = (String)labels.get(i); JLabel jlabel = new JLabel((String)labels.get(i)); if(configLabel.equals("configuration")) { jlabel = new JLabel(""); } jlabel.setForeground(Color.black); constrain(config_panel,jlabel, gridbag, 0, i, 1, 1, 1, 0, GridBagConstraints.WEST); labelReference.add(jlabel); jlabel.setFont(newFont); } 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(i).equals("enum")){ // create a drop down list to allow selection from // JComboBox select = new JComboBox(); select.setFont(newFont); select.setForeground(Color.black); // retrieve and add all possible values to this list // Vector enum_values = (Vector)values.get(i); for(int j=0; j < enum_values.size(); j++) { select.addItem(enum_values.get(j)); } // add the combo box to the panel // constrain(config_panel,select, gridbag, 3, i, 1, 1, 1, 0, GridBagConstraints.EAST); enteredData.add(select); blockType.add("enum"); Vertex selectedVertex = cfgVertexFocus; select.setSelectedItem(selectedVertex.values.get(i)); } // make a check box for a boolean type // else if (types.get(i).equals("boolean")){ // create the check box // String value = (String)(cfgVertexFocus.values.get(i)); // get the default value for the button // boolean value2; if (value.equals( "true")) value2 = true; else value2 = false; // instantiate and place chack box on config panel // JCheckBox checkBox = new JCheckBox("", value2); constrain(config_panel, checkBox, gridbag, 3, i, 1,1,1,0,GridBagConstraints.EAST); enteredData.add(checkBox); blockType.add("boolean"); } // add another pop up frame to set parameters for the class // else if (types.get(i).equals("param")) { String image_name = null; String image_association= null; // tells the program which transform it is looking to match // image_association = (String)values.get(i); // scans through the association until it // finds the smallIcon key // for(int j=data.association.indexOf(image_association); j <= data.association.lastIndexOf(image_association);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -