Example usage for javax.swing JComboBox addItem

List of usage examples for javax.swing JComboBox addItem

Introduction

In this page you can find the example usage for javax.swing JComboBox addItem.

Prototype

public void addItem(E item) 

Source Link

Document

Adds an item to the item list.

Usage

From source file:com.osparking.osparking.Settings_System.java

/**
 * Initialize some controls on the system settings change GUI. 
 */// ww  w.  jav a 2s  .c  o m
public Settings_System(ControlGUI mainForm) {
    prepareComPortControls();

    initComponents();
    changedControls = new ChangedComponentSave(SettingsSaveButton, SettingsCancelButton, SettingsCloseButton);

    setIconImages(OSPiconList);
    augmentComponentMap(this, componentMap);
    tuneComponentSize();

    this.mainForm = mainForm;
    if (mainForm == null)
        isStand_Alone = true;
    else {
        EBD_DisplaySettings = mainForm.EBD_DisplaySettings;
    }
    addPWStrengthItems();
    addMaxArrivalItems();
    maxArrivalCBoxIndex = findCBoxIndex(ImageDurationCBox, maxMaintainDate);
    addOperationLoggingLevelOptions();
    addPopSizeOptions();

    /**
     * Initialize device combobox items.
     */
    for (int gate = 1; gate <= gateCount; gate++) {
        //<editor-fold desc="-- Combo Box item init for device and connection type of each gate">
        JComboBox comboBx = ((JComboBox) getComponentByName("Camera" + gate + "_TypeCBox"));
        if (comboBx != null) {
            comboBx.removeAllItems();
            for (CameraType type : CameraType.values()) {
                if (type == CameraType.CarButton) {
                    if (gate == 1) {
                        comboBx.addItem(type);
                    }
                } else {
                    comboBx.addItem(type);
                }
            }
        }

        comboBx = ((JComboBox) getComponentByName("E_Board" + gate + "_TypeCBox"));
        if (comboBx != null) {
            comboBx.removeAllItems();
            for (E_BoardType type : E_BoardType.values()) {
                comboBx.addItem(type);
            }
        }

        comboBx = ((JComboBox) getComponentByName("GateBar" + gate + "_TypeCBox"));
        if (comboBx != null) {
            comboBx.removeAllItems();
            for (GateBarType type : GateBarType.values()) {
                comboBx.addItem(type);
            }
        }

        for (DeviceType devType : DeviceType.values()) {
            comboBx = ((JComboBox) getComponentByName(devType.name() + gate + "_connTypeCBox"));
            if (comboBx != null) {
                comboBx.removeAllItems();
                for (ConnectionType connType : ConnectionType.values()) {
                    if (devType != Camera || connType == ConnectionType.TCP_IP) {
                        comboBx.addItem(connType.getLabel());
                    }
                }
            }
        }
        //</editor-fold>
    }
    loadComponentValues();
    makeEnterActAsTab();
    setLocation(0, 0);
    // Enable data manager button for the admin
    if (loginID.equals(ADMIN_ID)) {
        manageData.setEnabled(true);
    }
}

From source file:com.mirth.connect.client.ui.Frame.java

/**
 * Creates all the items in the combo box for the connectors.
 * //  www  .jav a  2s  .c  o  m
 * This method is called from each connector.
 */
public void setupCharsetEncodingForConnector(javax.swing.JComboBox charsetEncodingCombobox) {
    if (this.availableCharsetEncodings == null) {
        this.setCharsetEncodings();
    }
    if (this.availableCharsetEncodings == null) {
        logger.error("Error, the are no encodings detected.");
        return;
    }
    charsetEncodingCombobox.removeAllItems();
    for (int i = 0; i < this.availableCharsetEncodings.size(); i++) {
        charsetEncodingCombobox.addItem(this.availableCharsetEncodings.get(i));
    }
}

From source file:com.game.ui.views.PlayerEditor.java

@Override
public void actionPerformed(ActionEvent ae) {
    validationMess.setText("");
    validationMess.setVisible(false);/*from  ww  w  .  j av a  2 s . co m*/
    if (ae.getActionCommand().equalsIgnoreCase("dropDown")) {
        JComboBox comboBox = (JComboBox) ae.getSource();
        String type = comboBox.getSelectedItem().toString();
        for (GameCharacter user : GameBean.playerDetails) {
            Player player = (Player) user;
            if (player.getType().equalsIgnoreCase(type)) {
                ((JTextField) leftPanel.getComponent(2)).setText(player.getName());
                ((JTextField) leftPanel.getComponent(4)).setText(player.getImagePath());
                ((JTextField) leftPanel.getComponent(6)).setText(new Integer(player.getHealth()).toString());
                ((JTextField) leftPanel.getComponent(8)).setText(new Integer(player.getAttackPts()).toString());
                ((JTextField) leftPanel.getComponent(10)).setText(new Integer(player.getArmor()).toString());
                ((JTextField) leftPanel.getComponent(12))
                        .setText(new Integer(player.getAttackRange()).toString());
                ((JTextField) leftPanel.getComponent(14)).setText(new Integer(player.getMovement()).toString());
                ((JTextField) leftPanel.getComponent(16)).setText(player.getType());
                JComboBox cBox = (JComboBox) leftPanel.getComponent(18);
                cBox.setSelectedItem(player.getInventory().getEquippedWeapon().getName());
                lvlPanel.txtFields[0].setText("" + player.getLevel());
                lvlPanel.txtFields[1].setText("" + player.getExp());
                lvlPanel.txtFields[2].setText("" + player.getStrength());
                lvlPanel.txtFields[3].setText("" + player.getVitality());
                lvlPanel.txtFields[4].setText("" + player.getDexterity());
                lvlPanel.txtFields[5].setText("" + player.getWisdom());
                break;
                //                    return;
            }
        }
    } else {
        String name = ((JTextField) leftPanel.getComponent(2)).getText();
        String image = ((JTextField) leftPanel.getComponent(4)).getText();
        String health = ((JTextField) leftPanel.getComponent(6)).getText();
        String attackPts = ((JTextField) leftPanel.getComponent(8)).getText();
        String armourPts = ((JTextField) leftPanel.getComponent(10)).getText();
        String attackRnge = ((JTextField) leftPanel.getComponent(12)).getText();
        String movement = ((JTextField) leftPanel.getComponent(14)).getText();
        String type = ((JTextField) leftPanel.getComponent(16)).getText();
        String weapon = ((JComboBox) leftPanel.getComponent(18)).getSelectedItem().toString();
        int attr[] = new int[6];
        attr[0] = Integer.parseInt(lvlPanel.txtFields[0].getText());
        attr[1] = Integer.parseInt(lvlPanel.txtFields[1].getText());
        attr[2] = Integer.parseInt(lvlPanel.txtFields[2].getText());
        attr[3] = Integer.parseInt(lvlPanel.txtFields[3].getText());
        attr[4] = Integer.parseInt(lvlPanel.txtFields[4].getText());
        attr[5] = Integer.parseInt(lvlPanel.txtFields[5].getText());
        //            validationMess.setText("");
        //            validationMess.setVisible(false);
        if (StringUtils.isNotBlank(image) && StringUtils.isNotBlank(health) && StringUtils.isNotBlank(attackPts)
                && StringUtils.isNotBlank(armourPts) && StringUtils.isNotBlank(attackRnge)
                && StringUtils.isNotBlank(movement) && StringUtils.isNotBlank(type)
                && StringUtils.isNotBlank(weapon)) {
            validationMess.setVisible(false);
            Player player = new Player();
            //have to remove the following statement later..
            player.setName(name);
            player.setAttackPts(Integer.parseInt(attackPts));
            player.setAttackRange(Integer.parseInt(attackRnge));
            player.setHealth(Integer.parseInt(health));
            player.setImagePath(image);
            player.setMovement(Integer.parseInt(movement));
            player.setArmor(Integer.parseInt(armourPts));
            player.setType(type);
            Inventory inventory = new Inventory();
            int position = GameUtils.getPositionOfWeaponItem(weapon);
            Weapon weaponObj = (Weapon) GameBean.weaponDetails.get(position);
            inventory.setEquippedWeapon(weaponObj);
            player.setInventory(inventory);
            player.setLevel(attr[0]);
            player.setExp(attr[1]);
            player.setStrength(attr[2]);
            player.setVitality(attr[3]);
            player.setDexterity(attr[4]);
            player.setWisdom(attr[5]);
            boolean characterAlrdyPresent = false;
            for (int i = 0; i < GameBean.playerDetails.size(); i++) {
                Player charFromList = (Player) GameBean.playerDetails.get(i);
                if (charFromList.getType().equalsIgnoreCase(type)) {
                    GameBean.playerDetails.remove(i);
                    characterAlrdyPresent = true;
                }
            }
            GameBean.playerDetails.add(player);
            try {
                GameUtils.writeCharactersToXML(GameBean.playerDetails, Configuration.PATH_FOR_USER_CHARACTERS);
                validationMess.setText("Saved Successfully..");
                validationMess.setVisible(true);
                if (!characterAlrdyPresent) {
                    comboBox.addItem(type);
                    comboBox.removeActionListener(this);
                    comboBox.setSelectedItem(type);
                    comboBox.addActionListener(this);
                }
            } catch (Exception e) {
                System.out.println("PlayerEditor : actionPerformed() : Some error occured " + e);
                validationMess.setText("Some error occured..");
                validationMess.setVisible(true);
                e.printStackTrace();
            }

        } else {
            validationMess.setText("Pls enter all the fields or pls choose a character from the drop down");
            validationMess.setVisible(true);
        }
    }
    this.revalidate();
    //        JFrame frame = (JFrame)SwingUtilities.getAncestorNamed("Frame", this);
    //        frame.revalidate();
}

From source file:userinterface.properties.GUIGraphHandler.java

public void plotNewFunction() {

    JDialog dialog;/*from   w  ww .j a  v  a  2 s .com*/
    JRadioButton radio2d, radio3d, newGraph, existingGraph;
    JTextField functionField, seriesName;
    JButton ok, cancel;
    JComboBox<String> chartOptions;
    JLabel example;

    //init all the fields of the dialog
    dialog = new JDialog(GUIPrism.getGUI());
    radio2d = new JRadioButton("2D");
    radio3d = new JRadioButton("3D");
    newGraph = new JRadioButton("New Graph");
    existingGraph = new JRadioButton("Exisiting");
    chartOptions = new JComboBox<String>();
    functionField = new JTextField();
    ok = new JButton("Plot");
    cancel = new JButton("Cancel");
    seriesName = new JTextField();
    example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
    example.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.HAND_CURSOR));
            example.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            example.setForeground(Color.BLACK);
        }

        @Override
        public void mouseClicked(MouseEvent e) {

            if (e.getButton() == MouseEvent.BUTTON1) {

                if (radio2d.isSelected()) {
                    functionField.setText("x/2 + 5");
                } else {
                    functionField.setText("x+y+5");
                }

                functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
                functionField.setForeground(Color.BLACK);

            }
        }

    });

    //set dialog properties
    dialog.setSize(400, 350);
    dialog.setTitle("Plot a new function");
    dialog.setModal(true);
    dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
    dialog.setLocationRelativeTo(GUIPrism.getGUI());

    //add every component to their dedicated panels
    JPanel graphTypePanel = new JPanel(new FlowLayout());
    graphTypePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type"));
    graphTypePanel.add(radio2d);
    graphTypePanel.add(radio3d);

    JPanel functionFieldPanel = new JPanel(new BorderLayout());
    functionFieldPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function"));
    functionFieldPanel.add(functionField, BorderLayout.CENTER);
    functionFieldPanel.add(example, BorderLayout.SOUTH);

    JPanel chartSelectPanel = new JPanel();
    chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS));
    chartSelectPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to"));
    JPanel radioPlotPanel = new JPanel(new FlowLayout());
    radioPlotPanel.add(newGraph);
    radioPlotPanel.add(existingGraph);
    JPanel chartOptionsPanel = new JPanel(new FlowLayout());
    chartOptionsPanel.add(chartOptions);
    chartSelectPanel.add(radioPlotPanel);
    chartSelectPanel.add(chartOptionsPanel);

    JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    bottomControlPanel.add(ok);
    bottomControlPanel.add(cancel);

    JPanel seriesNamePanel = new JPanel(new BorderLayout());
    seriesNamePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name"));
    seriesNamePanel.add(seriesName, BorderLayout.CENTER);

    // add all the panels to the dialog

    dialog.add(graphTypePanel);
    dialog.add(functionFieldPanel);
    dialog.add(chartSelectPanel);
    dialog.add(seriesNamePanel);
    dialog.add(bottomControlPanel);

    // do all the enables and set properties

    radio2d.setSelected(true);
    newGraph.setSelected(true);
    chartOptions.setEnabled(false);
    functionField.setText("Add function expression here....");
    functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
    functionField.setForeground(Color.GRAY);
    seriesName.setText("New function");
    ok.setMnemonic('P');
    cancel.setMnemonic('C');
    example.setToolTipText("click to try out");

    ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok");
    ok.getActionMap().put("ok", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ok.doClick();
        }
    });

    cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "cancel");
    cancel.getActionMap().put("cancel", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cancel.doClick();
        }
    });

    boolean found = false;

    for (int i = 0; i < theTabs.getTabCount(); i++) {

        if (theTabs.getComponentAt(i) instanceof Graph) {
            chartOptions.addItem(getGraphName(i));
            found = true;
        }
    }

    if (!found) {

        existingGraph.setEnabled(false);
        chartOptions.setEnabled(false);
    }

    //add all the action listeners

    radio2d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio2d.isSelected()) {

                radio3d.setSelected(false);

                if (chartOptions.getItemCount() > 0) {
                    existingGraph.setEnabled(true);
                    chartOptions.setEnabled(true);
                }

                example.setText(
                        "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
            }
        }
    });

    radio3d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio3d.isSelected()) {

                radio2d.setSelected(false);
                newGraph.setSelected(true);
                existingGraph.setEnabled(false);
                chartOptions.setEnabled(false);
                example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>");

            }

        }
    });

    newGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (newGraph.isSelected()) {
                existingGraph.setSelected(false);
                chartOptions.setEnabled(false);
            }
        }
    });

    existingGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (existingGraph.isSelected()) {

                newGraph.setSelected(false);
                chartOptions.setEnabled(true);
            }
        }
    });

    ok.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            String function = functionField.getText();

            Expression expr = null;

            try {

                expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function);
                expr = (Expression) expr.accept(new ASTTraverseModify() {

                    @Override
                    public Object visit(ExpressionIdent e) throws PrismLangException {
                        return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                    }

                });

                expr.typeCheck();
                expr.semanticCheck();

            } catch (PrismLangException e1) {

                // for copying style
                JLabel label = new JLabel();

                // html content in our case the error we want to show
                JEditorPane ep = new JEditorPane("text/html",
                        "<html> There was an error parsing the function. To read about what built-in"
                                + " functions are supported <br>and some more information on the functions, visit "
                                + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>."
                                + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>");

                // handle link events
                ep.addHyperlinkListener(new HyperlinkListener() {
                    @Override
                    public void hyperlinkUpdate(HyperlinkEvent e) {
                        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                            try {
                                Desktop.getDesktop().browse(e.getURL().toURI());
                            } catch (IOException | URISyntaxException e1) {

                                e1.printStackTrace();
                            }
                        }
                    }
                });
                ep.setEditable(false);
                ep.setBackground(label.getBackground());

                // show the error dialog
                JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (radio2d.isSelected()) {

                ParametricGraph graph = null;

                if (newGraph.isSelected()) {

                    graph = new ParametricGraph("");
                } else {

                    for (int i = 0; i < theTabs.getComponentCount(); i++) {

                        if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) {

                            graph = (ParametricGraph) theTabs.getComponent(i);
                        }
                    }

                }

                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true);

            } else if (radio3d.isSelected()) {

                try {

                    expr = (Expression) expr.accept(new ASTTraverseModify() {
                        @Override
                        public Object visit(ExpressionIdent e) throws PrismLangException {
                            return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                        }

                    });

                    expr.semanticCheck();
                    expr.typeCheck();

                } catch (PrismLangException e1) {
                    e1.printStackTrace();
                }

                if (expr.getAllConstants().size() < 2) {

                    JOptionPane.showMessageDialog(dialog,
                            "There are not enough variables in the function to plot a 3D chart!", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                // its always a new graph
                ParametricGraph3D graph = new ParametricGraph3D(expr);
                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false);
            }

            dialog.dispose();
        }
    });

    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    // we will show info about the function when field is out of focus
    functionField.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

            if (!functionField.getText().equals("")) {
                return;
            }

            functionField.setText("Add function expression here....");
            functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
            functionField.setForeground(Color.GRAY);
        }

        @Override
        public void focusGained(FocusEvent e) {

            if (!functionField.getText().equals("Add function expression here....")) {
                return;
            }

            functionField.setForeground(Color.BLACK);
            functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
            functionField.setText("");
        }
    });

    // show the dialog
    dialog.setVisible(true);
}

From source file:atlas.kingj.roi.FrmMain.java

@SuppressWarnings("unused")
private void PopulateComboBox(JComboBox c, String[] elements) {
    for (int i = 0; i < elements.length; ++i) {
        c.addItem(elements[i]);
    }/*from   w w  w .j  a v  a  2  s.  c  o m*/
}

From source file:npm.modules.java

public boolean listtocombox(Document doc, JComboBox boxname, String parentnodename, String nodename) {
    boxname.removeAllItems();/*  ww  w  .j a  v a 2s  .  c  om*/
    NodeList nlist = doc.getElementsByTagName(parentnodename);
    for (int temp = 0; temp < nlist.getLength(); temp++) {
        //System.out.println(nodename +"---"+temp);
        Node nNode = nlist.item(temp);
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element eElement = (Element) nNode;
            boxname.addItem(eElement.getElementsByTagName(nodename).item(0).getTextContent());
        }
    }
    return true;
}

From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataElementCellEditor.java

public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected,
        final int rowIndex, final int vColIndex) {
    // 'value' is value contained in the cell located at (rowIndex,
    // vColIndex)

    final MetaDataTableModel model = (MetaDataTableModel) table.getModel();
    final IMetaDataTypeExtended type = model.getRow(rowIndex);
    final int maximumLength = type.getMaximumLength();
    switch (type.getDataType()) {
    case Date:
        cal.setFormats(DATE_FORMAT);/*from  ww w . ja v  a  2 s.c o m*/
        component = componentDatePicker;
        ((JXDatePicker) component).setDate(parseDate((String) value));
        break;
    case MultiSelect:
        component = componentCombo;
        final JComboBox box = (JComboBox) component;
        box.removeAllItems();
        box.addItem(new MetaDataListValues("", "", 0));
        int itemNo = 1;
        for (MetaDataListValues listValue : type.getListItems()) {
            box.addItem(listValue);
            if (listValue.getValue().equals(value)) {
                box.setSelectedIndex(itemNo);
            }
            itemNo++;
        }
        ((JComboBox) component).setSelectedItem((String) value);
        break;
    case Boolean:
        component = componentCheck;
        final boolean boolValue = Boolean.parseBoolean((String) value);
        ((JCheckBox) component).setSelected(boolValue);
        break;
    case Integer:
        component = componentWholeNumber;
        ((WholeNumberField) component).setText((String) value);
        break;
    case RealNumber:
        component = componentDecimal;
        ((DecimalNumberField) component).setText((String) value);
        break;
    case Text:
    default:
        component = componentText;
        ((MaxLengthTextField) component).setMaximumLength(maximumLength);
        if (value == null) {
            ((MaxLengthTextField) component).setText("");
        } else {
            ((MaxLengthTextField) component).setText((String) value);
        }
    }
    if (theStandardFont != null) {
        component.setFont(theStandardFont);
    }
    return component;
}

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

private JPanel getExecutionTypePanel(final ModelGraph graph, final ViewState state) {
    JPanel panel = new JPanel();
    panel.setBorder(new EtchedBorder());
    panel.setLayout(new BorderLayout());
    panel.add(new JLabel("ExecutionType:"), BorderLayout.WEST);
    JComboBox comboBox = new JComboBox();
    if (graph.hasChildren()) {
        comboBox.addItem("parallel");
        comboBox.addItem("sequential");
    } else if (graph.getModel().getExecutionType().equals("task")) {
        comboBox.addItem("parallel");
        comboBox.addItem("sequential");
        comboBox.addItem("task");
    } else if (graph.isCondition() || graph.getModel().getExecutionType().equals("condition")) {
        comboBox.addItem("parallel");
        comboBox.addItem("sequential");
        comboBox.addItem("condition");
    } else {/*www. ja v  a 2s.c om*/
        comboBox.addItem("parallel");
        comboBox.addItem("sequential");
        comboBox.addItem("task");
    }
    comboBox.setSelectedItem(graph.getModel().getExecutionType());
    comboBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (!graph.getModel().getExecutionType().equals(e.getItem())) {
                graph.getModel().setExecutionType((String) e.getItem());
                DefaultPropView.this.notifyListeners();
                DefaultPropView.this.refreshView(state);
            }
        }
    });
    panel.add(comboBox, BorderLayout.CENTER);
    return panel;
}

From source file:org.jets3t.gui.UserInputFields.java

/**
 * Builds a user input panel matching the fields specified in the uploader.properties file.
 *
 * @param fieldsPanel/*from ww  w  .  ja  v a2s . c  om*/
 * the panel component to add prompt and user input components to.
 * @param uploaderProperties
 * properties specific to the Uploader application that includes the field.* settings
 * necessary to build the User Inputs screen.
 *
 * @return
 * true if there is at least one valid user input field, false otherwise.
 */
public boolean buildFieldsPanel(JPanel fieldsPanel, Jets3tProperties uploaderProperties) {
    int fieldIndex = 0;

    for (int fieldNo = 0; fieldNo < 100; fieldNo++) {
        String fieldName = uploaderProperties.getStringProperty("field." + fieldNo + ".name", null);
        String fieldType = uploaderProperties.getStringProperty("field." + fieldNo + ".type", null);
        String fieldPrompt = uploaderProperties.getStringProperty("field." + fieldNo + ".prompt", null);
        String fieldOptions = uploaderProperties.getStringProperty("field." + fieldNo + ".options", null);
        String fieldDefault = uploaderProperties.getStringProperty("field." + fieldNo + ".default", null);

        if (fieldName == null) {
            log.debug("No field with index number " + fieldNo);
            continue;
        } else {
            if (fieldType == null || fieldPrompt == null) {
                log.warn("Field '" + fieldName + "' missing .type or .prompt properties");
                continue;
            }

            if ("message".equals(fieldType)) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
            } else if ("radio".equals(fieldType)) {
                if (fieldOptions == null) {
                    log.warn(
                            "Radio button field '" + fieldName + "' is missing the required .options property");
                    continue;
                }

                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                JPanel optionsPanel = skinsFactory.createSkinnedJPanel("OptionsPanel");
                optionsPanel.setLayout(new GridBagLayout());
                int columnOffset = 0;
                ButtonGroup buttonGroup = new ButtonGroup();
                StringTokenizer st = new StringTokenizer(fieldOptions, ",");
                while (st.hasMoreTokens()) {
                    String option = st.nextToken();
                    JRadioButton radioButton = skinsFactory.createSkinnedJRadioButton(fieldName);
                    radioButton.setText(option);
                    buttonGroup.add(radioButton);

                    if (fieldDefault != null && fieldDefault.equals(option)) {
                        // This option is the default one.
                        radioButton.setSelected(true);
                    } else if (buttonGroup.getButtonCount() == 1) {
                        // Make first button the default.
                        radioButton.setSelected(true);
                    }

                    optionsPanel.add(radioButton, new GridBagConstraints(columnOffset++, 0, 1, 1, 0, 0,
                            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
                }
                fieldsPanel.add(optionsPanel, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.NONE, insetsNone, 0, 0));

                userInputComponentsMap.put(fieldName, buttonGroup);
            } else if ("selection".equals(fieldType)) {
                if (fieldOptions == null) {
                    log.warn(
                            "Radio button field '" + fieldName + "' is missing the required .options property");
                    continue;
                }

                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                JComboBox comboBox = skinsFactory.createSkinnedJComboBox(fieldName);
                StringTokenizer st = new StringTokenizer(fieldOptions, ",");
                while (st.hasMoreTokens()) {
                    String option = st.nextToken();
                    comboBox.addItem(option);
                }

                if (fieldDefault != null) {
                    comboBox.setSelectedItem(fieldDefault);
                }

                fieldsPanel.add(comboBox, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, comboBox);
            } else if ("text".equals(fieldType)) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
                JTextField textField = skinsFactory.createSkinnedJTextField(fieldName);
                if (fieldDefault != null) {
                    textField.setText(fieldDefault);
                }

                fieldsPanel.add(textField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, textField);
            } else if ("password".equals(fieldType)) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
                JPasswordField passwordField = skinsFactory.createSkinnedJPasswordField(fieldName);
                if (fieldDefault != null) {
                    passwordField.setText(fieldDefault);
                }

                fieldsPanel.add(passwordField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0,
                        GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, passwordField);
            } else if (fieldType.equals("textarea")) {
                JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName);
                label.setText(fieldPrompt);
                label.setHyperlinkeActivatedListener(hyperlinkListener);
                fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 2, 1, 0, 0,
                        GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
                JTextArea textArea = skinsFactory.createSkinnedJTextArea(fieldName);
                textArea.setLineWrap(true);
                if (fieldDefault != null) {
                    textArea.setText(fieldDefault);
                }

                JScrollPane scrollPane = skinsFactory.createSkinnedJScrollPane(fieldName);
                scrollPane.setViewportView(textArea);
                fieldsPanel.add(scrollPane, new GridBagConstraints(0, fieldIndex++, 2, 1, 1, 1,
                        GridBagConstraints.WEST, GridBagConstraints.BOTH, insetsDefault, 0, 0));

                userInputComponentsMap.put(fieldName, textArea);
            } else {
                log.warn("Unrecognised .type setting for field '" + fieldName + "'");
            }
        }
    }

    return isUserInputFieldsAvailable();
}

From source file:org.netbeans.jpa.modeler.specification.model.util.JPAModelerUtil.java

public static void initEntityModel(javax.swing.JComboBox entityComboBox, EntityMappings entityMappings) {
    entityComboBox.removeAllItems();/*from   w  w  w. j  a  va  2  s  . co m*/
    entityComboBox.addItem(new ComboBoxValue(null, ""));
    entityMappings.getEntity().stream().forEach((entity) -> {
        entityComboBox.addItem(new ComboBoxValue(entity, entity.getClazz()));
    });
}