📄 configboxword.java
字号:
GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.gridwidth = 2; c.gridheight = 1; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.anchor =GridBagConstraints.NORTH ; gridbag.setConstraints(scrollPane, c); config_panel.add(scrollPane); enteredData.add(list); blockType.add("enum"); Vertex selectedVertex = cfgVertexFocus; //select.setSelectedItem(enum_values.get(0)); // Create a text field for data entry and display // JPanel new_panel = new JPanel(); new_panel.setLayout(new BorderLayout()); //new_panel.setSize(350,10); // create the appropriate string for the border // String border_title = null; border_title = new String("Input"); // 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 // new_panel.setBorder(border); JLabel inputLabel = new JLabel("Input: "); inputLabel.setFont(newFont); inputLabel.setForeground(Color.black); //labelReference.add(inputLabel); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.gridheight = 1; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.anchor =GridBagConstraints.WEST ; gridbag.setConstraints(inputLabel, c); // config_panel.add(inputLabel); //constrain(config_panel,inputLabel, gridbag, 0, 2, // 1, 1, 1, 0, GridBagConstraints.WEST); dataField = new JTextField("", 30); dataField.setFont(newFont); dataField.setForeground(Color.black); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.gridheight = 1; c.fill = GridBagConstraints.BOTH; c.weightx = 0; c.weighty = 1; c.anchor =GridBagConstraints.WEST; new_panel.add(dataField,"Center"); gridbag.setConstraints(new_panel, c); config_panel.add(new_panel); //gridbag.setConstraints(dataField, c); //config_panel.add(dataField); //constrain(config_panel,dataField, gridbag, 2, 2, // 1, 1, 1, 1, GridBagConstraints.EAST); enteredData.add(dataField); blockType.add("data"); } // !!! unexpected data type // else { System.err.println(); System.err.println("---------------------------------------"); System.err.println("Error - Unexpected data type in file resource.txt: " + types.get(i)); System.err.println("---------------------------------------"); System.exit(0); } // check to see if the width of a JComboBox or JTextField // is wider than maxwidth and if it is, give that value to // maxwidth // String type = (String)blockType.get(i); if((!type.equals("Vertex") && (!type.equals("image")) && (!type.equals("input")) && (!type.equals("boolean")))) { Dimension size = (Dimension)((JComponent)enteredData. get(i)).getPreferredSize(); int width = (int)size.getWidth(); int height = (int)size.getHeight(); if( width > maxwidth) { maxwidth = width; maxheight = height; } } } /* // make all of the JComboBoxes and JTextFields be of equal length // for(int i = 0; i < blockType.size(); i++) { String type = (String)blockType.get(i); if((!type.equals("Vertex") && (!type.equals("image")) && (!type.equals("input")) && (!type.equals("boolean")))) { Dimension size = new Dimension(maxwidth, maxheight); ((JComponent)enteredData.get(i)). setPreferredSize(size); ((JComponent)enteredData.get(i)). setMinimumSize(size); } } */ } // method: constrain // // arguments: // JPanel container : panel being added to // Component button : what is being added to the panel // GridBagLayout gridbag : gridbag layout for config panel // int gridx : the x grid position of the constraint // int gridy : the y grid position of the constraint // int gridwidth : the number of gridspaces wide to constrain // int gridheight : the number of gridspaces tall to constrain // int weightx : the horizontal weighting of the constraint // int weighty : the vertical weighting of the constraint // int anchor : which side of the constraint to anchor to // // return : none // // places all the proper input items onto the config panel // for configuring any transform // public void constrain(JPanel container,Component button, GridBagLayout gridbag, int gridx,int gridy, int gridwidth, int gridheight, int weightx, int weighty, int anchor){ GridBagConstraints c = new GridBagConstraints(); c.gridx = gridx; c.gridy = gridy; c.gridwidth = gridwidth; c.gridheight = gridheight; c.weightx = weightx; c.weighty = weighty; c.anchor = anchor; gridbag.setConstraints(button, c); container.add(button); } // method: validation // // arguments: none // // return: boolean // // checks to make sure that all configuration data has been input properly // and if it has, make the changes to the referrign vertex // public boolean validation() { // code to use if the data is an enumerated type // if(blockType.get(0).equals("enum")) { // set the vertex's value to match the newly selected one // String ww = ""; for(int j=0; j < enum_values.size(); j++) { ww = ww + enum_values.get(j) + " "; } if(!cfgVertexFocus.values.isEmpty()){ cfgVertexFocus.values.set(0, ww); if(enum_values.size() == 0) { cfgVertexFocus.values = new Vector(5,5); } } else { if(enum_values.size() != 0) cfgVertexFocus.values.add(ww); else cfgVertexFocus.values = new Vector(5,5); } } return true; } // method: itemStateChanged // // arguments: // ItemEvent e: event thrown when one of the combo boxes is changed // // return: boolean // // prevents duplicates from being formed when changing the order in // a connector configuration screen // public void itemStateChanged(ItemEvent e) { // the combo box that caused the event to fire // JComboBox changedBox = (JComboBox)e.getSource(); } public void addList() { String s = dataField.getText(); dataField.setText( "" ); StringTokenizer tokens = new StringTokenizer(s, " "); String xvar = (tokens.nextToken()).trim(); if(xvar != null) { enum_values.addElement(xvar); } while(tokens.hasMoreTokens()) { xvar = (tokens.nextToken()).trim(); if(xvar != null) { enum_values.addElement(xvar); } } if(s != null) { list.setListData(enum_values); scrollPane.revalidate(); scrollPane.repaint(); } } public void removeList() { // Get the current selection // int selection = list.getSelectedIndex(); if( selection >= 0 ) { // Add this item to the list and refresh // enum_values.removeElementAt( selection ); list.setListData(enum_values); scrollPane.revalidate(); scrollPane.repaint(); // As a nice touch, select the next item if( selection >= enum_values.size() ) selection = enum_values.size() - 1; list.setSelectedIndex( selection ); } } // method: actionPerformed // // arguments: // ActionEvent e: event that was fired // // return : none // // listens for actions taking place on the components // public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("add")){ // if the block we've configured is a transform // if(cfgType == 0) { addList(); workArea.repaint(); } } if(e.getActionCommand().equals("save")) { // dispose of the changes and revert to the old ways // if(validation()) { this.dispose(); workArea.repaint(); } } if(e.getActionCommand().equals("remove")){ removeList(); workArea.repaint(); } if(e.getActionCommand().equals("revert")){ revertSettings(); } if(e.getActionCommand().equals("cancel")){ this.dispose(); workArea.repaint(); } /* if(e.getActionCommand().equals("help")){ // display a help message: "under construction" // JFrame frame = new JFrame("Help"); JOptionPane.showMessageDialog(frame, "The help message is under construction"); } */ } // method: defaultSettings // // arguments: none // // return: none // // resets all configuartion items to the default values as given in // the gui configuration file // public void defaultSettings() { if(cfgType == 0) { // now run through these and add labels and input // fields as appropriate // for(int i=0; i < cfgVertexFocus.values.size(); i++) { // make the selected option revert to its previous state // if(cfgVertexFocus.types.get(i).equals("enum")){ JComboBox select = (JComboBox)enteredData.get(i); // retrieve and set default value to this list // Vector enum_values = (Vector)cfgVertexFocus.values.get(i); select.setSelectedItem(enum_values.get(0)); } } } else if(cfgType == 1) { for(int i=0; i < connBox.size(); i++) { // set all the combo boxes to show their original values // ((JComboBox)connBox.get(i)).setSelectedIndex(i); // reset the connection order vector to the original setting // Integer value = new Integer(i); connection_order.set(i, value); } } } // method: revertSettings // // arguments: none // // return: none // // resets all configuartion items to the values that were stored in the // referring vertex before the configuration began // public void revertSettings() { // changes all of the settings back to what they were before the // user started changing things // if(cfgType == 1) { for(int i=0; i < connBox.size(); i++) { // set all the combo boxes to show their original values // ((JComboBox)connBox.get(i)).setSelectedIndex(i); // reset the connection order vector to the original setting // Integer value = new Integer(i); connection_order.set(i, value); } } else if(cfgType == 0) { // now run through these and add labels and input // fields as appropriate // for(int i=0; i < cfgVertexFocus.values.size(); i++) { // make the selected option revert to its previous state // if(cfgVertexFocus.types.get(i).equals("enum")){ JComboBox select = (JComboBox)enteredData.get(i); select.setSelectedItem(cfgVertexFocus.values.get(i)); } // make the check box revert to its previous state // else if (cfgVertexFocus.types.get(i).equals("boolean")){ // get the value for the check box // String value = (String)(cfgVertexFocus.values.get(i)); JCheckBox checkBox = (JCheckBox)enteredData.get(i); boolean value2; if (value.equals("true")) value2 = true; else value2 = false; checkBox.setSelected(value2); } // do nothing if the type is image // else if (cfgVertexFocus.types.get(i).equals("image")) { } // do nothing if type is class // else if (cfgVertexFocus.types.get(i).equals("class")) { } // take care of anything of type text // else if (cfgVertexFocus.types.get(i).equals("text")) { JTextField text_box = (JTextField)enteredData.get(i); String text = (String)cfgVertexFocus.values.get(i); text_box.setText(text); } // creation of input box for unsigned int // else if (cfgVertexFocus.types.get(i).equals("unsigned-integer")) { JTextField text_box = (JTextField)enteredData.get(i); String text = (String)cfgVertexFocus.values.get(i); text_box.setText(text); } // creation of input box for float // else if (cfgVertexFocus.types.get(i).equals("float")) { JTextField text_box = (JTextField)enteredData.get(i); String text = (String)cfgVertexFocus.values.get(i); text_box.setText(text); } // creation of input box for int // else if (cfgVertexFocus.types.get(i).equals("integer")) { JTextField text_box = (JTextField)enteredData.get(i); String text = (String)cfgVertexFocus.values.get(i); text_box.setText(text); } } } }}//// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -