Example usage for javax.swing JComboBox setName

List of usage examples for javax.swing JComboBox setName

Introduction

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

Prototype

public void setName(String name) 

Source Link

Document

Sets the name of the component to the specified string.

Usage

From source file:ItemTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    ItemListener listener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            System.out.println("Source: " + name(e.getSource()));
            System.out.println("Item: " + name(e.getItem()));
            int state = e.getStateChange();
            System.out.println("State: " + ((state == ItemEvent.SELECTED) ? "Selected" : "Deselected"));
        }//from w ww  . j  av a  2 s . co  m

        private String name(Object o) {
            if (o instanceof JComponent) {
                JComponent comp = (JComponent) o;
                return comp.getName();
            } else {
                return o.toString();
            }
        }
    };

    JPanel panel = new JPanel(new GridLayout(0, 1));
    ButtonGroup group = new ButtonGroup();
    JRadioButton option = new JRadioButton("French Fries", true);
    option.setName(option.getText());
    option.addItemListener(listener);
    group.add(option);
    panel.add(option);
    option = new JRadioButton("Onion Rings", false);
    option.setName(option.getText());
    option.addItemListener(listener);
    group.add(option);
    panel.add(option);
    option = new JRadioButton("Ice Cream", false);
    option.setName(option.getText());
    option.addItemListener(listener);
    group.add(option);
    panel.add(option);
    contentPane.add(panel, BorderLayout.NORTH);

    String flavors[] = { "Item 1", "Item 2", "Item 3" };
    JComboBox jc = new JComboBox(flavors);
    jc.setName("Combo");
    jc.addItemListener(listener);
    jc.setMaximumRowCount(4);
    contentPane.add(jc, BorderLayout.SOUTH);

    frame.pack();
    frame.show();
}

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());/*from w w  w . j  a  v  a  2s .co m*/
    combo.setName(name);
}

From source file:com.eviware.soapui.support.editor.inspectors.auth.ExpirationTimeChooser.java

private JComboBox createTimeUnitCombo(boolean enableManualTimeControls) {
    JComboBox timeUnitCombo = new JComboBox(TIME_UNIT_OPTIONS);
    timeUnitCombo.setName(TIME_UNIT_COMBO_NAME);
    timeUnitCombo.setEnabled(enableManualTimeControls);

    TimeUnitConfig.Enum timeUnit = profile.getManualAccessTokenExpirationTimeUnit();
    timeUnitCombo.setSelectedItem(WordUtils.capitalize(timeUnit.toString().toLowerCase()));

    return timeUnitCombo;
}

From source file:es.emergya.ui.gis.popups.GenericDialog.java

protected void addComboBox(Object selected, Object[] options, String title) {
    rows++;/*from   ww w .j  ava2  s.  c o  m*/
    mid.add(new JLabel(i18n.getString(title), JLabel.RIGHT));
    JComboBox cb = new JComboBox(options);
    cb.setName(title);
    cb.setSelectedItem(selected);
    mid.add(cb);
    componentes.add(cb);
    for (int i = 2; i < cols; i++)
        mid.add(Box.createHorizontalGlue());
}

From source file:es.emergya.ui.plugins.forms.FormGeneric.java

protected void addComboBox(Object selected, Object[] options, String title) {
    rows++;/*from www .ja  v  a 2  s.c om*/
    mid.add(new JLabel(i18n.getString(title), JLabel.RIGHT));
    JComboBox cb = new JComboBox(options);
    cb.setSelectedItem(selected);
    cb.setName(title);
    componentes.add(cb);
    mid.add(cb);
    for (int i = 2; i < cols; i++)
        mid.add(Box.createHorizontalGlue());
}

From source file:cool.pandora.modeller.ui.jpanel.base.SaveBagFrame.java

private JPanel createComponents() {
    final Border border = new EmptyBorder(5, 5, 5, 5);

    final TitlePane titlePane = new TitlePane();
    initStandardCommands();/* w  ww .  j  a v a  2  s  .c om*/
    final JPanel pageControl = new JPanel(new BorderLayout());
    final JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("SaveBagFrame.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Define the Bag " + "settings")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);
    final JPanel contentPane = new JPanel();

    // TODO: Add bag name field
    // TODO: Add save name file selection button
    final JLabel location = new JLabel("Save in:");
    final JButton browseButton = new JButton(getMessage("bag.button.browse"));
    browseButton.addActionListener(new SaveBagAsHandler());
    browseButton.setEnabled(true);
    browseButton.setToolTipText(getMessage("bag.button.browse.help"));
    final DefaultBag bag = bagView.getBag();
    if (bag != null) {
        bagNameField = new JTextField(bag.getName());
        bagNameField.setCaretPosition(bag.getName().length());
        bagNameField.setEditable(false);
        bagNameField.setEnabled(false);
    }

    // Holey bag control
    final JLabel holeyLabel = new JLabel(bagView.getPropertyMessage("bag.label.isholey"));
    holeyLabel.setToolTipText(bagView.getPropertyMessage("bag.isholey.help"));
    final JCheckBox holeyCheckbox = new JCheckBox(bagView.getPropertyMessage("bag.checkbox" + ".isholey"));
    holeyCheckbox.setBorder(border);
    holeyCheckbox.addActionListener(new HoleyBagHandler());
    holeyCheckbox.setToolTipText(bagView.getPropertyMessage("bag.isholey.help"));

    urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label"));
    urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description"));
    urlField = new JTextField("");
    try {
        assert bag != null;
        urlField.setText(bag.getFetch().getBaseURL());
    } catch (Exception e) {
        log.error("Failed to set url label", e);
    }
    urlField.setEnabled(false);

    // TODO: Add format label
    final JLabel serializeLabel;
    serializeLabel = new JLabel(getMessage("bag.label.ispackage"));
    serializeLabel.setToolTipText(getMessage("bag.serializetype.help"));

    // TODO: Add format selection panel
    noneButton = new JRadioButton(getMessage("bag.serializetype.none"));
    noneButton.setEnabled(true);
    final AbstractAction serializeListener = new SerializeBagHandler();
    noneButton.addActionListener(serializeListener);
    noneButton.setToolTipText(getMessage("bag.serializetype.none.help"));

    zipButton = new JRadioButton(getMessage("bag.serializetype.zip"));
    zipButton.setEnabled(true);
    zipButton.addActionListener(serializeListener);
    zipButton.setToolTipText(getMessage("bag.serializetype.zip.help"));

    /*
     * tarButton = new JRadioButton(getMessage("bag.serializetype.tar"));
     * tarButton.setEnabled(true);
     * tarButton.addActionListener(serializeListener);
     * tarButton.setToolTipText(getMessage("bag.serializetype.tar.help"));
     *
     * tarGzButton = new JRadioButton(getMessage("bag.serializetype.targz"));
     * tarGzButton.setEnabled(true);
     * tarGzButton.addActionListener(serializeListener);
     * tarGzButton.setToolTipText(getMessage("bag.serializetype.targz.help"));
     *
     * tarBz2Button = new JRadioButton(getMessage("bag.serializetype.tarbz2"));
     * tarBz2Button.setEnabled(true);
     * tarBz2Button.addActionListener(serializeListener);
     * tarBz2Button.setToolTipText(getMessage("bag.serializetype.tarbz2.help"));
     */

    short mode = 2;
    if (bag != null) {
        mode = bag.getSerialMode();
    }
    if (mode == DefaultBag.NO_MODE) {
        this.noneButton.setEnabled(true);
    } else if (mode == DefaultBag.ZIP_MODE) {
        this.zipButton.setEnabled(true);
    } else {
        this.noneButton.setEnabled(true);
    }

    final ButtonGroup serializeGroup = new ButtonGroup();
    serializeGroup.add(noneButton);
    serializeGroup.add(zipButton);
    // serializeGroup.add(tarButton);
    // serializeGroup.add(tarGzButton);
    // serializeGroup.add(tarBz2Button);
    final JPanel serializeGroupPanel = new JPanel(new FlowLayout());
    serializeGroupPanel.add(serializeLabel);
    serializeGroupPanel.add(noneButton);
    serializeGroupPanel.add(zipButton);
    // serializeGroupPanel.add(tarButton);
    // serializeGroupPanel.add(tarGzButton);
    // serializeGroupPanel.add(tarBz2Button);
    serializeGroupPanel.setBorder(border);
    serializeGroupPanel.setEnabled(true);
    serializeGroupPanel.setToolTipText(bagView.getPropertyMessage("bag.serializetype.help"));

    final JLabel tagLabel = new JLabel(getMessage("bag.label.istag"));
    tagLabel.setToolTipText(getMessage("bag.label.istag.help"));
    final JCheckBox isTagCheckbox = new JCheckBox();
    isTagCheckbox.setBorder(border);
    isTagCheckbox.addActionListener(new TagManifestHandler());
    isTagCheckbox.setToolTipText(getMessage("bag.checkbox.istag.help"));

    final JLabel tagAlgorithmLabel = new JLabel(getMessage("bag.label.tagalgorithm"));
    tagAlgorithmLabel.setToolTipText(getMessage("bag.label.tagalgorithm.help"));
    final ArrayList<String> listModel = new ArrayList<>();
    for (final Algorithm algorithm : Algorithm.values()) {
        listModel.add(algorithm.bagItAlgorithm);
    }
    final JComboBox<String> tagAlgorithmList = new JComboBox<>(listModel.toArray(new String[listModel.size()]));
    tagAlgorithmList.setName(getMessage("bag.tagalgorithmlist"));
    tagAlgorithmList.addActionListener(new TagAlgorithmListHandler());
    tagAlgorithmList.setToolTipText(getMessage("bag.tagalgorithmlist.help"));

    final JLabel payloadLabel = new JLabel(getMessage("bag.label.ispayload"));
    payloadLabel.setToolTipText(getMessage("bag.ispayload.help"));
    final JCheckBox isPayloadCheckbox = new JCheckBox();
    isPayloadCheckbox.setBorder(border);
    isPayloadCheckbox.addActionListener(new PayloadManifestHandler());
    isPayloadCheckbox.setToolTipText(getMessage("bag.ispayload.help"));

    final JLabel payAlgorithmLabel = new JLabel(bagView.getPropertyMessage("bag.label" + ".payalgorithm"));
    payAlgorithmLabel.setToolTipText(getMessage("bag.payalgorithm.help"));
    final JComboBox<String> payAlgorithmList = new JComboBox<String>(
            listModel.toArray(new String[listModel.size()]));
    payAlgorithmList.setName(getMessage("bag.payalgorithmlist"));
    payAlgorithmList.addActionListener(new PayAlgorithmListHandler());
    payAlgorithmList.setToolTipText(getMessage("bag.payalgorithmlist.help"));

    //only if bag is not null
    if (bag != null) {
        final String fileName = bag.getName();
        bagNameField = new JTextField(fileName);
        bagNameField.setCaretPosition(fileName.length());

        holeyCheckbox.setSelected(bag.isHoley());
        urlLabel.setEnabled(bag.isHoley());
        isTagCheckbox.setSelected(bag.isBuildTagManifest());
        tagAlgorithmList.setSelectedItem(bag.getTagManifestAlgorithm());
        isPayloadCheckbox.setSelected(bag.isBuildPayloadManifest());
        payAlgorithmList.setSelectedItem(bag.getPayloadManifestAlgorithm());
    }

    final GridBagLayout layout = new GridBagLayout();
    final GridBagConstraints glbc = new GridBagConstraints();
    final JPanel panel = new JPanel(layout);
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));

    int row = 0;

    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(location, glbc);
    panel.add(location);

    buildConstraints(glbc, 2, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.EAST);
    glbc.ipadx = 5;
    layout.setConstraints(browseButton, glbc);
    glbc.ipadx = 0;
    panel.add(browseButton);

    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
    glbc.ipadx = 5;
    layout.setConstraints(bagNameField, glbc);
    glbc.ipadx = 0;
    panel.add(bagNameField);

    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(holeyLabel, glbc);
    panel.add(holeyLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.WEST, GridBagConstraints.WEST);
    layout.setConstraints(holeyCheckbox, glbc);
    panel.add(holeyCheckbox);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(urlLabel, glbc);
    panel.add(urlLabel);
    buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(urlField, glbc);
    panel.add(urlField);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(serializeLabel, glbc);
    panel.add(serializeLabel);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
    layout.setConstraints(serializeGroupPanel, glbc);
    panel.add(serializeGroupPanel);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(tagLabel, glbc);
    panel.add(tagLabel);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(isTagCheckbox, glbc);
    panel.add(isTagCheckbox);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(tagAlgorithmLabel, glbc);
    panel.add(tagAlgorithmLabel);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(tagAlgorithmList, glbc);
    panel.add(tagAlgorithmList);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(payloadLabel, glbc);
    panel.add(payloadLabel);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(isPayloadCheckbox, glbc);
    panel.add(isPayloadCheckbox);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    layout.setConstraints(payAlgorithmLabel, glbc);
    panel.add(payAlgorithmLabel);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
    layout.setConstraints(payAlgorithmList, glbc);
    panel.add(payAlgorithmList);
    row++;
    buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST);
    buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);

    GuiStandardUtils.attachDialogBorder(contentPane);
    pageControl.add(panel);
    final JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;

}

From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java

/**
 * Creates the proper UI component for the Mapping item.
 * @param dbFieldType the field type/* w  w  w  .ja  v  a 2 s  .  c  o m*/
 * @param caption the caption
 * @param fieldName the name of the field
 * @param dataFieldLength the length of the definition for that field
 * @param fieldType the field type
 * @return a UI component for editing
 */
protected JComponent createUIComp(final Class<?> dbFieldTypeArg, final String caption, final String fieldName,
        final Short fieldType, final Short fieldLength, final short columns, final short rows,
        final WorkbenchTemplateMappingItem wbtmi) {
    short uiType = WorkbenchTemplateMappingItem.UNKNOWN;
    //System.out.println(wbtmi.getCaption()+" "+wbtmi.getDataType()+" "+wbtmi.getFieldLength());
    Class<?> dbFieldType = dbFieldTypeArg;
    if (dbFieldType == null) {
        // if we can't find a class for the field (i.e. Genus Species, or other 'fake' fields), we say it's a string
        dbFieldType = String.class;
    }

    JComponent comp;
    Component focusComp;

    // handle dates
    if (dbFieldType.equals(Calendar.class) || dbFieldType.equals(Date.class)) {
        //ValFormattedTextField txt = new ValFormattedTextField("Date"); 
        //txt.setColumns(columns == -1 ? DEFAULT_TEXTFIELD_COLS : columns);
        ValTextField txt = new ValTextField(columns);
        txt.getDocument().addDocumentListener(docListener);
        comp = txt;
        focusComp = comp;
        uiType = WorkbenchTemplateMappingItem.TEXTFIELD_DATE;
    }
    //        else if (dbFieldType.equals(Boolean.class)) // strings
    //        {
    //            ValCheckBox checkBox = new ValCheckBox(caption, false, false);
    //            checkBox.addChangeListener(changeListener);
    //            comp      = checkBox;
    //            focusComp = comp;
    //            uiType = WorkbenchTemplateMappingItem.CHECKBOX;
    //        }
    else if (useComboBox(wbtmi)) {
        //ValComboBox comboBox = new ValComboBox(getValues(wbtmi), true);

        final JComboBox comboBox = new JComboBox(getValues(wbtmi));
        comboBox.setName("Form Combo");
        comboBox.setEditable(true);
        comboBox.addActionListener(new ActionListener() {

            /* (non-Javadoc)
             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
             */
            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (arg0.getSource() == comboBox) {
                    //System.out.println("ComboBox Action!" + ((JComboBox )arg0.getSource()).getName());
                    stateChange();
                }
            }

        });
        //           comboBox.getEditor().getEditorComponent().addFocusListener(new FocusListener() {
        //
        //            /* (non-Javadoc)
        //             * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
        //             */
        //            @Override
        //            public void focusGained(FocusEvent arg0) {
        //               System.out.println("FOCUS GAINED");
        //               
        //            }
        //
        //            /* (non-Javadoc)
        //             * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
        //             */
        //            @Override
        //            public void focusLost(FocusEvent arg0) {
        //               System.out.println("FOCUS LOST");
        //               
        //            }
        //              
        //           });
        comp = comboBox;
        focusComp = comp;
        uiType = WorkbenchTemplateMappingItem.COMBOBOX;
    } else if (useTextField(fieldName, fieldType, fieldLength)) {
        ValTextField txt = new ValTextField(columns);
        txt.getDocument().addDocumentListener(docListener);
        txt.setInputVerifier(new LengthInputVerifier(caption, fieldLength));
        comp = txt;
        focusComp = comp;
        uiType = WorkbenchTemplateMappingItem.TEXTFIELD;

    } else {
        JScrollPane taScrollPane = createTextArea(columns, rows);
        ((JTextArea) taScrollPane.getViewport().getView())
                .setInputVerifier(new LengthInputVerifier(caption, fieldLength));
        comp = taScrollPane;
        focusComp = taScrollPane.getViewport().getView();
        uiType = WorkbenchTemplateMappingItem.TEXTAREA;
    }

    wbtmi.setFieldType(uiType);

    focusComp.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
            selectControl(e.getSource());
        }

        public void focusLost(FocusEvent e) {
            //stateChange();
        }
    });

    comp.setEnabled(!readOnly);
    focusComp.setEnabled(!readOnly);

    comp.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!readOnly) {
                if ((e.isControlDown() || e.isMetaDown()) && e.getKeyCode() == KeyEvent.VK_N) {
                    workbenchPane.addRowAfter();
                }
            }
            super.keyTyped(e);
        }

    });
    return comp;
}

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

/**
 * Metodo adibito alla creazione dinamica ricorsiva dell'interfaccia dei
 * metadati/*from   ww  w .  j  a  v 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:org.spiderplan.tools.visulization.GraphFrame.java

/**
 * @param graph// w  ww .  j  a  v  a2s .  c  o m
 * @param history optional history of the graph
 * @param title 
 * @param lC the layout
 * @param edgeLabels map from edges to string labels
 * @param w width of the window
 * @param h height of the window
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public GraphFrame(AbstractTypedGraph<V, E> graph, Vector<AbstractTypedGraph<V, E>> history, String title,
        LayoutClass lC, Map<E, String> edgeLabels, int w, int h) {
    super(title);
    this.edgeLabels = edgeLabels;
    this.g = new ObservableGraph<V, E>(graph);
    this.g.addGraphEventListener(this);

    this.defaultEdgeType = this.g.getDefaultEdgeType();

    this.layoutClass = lC;

    this.history = history;

    this.setLayout(lC);

    layout.setSize(new Dimension(w, h));

    try {
        Relaxer relaxer = new VisRunner((IterativeContext) layout);
        relaxer.stop();
        relaxer.prerelax();
    } catch (java.lang.ClassCastException e) {
    }

    //      Layout<V,E> staticLayout = new StaticLayout<V,E>(g, layout);
    //      Layout<V,E> staticLayout = new SpringLayout<V, E>(g);

    vv = new VisualizationViewer<V, E>(layout, new Dimension(w, h));

    JRootPane rp = this.getRootPane();
    rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().setBackground(java.awt.Color.lightGray);
    getContentPane().setFont(new Font("Serif", Font.PLAIN, 10));

    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S);
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<V>());
    vv.setForeground(Color.black);

    graphMouse = new EditingModalGraphMouse<V, E>(vv.getRenderContext(), null, null);
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    //        vv.getRenderContext().setEd
    vv.getRenderContext().setEdgeLabelTransformer(this);
    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<E>(vv.getPickedEdgeState(), Color.black, Color.cyan));

    vv.addComponentListener(new ComponentAdapter() {

        /**
         * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent)
         */
        @Override
        public void componentResized(ComponentEvent arg0) {
            super.componentResized(arg0);
            layout.setSize(arg0.getComponent().getSize());
        }
    });

    getContentPane().add(vv);

    /**
     * Create simple container for stuff on SOUTH border of this JFrame
     */
    Container c = new Container();
    c.setLayout(new FlowLayout());
    c.setBackground(java.awt.Color.lightGray);
    c.setFont(new Font("Serif", Font.PLAIN, 10));

    /**
     * Button to dump jpeg
     */
    dumpJPEG = new JButton("Dump");
    dumpJPEG.addActionListener(this);
    dumpJPEG.setName("Dump");
    c.add(dumpJPEG);

    /**
     * Button that creates offspring frame for selected vertices
     */
    subGraphButton = new JButton("Subgraph");
    subGraphButton.addActionListener(this);
    subGraphButton.setName("Subgraph");
    c.add(subGraphButton);

    subGraphDepthLabel = new JLabel("Depth");
    c.add(subGraphDepthLabel);
    subGraphDepth = new JTextField("0", 2);
    subGraphDepth.setHorizontalAlignment(SwingConstants.CENTER);
    subGraphDepth.setToolTipText("Depth of sub-graph created from selected nodes.");
    c.add(subGraphDepth);

    /**
     * Button that switches mouse mode
     */
    switchMode = new JButton("Transformation");
    switchMode.addActionListener(this);
    switchMode.setName("SwitchMode");
    c.add(switchMode);

    /**
     * ComboBox for Layout selection:
     */
    JComboBox layoutList;
    if (graph instanceof Forest) {
        String[] layoutStrings = { "Static", "Circle", "DAG", "Spring", "Spring2", "FR", "FR2", "Baloon",
                "ISOM", "KK", "PolarPoint", "RadialTree", "Tree" };
        layoutList = new JComboBox(layoutStrings);
    } else {
        String[] layoutStrings = { "Static", "Circle", "DAG", "Spring", "Spring2", "FR", "FR2", "ISOM", "KK",
                "PolarPoint" };
        layoutList = new JComboBox(layoutStrings);
    }

    layoutList.setSelectedIndex(5);
    layoutList.addActionListener(this);
    layoutList.setName("SelectLayout");
    c.add(layoutList);

    /**
     * Add container to layout
     */
    c.setVisible(true);
    getContentPane().add(c, BorderLayout.SOUTH);

    /**
     * Setup history scroll bar
     */
    if (history != null) {
        historySlider = new JSlider(0, history.size() - 1, history.size() - 1);
        historySlider.addChangeListener(this);
        historySlider.setMajorTickSpacing(10);
        historySlider.setMinorTickSpacing(1);
        historySlider.setPaintTicks(true);
        historySlider.setPaintLabels(true);

        historySlider.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
        Font font = new Font("Serif", Font.ITALIC, 15);
        historySlider.setFont(font);

        getContentPane().add(historySlider, BorderLayout.NORTH);

    }
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.pack();
    this.setVisible(true);
}