Example usage for javax.swing JComboBox setPreferredSize

List of usage examples for javax.swing JComboBox setPreferredSize

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:Main.java

public static void main(String[] args) {
    Object[] items = new Object[] { "Dog", "Cat", "Other" };
    DefaultComboBoxModel dcbm = new DefaultComboBoxModel(items);
    JComboBox comboBox = new JComboBox(dcbm);
    comboBox.setPreferredSize(new Dimension(200, 20));
    comboBox.addItemListener(e -> {/*from  w  w w  . j ava  2 s  .  co  m*/
        Object selectedItem = comboBox.getSelectedItem();
        boolean editable = selectedItem instanceof String && ((String) selectedItem).equals("Other");
        comboBox.setEditable(editable);
    });
    comboBox.getEditor().addActionListener(e -> {
        Object newItem = comboBox.getEditor().getItem();
        DefaultComboBoxModel d = (DefaultComboBoxModel) comboBox.getModel();
        d.addElement(newItem);
        d.setSelectedItem(newItem);

    });

    JPanel content = new JPanel(new FlowLayout());
    content.add(new JLabel("Test:"));
    content.add(comboBox);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(content);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void setComboLayout(JComboBox<?> combo, int w, int h, String name) {
    combo.setPreferredSize(getControlDimension(w, h));
    combo.setMinimumSize(getControlDimension(w, h));
    combo.setFont(getFont());//w w w .j a  v a2  s.  c o  m
    combo.setName(name);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java

public static void adjustSize(JComboBox comboBox) {
    comboBox.setPreferredSize(new Dimension(0, FIELD_HEIGHT));
}

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

public void doGui() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel noteLbl = new JLabel(
            "<html><div style='width : 500px;'>Pls select a value to choose an Weapon or you can create a new "
                    + "Weapon entity below. Once selected a weapon, its' details will be available below</div></html>");
    noteLbl.setAlignmentX(0);//from  ww  w . j  ava  2  s  .c  o m
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (Item item : GameBean.weaponDetails) {
        if (item instanceof Weapon) {
            model.addElement(((Weapon) item).getName());
        }
    }
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setAlignmentX(0);
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(Box.createVerticalStrut(10));
    add(comboBox);
    add(Box.createVerticalStrut(10));
    JPanel panel1 = new JPanel();
    panel1.setAlignmentX(0);
    panel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel1.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel weaponDtsLbl = new JLabel("Weapon Details : ");
    weaponDtsLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    panel1.add(weaponDtsLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    panel1.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    panel1.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel weaponTypeLbl = new JLabel("Weapon Type : ");
    panel1.add(weaponTypeLbl, c);
    c.gridx = 1;
    JComboBox weaponType = new JComboBox(Configuration.weaponTypes);
    weaponType.setSelectedIndex(0);
    weaponType.setPreferredSize(name.getPreferredSize());
    System.out.println(name.getPreferredSize());
    panel1.add(weaponType, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel attackRangeLbl = new JLabel("Attack Range : ");
    panel1.add(attackRangeLbl, c);
    c.gridx = 1;
    JTextField attackRange = new JTextField("");
    attackRange.setColumns(20);
    panel1.add(attackRange, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    panel1.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    panel1.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    panel1.add(submit, c);
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = 2;
    c.weighty = 0;
    c.weightx = 1;
    validationMess = new JLabel("Pls enter all the fields or pls choose a weapon from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    panel1.add(validationMess, c);
    //        c.fill = GridBagConstraints.BOTH;
    //        c.gridy = 7;
    //        c.weightx = 1;
    //        c.weighty = 1;
    //        panel1.add(new JLabel(""), c);
    panel1.setBorder(LineBorder.createGrayLineBorder());
    add(panel1);
    add(Box.createVerticalGlue());
}

From source file:Interface.Stats.java

/**
 *
 * @param f /*from  w  w w.j  a v a2s . c o m*/
 */
private Stats(JFrame f) {
    // On initialise les boutons
    JButton valider = new JButton("Valider");
    JButton retour = new JButton("Retour");
    JComboBox combo = new JComboBox();

    // On initialise et remplit la combobox
    combo.setPreferredSize(new Dimension(400, 30));
    combo.addItem("Nombre de patient par service");
    combo.addItem("Salaire moyen des employs");
    combo.addItem("Nombre d'intervention par mdecin");

    // On initialise les JLabels
    JLabel texte = new JLabel("Veuillez selectionner la requete  envoyer");

    // On change le bouton de forme
    valider.setPreferredSize(new Dimension(200, 30));
    valider.setOpaque(false);
    retour.setPreferredSize(new Dimension(200, 30));
    retour.setOpaque(false);

    // On initialise les Jpanels
    p1 = new JPanel();
    p1.setPreferredSize(new Dimension(600, 100));
    p1.add(texte);
    p1.setOpaque(false);

    p2 = new JPanel();
    p2.add(combo);
    p2.setOpaque(false);

    p4 = new JPanel();
    p4.add(retour);
    p4.add(valider);
    p4.setOpaque(false);

    // Gestion des boutons
    retour.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Accueil.getFenetre(f);
        }
    });

    valider.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (combo.getSelectedItem().equals("Nombre de patient par service")) {

                System.out.println(
                        "Nb de patients en REA : " + Connexion.getInstance().nb_malade_services("\"REA\""));
                System.out.println(
                        "Nb de patients en ORL : " + Connexion.getInstance().nb_malade_services("\"ORL\""));
                System.out.println(
                        "Nb de patients en CHG : " + Connexion.getInstance().nb_malade_services("\"CHG\""));

                //      new Camembert(f, Connexion.getInstance().nb_malade_services("\"REA\""), Connexion.getInstance().nb_malade_services("\"ORL\""), Connexion.getInstance().nb_malade_services("\"CHG\""));
                JPanel panel_camemb = Camembert.cCamembert(f,
                        Connexion.getInstance().nb_malade_services("\"REA\""),
                        Connexion.getInstance().nb_malade_services("\"ORL\""),
                        Connexion.getInstance().nb_malade_services("\"CHG\""));
                ;

                f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                f.add(p1);
                f.add(p2);
                f.add(p4);
                f.add(panel_camemb);

                f.setVisible(true);

            } else if (combo.getSelectedItem().equals("Salaire moyen des employs")) {
                JLabel jf_doc, jf_inf, jf_emp;
                JTextField jtf_doc, jtf_inf, jtf_emp;
                JPanel p5, p6, p7;

                // On initialise les JF
                jf_doc = new JLabel("Salaire moyen des docteurs");
                jf_inf = new JLabel("Salaire moyen des infirmiers");
                jf_emp = new JLabel("Salaire moyen de tous les employs");

                // On initialise les JTF
                jtf_doc = new JTextField();
                jtf_doc.setPreferredSize(new Dimension(200, 30));
                jtf_doc.setText(Float.toString(Connexion.getInstance().moyenne_salaired()) + " ");

                jtf_inf = new JTextField();
                jtf_inf.setPreferredSize(new Dimension(200, 30));
                jtf_inf.setText(Float.toString((Connexion.getInstance().moyenne_salairei())) + " ");

                jtf_emp = new JTextField();
                jtf_emp.setPreferredSize(new Dimension(160, 30));
                jtf_emp.setText(Float.toString((Connexion.getInstance().moyenne_salaire())) + " ");

                // On cre les JPanels
                p5 = new JPanel();
                p5.add(jf_doc);
                p5.add(jtf_doc);
                p5.setOpaque(false);

                p6 = new JPanel();
                p6.add(jf_inf);
                p6.add(jtf_inf);
                p6.setOpaque(false);

                p7 = new JPanel();
                p7.add(jf_emp);
                p7.add(jtf_emp);
                p7.setOpaque(false);

                f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                f.add(p1);
                f.add(p2);
                f.add(p4);
                f.add(p5);
                f.add(p6);
                f.add(p7);

                f.setVisible(true);
                f.setSize(new Dimension(600, 600));
            } else if (combo.getSelectedItem().equals("Nombre d'intervention par mdecin")) {
                ArrayList liste = null;
                try {
                    // ICI !!!!!!!!!!
                    liste = Connexion.getInstance().reporting(
                            "SELECT e.nom , COUNT(d.no_docteur) FROM hospitalisation h, docteur d , employe e WHERE (h.no_docteur= d.no_docteur) AND e.no_employe = d.no_docteur  GROUP BY e.nom");
                } catch (SQLException ex) {
                    Logger.getLogger(Stats.class.getName()).log(Level.SEVERE, null, ex);
                }
                if (liste != null) {
                    JPanel panel_camemb = Camembert.cCamembert(f, liste);

                    f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                    f.add(p1);
                    f.add(p2);
                    f.add(p4);
                    f.add(panel_camemb);

                    f.setVisible(true);
                }

            }
        }
    });
}

From source file:edu.virginia.iath.oxygenplugins.juel.JUELPluginMenu.java

public JUELPluginMenu(StandalonePluginWorkspace spw, LocalOptions ops) {
    super(name, true);
    ws = spw;//from  w w w. j  a  va  2 s . com
    options = ops;

    // setup the options
    //options.readStorage();

    // Find names
    JMenuItem search = new JMenuItem("Find Name");
    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent selection) {
            String label = "Find Name";

            final JTextField lastName = new JTextField("", 30);
            lastName.setPreferredSize(new Dimension(350, 25));
            //JTextField projectName = new JTextField("", 30);

            final JComboBox possibleVals = new JComboBox();
            possibleVals.setEnabled(false);
            possibleVals.setPreferredSize(new Dimension(350, 25));

            JButton search = new JButton("Search");
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent selection) {
                    // query the database
                    try {
                        String json = "";
                        String line;
                        URL url = new URL("http://juel.iath.virginia.edu/academical_db/people/find_people?term="
                                + lastName.getText());
                        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                        while ((line = in.readLine()) != null) {
                            json += line;
                        }
                        JSONArray obj = new JSONArray(json);

                        // Read the JSON and update possibleVals
                        possibleVals.removeAllItems();
                        possibleVals.setEnabled(false);

                        for (int i = 0; i < obj.length(); i++) {
                            JSONObject cur = obj.getJSONObject(i);
                            String name = cur.getString("label");
                            String id = String.format("P%05d", cur.getInt("value"));
                            possibleVals.addItem(new ComboBoxObject(name, id));
                            possibleVals.setEnabled(true);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        possibleVals.setEnabled(false);
                    }

                    return;
                }
            });
            search.setPreferredSize(new Dimension(100, 25));

            JButton insert = new JButton("Insert");
            insert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent sel) {
                    // Insert into the page
                    // Get the selected value, grab the ID, then insert into the document

                    // Get the editor
                    WSTextEditorPage ed = null;
                    WSEditor editorAccess = ws
                            .getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
                    if (editorAccess != null && editorAccess.getCurrentPage() instanceof WSTextEditorPage) {
                        ed = (WSTextEditorPage) editorAccess.getCurrentPage();
                    }

                    String result = "key=\"" + ((ComboBoxObject) possibleVals.getSelectedItem()).id + "\"";

                    // Update the text in the document
                    ed.beginCompoundUndoableEdit();
                    int selectionOffset = ed.getSelectionStart();
                    ed.deleteSelection();
                    javax.swing.text.Document doc = ed.getDocument();
                    try {
                        if (selectionOffset > 0 && !doc.getText(selectionOffset - 1, 1).equals(" "))
                            result = " " + result;
                        if (selectionOffset > 0 && !doc.getText(selectionOffset, 1).equals(" ")
                                && !doc.getText(selectionOffset, 1).equals(">"))
                            result = result + " ";
                        doc.insertString(selectionOffset, result, javax.swing.text.SimpleAttributeSet.EMPTY);
                    } catch (javax.swing.text.BadLocationException b) {
                        // Okay if it doesn't work
                    }
                    ed.endCompoundUndoableEdit();

                    return;
                }
            });
            insert.setPreferredSize(new Dimension(100, 25));

            java.awt.GridLayout layoutOuter = new java.awt.GridLayout(3, 1);
            java.awt.FlowLayout layout = new java.awt.FlowLayout(FlowLayout.RIGHT); // rows, columns

            JPanel addPanel = new JPanel();
            JPanel addPanelInner = new JPanel();
            addPanel.setLayout(layoutOuter);
            addPanel.add(new JLabel("Search for last name, then choose a full name from the list below"));
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Search Last Name: "));
            addPanelInner.add(lastName);
            addPanelInner.add(search);
            addPanel.add(addPanelInner);
            addPanelInner = new JPanel();
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Narrow Search: "));
            addPanelInner.add(possibleVals);
            addPanelInner.add(insert);
            addPanel.add(addPanelInner);

            JOptionPane.showMessageDialog((java.awt.Frame) ws.getParentFrame(), addPanel, label,
                    JOptionPane.PLAIN_MESSAGE);

        }
    });
    this.add(search);

    // Find places
    search = new JMenuItem("Find Place");
    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent selection) {
            String label = "Find Place";

            final JTextField searchText = new JTextField("", 30);
            searchText.setPreferredSize(new Dimension(350, 25));
            //JTextField projectName = new JTextField("", 30);

            final JComboBox possibleVals = new JComboBox();
            possibleVals.setEnabled(false);
            possibleVals.setPreferredSize(new Dimension(350, 25));

            JButton search = new JButton("Search");
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent selection) {
                    // query the database
                    try {
                        String json = "";
                        String line;
                        URL url = new URL(
                                "http://academical.village.virginia.edu/academical_db/places/find_places?term="
                                        + searchText.getText());
                        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                        while ((line = in.readLine()) != null) {
                            json += line;
                        }
                        JSONArray obj = new JSONArray(json);

                        // Read the JSON and update possibleVals
                        possibleVals.removeAllItems();
                        possibleVals.setEnabled(false);

                        for (int i = 0; i < obj.length(); i++) {
                            JSONObject cur = obj.getJSONObject(i);
                            String id = String.format("PL%04d", cur.getInt("value"));
                            String name = cur.getString("label") + " (" + id + ")";
                            possibleVals.addItem(new ComboBoxObject(name, id));
                            possibleVals.setEnabled(true);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        possibleVals.setEnabled(false);
                    }

                    return;
                }
            });
            search.setPreferredSize(new Dimension(100, 25));

            JButton insert = new JButton("Insert");
            insert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent sel) {
                    // Insert into the page
                    // Get the selected value, grab the ID, then insert into the document

                    // Get the editor
                    WSTextEditorPage ed = null;
                    WSEditor editorAccess = ws
                            .getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
                    if (editorAccess != null && editorAccess.getCurrentPage() instanceof WSTextEditorPage) {
                        ed = (WSTextEditorPage) editorAccess.getCurrentPage();
                    }

                    String result = "key=\"" + ((ComboBoxObject) possibleVals.getSelectedItem()).id + "\"";

                    // Update the text in the document
                    ed.beginCompoundUndoableEdit();
                    int selectionOffset = ed.getSelectionStart();
                    ed.deleteSelection();
                    javax.swing.text.Document doc = ed.getDocument();
                    try {
                        if (selectionOffset > 0 && !doc.getText(selectionOffset - 1, 1).equals(" "))
                            result = " " + result;
                        if (selectionOffset > 0 && !doc.getText(selectionOffset, 1).equals(" ")
                                && !doc.getText(selectionOffset, 1).equals(">"))
                            result = result + " ";
                        doc.insertString(selectionOffset, result, javax.swing.text.SimpleAttributeSet.EMPTY);
                    } catch (javax.swing.text.BadLocationException b) {
                        // Okay if it doesn't work
                    }
                    ed.endCompoundUndoableEdit();

                    return;
                }
            });
            insert.setPreferredSize(new Dimension(100, 25));

            java.awt.GridLayout layoutOuter = new java.awt.GridLayout(3, 1);
            java.awt.FlowLayout layout = new java.awt.FlowLayout(FlowLayout.RIGHT); // rows, columns

            JPanel addPanel = new JPanel();
            JPanel addPanelInner = new JPanel();
            addPanel.setLayout(layoutOuter);
            addPanel.add(new JLabel("Search for a place name, then choose one from the list below"));
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Search Keyword: "));
            addPanelInner.add(searchText);
            addPanelInner.add(search);
            addPanel.add(addPanelInner);
            addPanelInner = new JPanel();
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Narrow Search: "));
            addPanelInner.add(possibleVals);
            addPanelInner.add(insert);
            addPanel.add(addPanelInner);

            JOptionPane.showMessageDialog((java.awt.Frame) ws.getParentFrame(), addPanel, label,
                    JOptionPane.PLAIN_MESSAGE);

        }
    });
    this.add(search);

    // Find corporate bodies
    search = new JMenuItem("Find Corporate Body");
    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent selection) {
            String label = "Find Corporate Body";

            final JTextField searchText = new JTextField("", 30);
            searchText.setPreferredSize(new Dimension(350, 25));
            //JTextField projectName = new JTextField("", 30);

            final JComboBox possibleVals = new JComboBox();
            possibleVals.setEnabled(false);
            possibleVals.setPreferredSize(new Dimension(350, 25));

            JButton search = new JButton("Search");
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent selection) {
                    // query the database
                    try {
                        String json = "";
                        String line;
                        URL url = new URL(
                                "http://academical.village.virginia.edu/academical_db/corporate_bodies/find?term="
                                        + searchText.getText());
                        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                        while ((line = in.readLine()) != null) {
                            json += line;
                        }
                        JSONArray obj = new JSONArray(json);

                        // Read the JSON and update possibleVals
                        possibleVals.removeAllItems();
                        possibleVals.setEnabled(false);

                        for (int i = 0; i < obj.length(); i++) {
                            JSONObject cur = obj.getJSONObject(i);
                            String id = String.format("CB%04d", cur.getInt("value"));
                            String name = cur.getString("label") + " (" + id + ")";
                            possibleVals.addItem(new ComboBoxObject(name, id));
                            possibleVals.setEnabled(true);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        possibleVals.setEnabled(false);
                    }

                    return;
                }
            });
            search.setPreferredSize(new Dimension(100, 25));

            JButton insert = new JButton("Insert");
            insert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent sel) {
                    // Insert into the page
                    // Get the selected value, grab the ID, then insert into the document

                    // Get the editor
                    WSTextEditorPage ed = null;
                    WSEditor editorAccess = ws
                            .getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
                    if (editorAccess != null && editorAccess.getCurrentPage() instanceof WSTextEditorPage) {
                        ed = (WSTextEditorPage) editorAccess.getCurrentPage();
                    }

                    String result = "key=\"" + ((ComboBoxObject) possibleVals.getSelectedItem()).id + "\"";

                    // Update the text in the document
                    ed.beginCompoundUndoableEdit();
                    int selectionOffset = ed.getSelectionStart();
                    ed.deleteSelection();
                    javax.swing.text.Document doc = ed.getDocument();
                    try {
                        if (selectionOffset > 0 && !doc.getText(selectionOffset - 1, 1).equals(" "))
                            result = " " + result;
                        if (selectionOffset > 0 && !doc.getText(selectionOffset, 1).equals(" ")
                                && !doc.getText(selectionOffset, 1).equals(">"))
                            result = result + " ";
                        doc.insertString(selectionOffset, result, javax.swing.text.SimpleAttributeSet.EMPTY);
                    } catch (javax.swing.text.BadLocationException b) {
                        // Okay if it doesn't work
                    }
                    ed.endCompoundUndoableEdit();

                    return;
                }
            });
            insert.setPreferredSize(new Dimension(100, 25));

            java.awt.GridLayout layoutOuter = new java.awt.GridLayout(3, 1);
            java.awt.FlowLayout layout = new java.awt.FlowLayout(FlowLayout.RIGHT); // rows, columns

            JPanel addPanel = new JPanel();
            JPanel addPanelInner = new JPanel();
            addPanel.setLayout(layoutOuter);
            addPanel.add(new JLabel("Search for a corporate body, then one from the list below"));
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Search Keyword: "));
            addPanelInner.add(searchText);
            addPanelInner.add(search);
            addPanel.add(addPanelInner);
            addPanelInner = new JPanel();
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Narrow Search: "));
            addPanelInner.add(possibleVals);
            addPanelInner.add(insert);
            addPanel.add(addPanelInner);

            JOptionPane.showMessageDialog((java.awt.Frame) ws.getParentFrame(), addPanel, label,
                    JOptionPane.PLAIN_MESSAGE);

        }
    });
    this.add(search);

    // Find Courses
    search = new JMenuItem("Find Course");
    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent selection) {
            String label = "Find Course";

            final JTextField searchText = new JTextField("", 30);
            searchText.setPreferredSize(new Dimension(350, 25));
            //JTextField projectName = new JTextField("", 30);

            final JComboBox possibleVals = new JComboBox();
            possibleVals.setEnabled(false);
            possibleVals.setPreferredSize(new Dimension(350, 25));

            JButton search = new JButton("Search");
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent selection) {
                    // query the database
                    try {
                        String json = "";
                        String line;
                        URL url = new URL(
                                "http://academical.village.virginia.edu/academical_db/courses/find?term="
                                        + searchText.getText());
                        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                        while ((line = in.readLine()) != null) {
                            json += line;
                        }
                        JSONArray obj = new JSONArray(json);

                        // Read the JSON and update possibleVals
                        possibleVals.removeAllItems();
                        possibleVals.setEnabled(false);

                        for (int i = 0; i < obj.length(); i++) {
                            JSONObject cur = obj.getJSONObject(i);
                            String id = String.format("C%04d", cur.getInt("value"));
                            String name = cur.getString("label") + " (" + id + ")";
                            possibleVals.addItem(new ComboBoxObject(name, id));
                            possibleVals.setEnabled(true);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        possibleVals.setEnabled(false);
                    }

                    return;
                }
            });
            search.setPreferredSize(new Dimension(100, 25));

            JButton insert = new JButton("Insert");
            insert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent sel) {
                    // Insert into the page
                    // Get the selected value, grab the ID, then insert into the document

                    // Get the editor
                    WSTextEditorPage ed = null;
                    WSEditor editorAccess = ws
                            .getCurrentEditorAccess(StandalonePluginWorkspace.MAIN_EDITING_AREA);
                    if (editorAccess != null && editorAccess.getCurrentPage() instanceof WSTextEditorPage) {
                        ed = (WSTextEditorPage) editorAccess.getCurrentPage();
                    }

                    String result = "key=\"" + ((ComboBoxObject) possibleVals.getSelectedItem()).id + "\"";

                    // Update the text in the document
                    ed.beginCompoundUndoableEdit();
                    int selectionOffset = ed.getSelectionStart();
                    ed.deleteSelection();
                    javax.swing.text.Document doc = ed.getDocument();
                    try {
                        if (selectionOffset > 0 && !doc.getText(selectionOffset - 1, 1).equals(" "))
                            result = " " + result;
                        if (selectionOffset > 0 && !doc.getText(selectionOffset, 1).equals(" ")
                                && !doc.getText(selectionOffset, 1).equals(">"))
                            result = result + " ";
                        doc.insertString(selectionOffset, result, javax.swing.text.SimpleAttributeSet.EMPTY);
                    } catch (javax.swing.text.BadLocationException b) {
                        // Okay if it doesn't work
                    }
                    ed.endCompoundUndoableEdit();

                    return;
                }
            });
            insert.setPreferredSize(new Dimension(100, 25));

            java.awt.GridLayout layoutOuter = new java.awt.GridLayout(3, 1);
            java.awt.FlowLayout layout = new java.awt.FlowLayout(FlowLayout.RIGHT); // rows, columns

            JPanel addPanel = new JPanel();
            JPanel addPanelInner = new JPanel();
            addPanel.setLayout(layoutOuter);
            addPanel.add(new JLabel("Search for a course, then choose one from the list below"));
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Search Keyword: "));
            addPanelInner.add(searchText);
            addPanelInner.add(search);
            addPanel.add(addPanelInner);
            addPanelInner = new JPanel();
            addPanelInner.setLayout(layout);
            addPanelInner.add(new JLabel("Narrow Search: "));
            addPanelInner.add(possibleVals);
            addPanelInner.add(insert);
            addPanel.add(addPanelInner);

            JOptionPane.showMessageDialog((java.awt.Frame) ws.getParentFrame(), addPanel, label,
                    JOptionPane.PLAIN_MESSAGE);

        }
    });
    this.add(search);
}

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

/**
 * Helper factory method for creating a language selector that provides functionality to change the locale.
 *
 * @param width/*  w  w w . j  a va 2s  .c om*/
 *         the preferred width of the component in pixels
 * @return the newly created language selector
 */
protected JComboBox createLanguageSelector(int width) {
    Preconditions.checkArgument(width >= 0);
    final JComboBox<SupportedLocale> selector = new JComboBox(i18n.getSupportedLocales().toArray());
    selector.setSelectedItem(i18n.getCurrentSupportedLocale());
    selector.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            i18n.setLocale((SupportedLocale) selector.getSelectedItem());
        }
    });
    int height = selector.getPreferredSize().height;
    selector.setMinimumSize(new Dimension(width, height));
    selector.setMaximumSize(new Dimension(width, height));
    selector.setPreferredSize(new Dimension(width, height));
    selector.setMaximumRowCount(i18n.getSupportedLocales().size());
    selector.setComponentOrientation(ComponentOrientation.getOrientation(i18n.getLocale()));
    return selector;
}

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Metodo adibito alla creazione dinamica ricorsiva dell'interfaccia dei
 * metadati//  w w w.  j  av a  2s .c  o  m
 *
 * @param submetadatas Map contente i metadati e i sottolivelli di metadati
 * @param vocabularies Map contenente i dati contenuti nel file xml
 * vocabulary.xml
 * @param parent Jpanel nel quale devono venir inseriti i metadati
 * @param level Livello corrente
 */
public void create_metadata_view(Map<Object, Metadata> submetadatas, JPanel parent, int level,
        final String panelname) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader);
    int lenght = submetadatas.size();
    int labelwidth = 220;
    int i = 0;
    JButton addcontribute = null;

    for (Map.Entry<Object, Metadata> kv : submetadatas.entrySet()) {
        ArrayList<Component> tabobjects = new ArrayList<Component>();

        if (kv.getValue().MID == 17 || kv.getValue().MID == 23 || kv.getValue().MID == 18
                || kv.getValue().MID == 137) {
            continue;
        }

        //Crea un jpanel nuovo e fa appen su parent
        JPanel innerPanel = new JPanel(new MigLayout("fillx, insets 1 1 1 1"));
        innerPanel.setName("pannello" + level + i);

        i++;
        String datatype = kv.getValue().datatype.toString();

        if (kv.getValue().MID == 45) {
            JPanel choice = new JPanel(new MigLayout());

            JComboBox combo = addClassificationChoice(choice, kv.getValue().sequence, panelname);

            JLabel labelc = new JLabel();
            labelc.setText(Utility.getBundleString("selectclassif", bundle));
            labelc.setPreferredSize(new Dimension(100, 20));

            choice.add(labelc);

            findLastClassification(panelname);
            if (last_classification != 0 && classificationRemoveButton == null) {
                logger.info("Removing last clasification");
                classificationRemoveButton = new JButton("-");

                classificationRemoveButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        removeClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        findLastClassification(panelname); //update last_classification
                        BookImporter.getInstance().setCursor(null);
                    }
                });
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50:");
                }
            }

            if (classificationAddButton == null) {
                logger.info("Adding a new classification");
                choice.add(combo, "width 100:600:600");

                classificationAddButton = new JButton("+");

                classificationAddButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        addClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        BookImporter.getInstance().setCursor(null);
                    }
                });

                choice.add(classificationAddButton, "width :50:");
            } else {
                //choice.add(combo, "wrap,width 100:700:700");
                choice.add(combo, "width 100:700:700");
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50");
                }
            }
            parent.add(choice, "wrap,width 100:700:700");
            classificationMID = kv.getValue().MID;

            innerPanel.setName(panelname + "---ImPannelloClassif---" + kv.getValue().sequence);
            try {

                addClassification(innerPanel, classificationMID, kv.getValue().sequence, panelname);
            } catch (Exception ex) {
                logger.error("Errore nell'aggiunta delle classificazioni");
            }
            parent.add(innerPanel, "wrap, growx");
            BookImporter.policy.addIndexedComponent(combo);

            continue;
        }

        if (datatype.equals("Node")) {
            JLabel label = new JLabel();
            label.setText(kv.getValue().description);
            label.setPreferredSize(new Dimension(100, 20));

            int size = 16 - (level * 2);
            Font myFont = new Font("MS Sans Serif", Font.PLAIN, size);
            label.setFont(myFont);

            if (Integer.toString(kv.getValue().MID).equals("11")) {
                JPanel temppanel = new JPanel(new MigLayout());

                //update last_contribute
                findLastContribute(panelname);

                if (last_contribute != 0 && removeContribute == null) {
                    logger.info("Removing last contribute");
                    removeContribute = new JButton("-");

                    removeContribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            removeContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            innerPanel.add(removeContribute, "width :50:");
                        }
                    }
                }

                if (addcontribute == null) {
                    logger.info("Adding a new contribute");
                    addcontribute = new JButton("+");

                    addcontribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            addContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    temppanel.add(label, " width :200:");
                    temppanel.add(addcontribute, "width :50:");
                    innerPanel.add(temppanel, "wrap, growx");
                } else {
                    temppanel.add(label, " width :200:");
                    findLastContribute(panelname);
                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            temppanel.add(removeContribute, "width :50:");
                        }
                    }
                    innerPanel.add(temppanel, "wrap, growx");
                }
            } else if (Integer.toString(kv.getValue().MID).equals("115")) {
                logger.info("Devo gestire una provenience!");
            }
        } else {
            String title = "";

            if (kv.getValue().mandatory.equals("Y") || kv.getValue().MID == 14 || kv.getValue().MID == 15) {
                title = kv.getValue().description + " *";
            } else {
                title = kv.getValue().description;
            }

            innerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title,
                    TitledBorder.LEFT, TitledBorder.TOP));

            if (datatype.equals("Vocabulary")) {
                TreeMap<String, String> entryCombo = new TreeMap<String, String>();
                int index = 0;
                String selected = null;

                if (!Integer.toString(kv.getValue().MID).equals("8"))
                    entryCombo.put(Utility.getBundleString("comboselect", bundle),
                            Utility.getBundleString("comboselect", bundle));

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    String tempmid = Integer.toString(kv.getValue().MID);

                    if (Integer.toString(kv.getValue().MID_parent).equals("11")
                            || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                        String[] testmid = tempmid.split("---");
                        tempmid = testmid[0];
                    }

                    if (vc.getKey().equals(tempmid)) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);
                            if (kv.getValue().value != null) {
                                if (kv.getValue().value.equals(ivc.getValue().ID)) {
                                    selected = ivc.getValue().ID;
                                }
                            }
                            index++;
                        }
                    }
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.setVocabularyCombo(true);
                model.putAll(entryCombo);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                if (Integer.toString(kv.getValue().MID).equals("8") && selected == null)
                    selected = "44";

                selected = (selected == null) ? Utility.getBundleString("comboselect", bundle) : selected;

                for (int k = 0; k < voc.getItemCount(); k++) {
                    Map.Entry<String, String> el = (Map.Entry<String, String>) voc.getItemAt(k);
                    if (el.getValue().equals(selected))
                        voc.setSelectedIndex(k);
                }

                voc.setPreferredSize(new Dimension(150, 30));
                innerPanel.add(voc, "wrap, width :400:");
                tabobjects.add(voc);
            } else if (datatype.equals("CharacterString") || datatype.equals("GPS")) {
                final JTextArea textField = new javax.swing.JTextArea();

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    textField.setName(
                            "MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    textField.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                textField.setPreferredSize(new Dimension(230, 0));
                textField.setText(kv.getValue().value);
                textField.setLineWrap(true);
                textField.setWrapStyleWord(true);

                innerPanel.add(textField, "wrap, width :300:");

                textField.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                textField.transferFocusBackward();
                            } else {
                                textField.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });

                tabobjects.add(textField);
            } else if (datatype.equals("LangString")) {
                JScrollPane inner_scroll = new javax.swing.JScrollPane();
                inner_scroll.setHorizontalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                inner_scroll.setVerticalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
                inner_scroll.setPreferredSize(new Dimension(240, 80));
                inner_scroll.setName("langStringScroll");
                final JTextArea jTextArea1 = new javax.swing.JTextArea();
                jTextArea1.setName("MID_" + Integer.toString(kv.getValue().MID));
                jTextArea1.setText(kv.getValue().value);

                jTextArea1.setSize(new Dimension(350, 70));
                jTextArea1.setLineWrap(true);
                jTextArea1.setWrapStyleWord(true);

                inner_scroll.setViewportView(jTextArea1);
                innerPanel.add(inner_scroll, "width :300:");

                //Add combo language box
                JComboBox voc = getComboLangBox(kv.getValue().language);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "_lang");

                voc.setPreferredSize(new Dimension(200, 20));
                innerPanel.add(voc, "wrap, width :300:");

                jTextArea1.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                jTextArea1.transferFocusBackward();
                            } else {
                                jTextArea1.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });
                tabobjects.add(jTextArea1);
                tabobjects.add(voc);
            } else if (datatype.equals("Language")) {
                final JComboBox voc = getComboLangBox(kv.getValue().value);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID));

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");

                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);

            } else if (datatype.equals("Boolean")) {
                int selected = 0;
                TreeMap bin = new TreeMap<String, String>();
                bin.put("yes", Utility.getBundleString("voc1", bundle));
                bin.put("no", Utility.getBundleString("voc2", bundle));

                if (kv.getValue().value == null) {
                    switch (kv.getValue().MID) {
                    case 35:
                        selected = 0;
                        break;
                    case 36:
                        selected = 1;
                        break;
                    }
                } else if (kv.getValue().value.equals("yes")) {
                    selected = 1;
                } else {
                    selected = 0;
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.putAll(bin);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(selected);

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :300:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("License")) {
                String selectedIndex = null;
                int vindex = 0;
                int defaultIndex = 0;

                TreeMap<String, String> entryCombo = new TreeMap<String, String>();

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    if (vc.getKey().equals(Integer.toString(kv.getValue().MID))) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);

                            if (ivc.getValue().ID.equals("1"))
                                defaultIndex = vindex;

                            if (kv.getValue().value != null) {
                                if (ivc.getValue().ID.equals(kv.getValue().value)) {
                                    selectedIndex = Integer.toString(vindex);
                                }
                            }
                            vindex++;
                        }
                    }
                }

                if (selectedIndex == null)
                    selectedIndex = Integer.toString(defaultIndex);

                ComboMapImpl model = new ComboMapImpl();
                model.putAll(entryCombo);
                model.setVocabularyCombo(true);

                JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(Integer.parseInt(selectedIndex));
                voc.setPreferredSize(new Dimension(150, 20));

                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("DateTime")) {
                //final JXDatePicker datePicker = new JXDatePicker();
                JDateChooser datePicker = new JDateChooser();
                datePicker.setName("MID_" + Integer.toString(kv.getValue().MID));

                JPanel test = new JPanel(new MigLayout());
                JLabel lbefore = new JLabel(Utility.getBundleString("beforechristlabel", bundle));
                JCheckBox beforechrist = new JCheckBox();
                beforechrist.setName("MID_" + Integer.toString(kv.getValue().MID) + "_check");

                if (kv.getValue().value != null) {
                    try {
                        if (kv.getValue().value.charAt(0) == '-') {
                            beforechrist.setSelected(true);
                        }

                        Date date1 = new Date();
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        if (kv.getValue().value.charAt(0) == '-') {
                            date1 = sdf.parse(adjustDate(kv.getValue().value));
                        } else {
                            date1 = sdf.parse(kv.getValue().value);
                        }
                        datePicker.setDate(date1);
                    } catch (Exception e) {
                        //Console.WriteLine("ERROR import date:" + ex.Message);
                    }
                }

                test.add(datePicker, "width :200:");
                test.add(lbefore, "gapleft 30");
                test.add(beforechrist, "wrap");

                innerPanel.add(test, "wrap");
            }
        }

        //Recursive call
        create_metadata_view(kv.getValue().submetadatas, innerPanel, level + 1, panelname);

        if (kv.getValue().editable.equals("Y")
                || (datatype.equals("Node") && kv.getValue().hidden.equals("0"))) {
            parent.add(innerPanel, "wrap, growx");

            for (Component tabobject : tabobjects) {
                BookImporter.policy.addIndexedComponent(tabobject);
            }
        }
    }
}

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

private void prepareComPortControls() {
    E_Board1_comLabel = new javax.swing.JLabel();
    E_Board2_comLabel = new javax.swing.JLabel();
    E_Board3_comLabel = new javax.swing.JLabel();
    E_Board4_comLabel = new javax.swing.JLabel();
    GateBar1_comLabel = new javax.swing.JLabel();
    GateBar2_comLabel = new javax.swing.JLabel();
    GateBar3_comLabel = new javax.swing.JLabel();
    GateBar4_comLabel = new javax.swing.JLabel();

    E_Board1_comLabel.setName("E_Board1_comLabel"); // E_Board1_comLabel
    E_Board2_comLabel.setName("E_Board2_comLabel");
    E_Board3_comLabel.setName("E_Board3_comLabel");
    E_Board4_comLabel.setName("E_Board4_comLabel");
    GateBar1_comLabel.setName("GateBar1_comLabel");
    GateBar2_comLabel.setName("GateBar2_comLabel");
    GateBar3_comLabel.setName("GateBar3_comLabel");
    GateBar4_comLabel.setName("GateBar4_comLabel");

    augmentComponentMap(E_Board1_comLabel, componentMap);
    augmentComponentMap(E_Board2_comLabel, componentMap);
    augmentComponentMap(E_Board3_comLabel, componentMap);
    augmentComponentMap(E_Board4_comLabel, componentMap);
    augmentComponentMap(GateBar1_comLabel, componentMap);
    augmentComponentMap(GateBar2_comLabel, componentMap);
    augmentComponentMap(GateBar3_comLabel, componentMap);
    augmentComponentMap(GateBar4_comLabel, componentMap);

    initComPortIDLabel(E_Board1_comLabel);
    initComPortIDLabel(E_Board2_comLabel);
    initComPortIDLabel(E_Board3_comLabel);
    initComPortIDLabel(E_Board4_comLabel);
    initComPortIDLabel(GateBar1_comLabel);
    initComPortIDLabel(GateBar2_comLabel);
    initComPortIDLabel(GateBar3_comLabel);
    initComPortIDLabel(GateBar4_comLabel);

    E_Board1_comID_CBox = new JComboBox();
    E_Board2_comID_CBox = new JComboBox();
    E_Board3_comID_CBox = new JComboBox();
    E_Board4_comID_CBox = new JComboBox();
    GateBar1_comID_CBox = new JComboBox();
    GateBar2_comID_CBox = new JComboBox();
    GateBar3_comID_CBox = new JComboBox();
    GateBar4_comID_CBox = new JComboBox();

    E_Board1_comID_CBox.setName("E_Board1_comID_CBox");
    E_Board2_comID_CBox.setName("E_Board2_comID_CBox");
    E_Board3_comID_CBox.setName("E_Board3_comID_CBox");
    E_Board4_comID_CBox.setName("E_Board4_comID_CBox");
    GateBar1_comID_CBox.setName("GateBar1_comID_CBox");
    GateBar2_comID_CBox.setName("GateBar2_comID_CBox");
    GateBar3_comID_CBox.setName("GateBar3_comID_CBox");
    GateBar4_comID_CBox.setName("GateBar4_comID_CBox");

    augmentComponentMap(E_Board1_comID_CBox, componentMap);
    augmentComponentMap(E_Board2_comID_CBox, componentMap);
    augmentComponentMap(E_Board3_comID_CBox, componentMap);
    augmentComponentMap(E_Board4_comID_CBox, componentMap);
    augmentComponentMap(GateBar1_comID_CBox, componentMap);
    augmentComponentMap(GateBar2_comID_CBox, componentMap);
    augmentComponentMap(GateBar3_comID_CBox, componentMap);
    augmentComponentMap(GateBar4_comID_CBox, componentMap);

    //<editor-fold desc="-- Initialize other properties of COM ID combobox">
    for (int gate = 1; gate <= gateCount; gate++) {
        for (final DeviceType devType : DeviceType.values()) {
            String name = devType.name() + gate + "_comID_CBox";
            final JComboBox comIDcBox = ((JComboBox) getComponentByName(name));

            if (comIDcBox != null) {
                comIDcBox.setFont(new java.awt.Font(font_Type, font_Style, font_Size));
                comIDcBox.setModel(new javax.swing.DefaultComboBoxModel(
                        new String[] { "1", "2", "3", "4", "5", "6", "7", "8" }));
                comIDcBox.setMinimumSize(new java.awt.Dimension(50, CBOX_HEIGHT));
                comIDcBox.setPreferredSize(new java.awt.Dimension(50, CBOX_HEIGHT));
                final int gateNo = gate;

                comIDcBox.addItemListener(new java.awt.event.ItemListener() {
                    public void itemStateChanged(java.awt.event.ItemEvent evt) {
                        if (evt.getStateChange() == ItemEvent.SELECTED) {
                            String COM_ID = (String) comIDcBox.getSelectedItem();
                            if (COM_ID.equals(deviceComID[devType.ordinal()][gateNo])) {
                                changedControls.remove(comIDcBox);
                            } else {
                                changedControls.add(comIDcBox);
                            }/*from   www  . ja va 2  s. com*/
                        }
                    }
                });
            }
        }
    }
    //</editor-fold>
}

From source file:org.ut.biolab.medsavant.client.filter.TagFilterView.java

public TagFilterView(int queryID) {
    super(FILTER_NAME, queryID);

    setLayout(new BorderLayout());
    setBorder(ViewUtil.getBigBorder());//from w  w  w  .jav a  2s  . co m
    setMaximumSize(new Dimension(200, 80));

    JPanel cp = new JPanel();
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    c.gridx = 0;
    c.gridy = 0;

    cp.setLayout(gbl);

    variantTags = new ArrayList<VariantTag>();
    appliedTags = new ArrayList<VariantTag>();

    clear = new JButton("Clear");
    applyButton = new JButton("Apply");

    try {
        final JComboBox tagNameCB = new JComboBox();
        //tagNameCB.setMaximumSize(new Dimension(1000,30));

        final JComboBox tagValueCB = new JComboBox();
        //tagValueCB.setMaximumSize(new Dimension(1000,30));

        JPanel bottomContainer = new JPanel();
        ViewUtil.applyHorizontalBoxLayout(bottomContainer);

        List<String> tagNames = MedSavantClient.VariantManager
                .getDistinctTagNames(LoginController.getSessionID());

        for (String tag : tagNames) {
            tagNameCB.addItem(tag);
        }

        ta = new JTextArea();
        ta.setRows(10);
        ta.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        ta.setEditable(false);

        applyButton.setEnabled(false);

        JLabel addButton = ViewUtil
                .createIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.ADD));
        addButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {

                if (tagNameCB.getSelectedItem() == null || tagValueCB.getSelectedItem() == null) {
                    return;
                }

                VariantTag tag = new VariantTag((String) tagNameCB.getSelectedItem(),
                        (String) tagValueCB.getSelectedItem());
                if (variantTags.isEmpty()) {
                    ta.append(tag.toString() + "\n");
                } else {
                    ta.append("AND " + tag.toString() + "\n");
                }
                variantTags.add(tag);
                applyButton.setEnabled(true);
            }
        });

        clear.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                variantTags.clear();
                ta.setText("");
                applyButton.setEnabled(true);
            }
        });

        int width = 150;

        ta.setPreferredSize(new Dimension(width, width));
        ta.setMaximumSize(new Dimension(width, width));
        tagNameCB.setPreferredSize(new Dimension(width, 25));
        tagValueCB.setPreferredSize(new Dimension(width, 25));
        tagNameCB.setMaximumSize(new Dimension(width, 25));
        tagValueCB.setMaximumSize(new Dimension(width, 25));

        cp.add(new JLabel("Name"), c);
        c.gridx++;
        cp.add(tagNameCB, c);
        c.gridx++;

        c.gridx = 0;
        c.gridy++;

        cp.add(new JLabel("Value"), c);
        c.gridx++;
        cp.add(tagValueCB, c);
        c.gridx++;
        cp.add(addButton, c);

        tagNameCB.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent ie) {
                updateTagValues((String) tagNameCB.getSelectedItem(), tagValueCB);
            }
        });

        if (tagNameCB.getItemCount() > 0) {
            tagNameCB.setSelectedIndex(0);
            updateTagValues((String) tagNameCB.getSelectedItem(), tagValueCB);
        }

        al = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                applyButton.setEnabled(false);

                appliedTags = new ArrayList<VariantTag>(variantTags);

                Filter f = new Filter() {

                    @Override
                    public Condition[] getConditions() {
                        try {
                            List<Integer> uploadIDs = MedSavantClient.VariantManager
                                    .getUploadIDsMatchingVariantTags(LoginController.getSessionID(),
                                            TagFilterView.tagsToStringArray(variantTags));

                            Condition[] uploadIDConditions = new Condition[uploadIDs.size()];

                            TableSchema table = MedSavantClient.CustomTablesManager.getCustomTableSchema(
                                    LoginController.getSessionID(),
                                    MedSavantClient.ProjectManager.getVariantTableName(
                                            LoginController.getSessionID(),
                                            ProjectController.getInstance().getCurrentProjectID(),
                                            ReferenceController.getInstance().getCurrentReferenceID(), true));

                            for (int i = 0; i < uploadIDs.size(); i++) {
                                uploadIDConditions[i] = BinaryCondition.equalTo(
                                        table.getDBColumn(BasicVariantColumns.UPLOAD_ID), uploadIDs.get(i));
                            }

                            return new Condition[] { ComboCondition.or(uploadIDConditions) };
                        } catch (Exception ex) {
                            ClientMiscUtils.reportError("Error getting upload IDs: %s", ex);
                        }
                        return new Condition[0];
                    }

                    @Override
                    public String getName() {
                        return FILTER_NAME;
                    }

                    @Override
                    public String getID() {
                        return FILTER_ID;
                    }
                };
                FilterController.getInstance().addFilter(f, TagFilterView.this.queryID);
            }
        };

        applyButton.addActionListener(al);

        bottomContainer.add(Box.createHorizontalGlue());
        bottomContainer.add(clear);
        bottomContainer.add(applyButton);

        add(ViewUtil.getClearBorderedScrollPane(ta), BorderLayout.CENTER);
        add(bottomContainer, BorderLayout.SOUTH);

    } catch (Exception ex) {
        ClientMiscUtils.checkSQLException(ex);
    }

    add(cp, BorderLayout.NORTH);

    this.showViewCard();
}