📄 subconfigbox.java
字号:
// file: SubConfigBox.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 SubConfigBox extends JDialog implements ActionListener, Constants { // --------------------------------------------------- // // declare class member data // // --------------------------------------------------- // set the current vertex that is in focus // private Vertex currVertexFocus = null; // 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; // Parent dialogue // JDialog parent = null; // global representation of the transform type we are dealing with // Vertex cfgVertexFocus; // transform tyoe this subclass represents // Vertex subVertex; // 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 sub parameters // 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; // Max number of subparam // int max_subparam = 0; // total number of subclasses (to prevent re-adding to the subclass vector) // int max_subclass = 1; // parameter button // Vertex buttonParam = null; // maximum font size for the componets // private static final int MAX_FONT_SIZE = (int)12; // --------------------------------------------------- // // declare class constructors // // --------------------------------------------------- // method: SubConfigBox // // arguments: none // returns : none // public SubConfigBox(JDialog par, Data d, Vertex subclass, Vertex process) { // invoke the parent default constructor // //super("Subclass Configuration Box"); parent = par; setModal(true); Point xy = parent.getLocation(); setLocation((int)xy.getX() + 100,(int)xy.getY() + 200); // 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); // give the name of the transfrom in question over to its global // counterpart // subVertex = subclass; cfgVertexFocus = process; // create this new panel with gridbag layout // config_panel = new JPanel(); addConfig(); // set the sizes of the scroll pane and configuration panel // int height = labelReference.size() * 25 + 75; 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)); // add the scroll pane to the frame // this.getContentPane().add(config_panel, BorderLayout.NORTH); // create, configure, and place a border on the config pane // String border_title = new String(subVertex.association + " Configuration:"); BorderUIResource.TitledBorderUIResource border = new BorderUIResource.TitledBorderUIResource(border_title); border.setTitleFont(newFont); border.setTitleColor(Color.black); config_panel.setBorder(border); } // --------------------------------------------------- // // declare class methods // // --------------------------------------------------- // method: addConfig() // // arguments: none // return: none // // dynamically adds and constrains all objects on the JPanel // public void addConfig() { GridBagLayout gridbag = new GridBagLayout(); config_panel.setLayout(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 // Vector labels = new Vector(5,5); Vector types = new Vector(5,5); Vector values = new Vector(5,5); String transform = subVertex.association; int subclassIndex = 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)); } } // 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.setFont(newFont); jlabel.setForeground(Color.black); constrain(config_panel,jlabel, gridbag, 0, i, 1, 1, 1, 0, GridBagConstraints.WEST); labelReference.add(jlabel); } 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(); constrain(config_panel,select, gridbag, 3, i, 1, 1, 1, 0, GridBagConstraints.EAST); // 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)); } enteredData.add(select); blockType.add("enum"); select.setSelectedItem(subVertex.values.get(i)); select.setFont(newFont); select.setForeground(Color.black); } // make a check box for a boolean type // else if (types.get(i).equals("boolean")){ //create the check box // String value = (String)(subVertex.values.get(i)); // get the default value for the button // boolean value2; if (value.equals("true")) value2 = true; else value2 = false; 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); j++) { if(j != -1) { if(((String)(data.name.get(j))). equals("iconSmall")) { // sets the image_name to the value // held in small icon // image_name = (String)data.values.get(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 = GUI_PATH + "/images_small/default.gif"; } else { image_name = GUI_PATH + "/images_small/default.gif"; } image_name = GUI_PATH+"/lib/images/isip_transform_builder/icons/algorithm_00.gif"; // create the icons for the config panel // ImageIcon icon = new ImageIcon(image_name); // create the button for the config panel // buttonParam = new Vertex(" Configure "); buttonParam.association = image_association; // 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(image_association); j <= data.association.lastIndexOf(image_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 // //button.initializeConfig(labels2, values2, types2, // image_association, data); // add subparam button to the vector // subVertex.subparam.add(buttonParam); // add the vertex to the button panel // enteredData.add(buttonParam); blockType.add("Vertex"); max_subparam++; } // add another pop up frame to set parameters for the class // else if (types.get(i).equals("class")) { 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); j++) { if(j != -1) { if(((String)(data.name.get(j))).equals("iconSmall")) { // sets the image_name to the value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -