Example usage for java.awt.event ItemListener ItemListener

List of usage examples for java.awt.event ItemListener ItemListener

Introduction

In this page you can find the example usage for java.awt.event ItemListener ItemListener.

Prototype

ItemListener

Source Link

Usage

From source file:net.pms.encoders.FFmpegVideo.java

protected JComponent config(String languageLabel) {
    FormLayout layout = new FormLayout("left:pref, 0:grow", "p, 3dlu, p, 3dlu, p, 3dlu, p");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.EMPTY_BORDER);
    builder.setOpaque(false);/*from w  w  w. ja v a2 s .co m*/

    CellConstraints cc = new CellConstraints();

    JComponent cmp = builder.addSeparator(Messages.getString(languageLabel), cc.xyw(2, 1, 1));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    multiThreadingCheckBox = new JCheckBox(Messages.getString("MEncoderVideo.35"));
    multiThreadingCheckBox.setContentAreaFilled(false);
    if (configuration.isFfmpegMultithreading()) {
        multiThreadingCheckBox.setSelected(true);
    }
    multiThreadingCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setFfmpegMultithreading(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(multiThreadingCheckBox, cc.xy(2, 3));

    videoRemuxCheckBox = new JCheckBox(Messages.getString("FFmpeg.0"));
    videoRemuxCheckBox.setContentAreaFilled(false);
    if (configuration.isFFmpegMuxWhenCompatible()) {
        videoRemuxCheckBox.setSelected(true);
    }
    videoRemuxCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setFFmpegMuxWhenCompatible(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(videoRemuxCheckBox, cc.xy(2, 5));

    return builder.getPanel();
}

From source file:org.languagetool.gui.ConfigurationDialog.java

@NotNull
private JPanel getMotherTonguePanel(GridBagConstraints cons) {
    JPanel motherTonguePanel = new JPanel();
    if (insideOffice) {
        motherTonguePanel.setLayout(new GridBagLayout());
        GridBagConstraints cons1 = new GridBagConstraints();
        cons1.insets = new Insets(0, 0, 0, 0);
        cons1.gridx = 0;//from   w w w  . j av a 2 s  .  co m
        cons1.gridy = 0;
        cons1.anchor = GridBagConstraints.WEST;
        cons1.fill = GridBagConstraints.NONE;
        cons1.weightx = 0.0f;
        JRadioButton[] radioButtons = new JRadioButton[2];
        ButtonGroup numParaGroup = new ButtonGroup();
        radioButtons[0] = new JRadioButton(Tools.getLabel(messages.getString("guiUseDocumentLanguage")));
        radioButtons[0].setActionCommand("DocLang");
        radioButtons[0].setSelected(true);

        radioButtons[1] = new JRadioButton(Tools.getLabel(messages.getString("guiSetLanguageTo")));
        radioButtons[1].setActionCommand("SelectLang");

        JComboBox<String> motherTongueBox = new JComboBox<>(getPossibleMotherTongues());
        if (config.getMotherTongue() != null) {
            motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages));
        }
        motherTongueBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    Language motherTongue;
                    if (motherTongueBox.getSelectedItem() instanceof String) {
                        motherTongue = getLanguageForLocalizedName(
                                motherTongueBox.getSelectedItem().toString());
                    } else {
                        motherTongue = (Language) motherTongueBox.getSelectedItem();
                    }
                    config.setMotherTongue(motherTongue);
                    config.setUseDocLanguage(false);
                    radioButtons[1].setSelected(true);
                }
            }
        });

        for (int i = 0; i < 2; i++) {
            numParaGroup.add(radioButtons[i]);
        }

        if (config.getUseDocLanguage()) {
            radioButtons[0].setSelected(true);
        } else {
            radioButtons[1].setSelected(true);
        }

        radioButtons[0].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                config.setUseDocLanguage(true);
            }
        });

        radioButtons[1].addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                config.setUseDocLanguage(false);
                Language motherTongue;
                if (motherTongueBox.getSelectedItem() instanceof String) {
                    motherTongue = getLanguageForLocalizedName(motherTongueBox.getSelectedItem().toString());
                } else {
                    motherTongue = (Language) motherTongueBox.getSelectedItem();
                }
                config.setMotherTongue(motherTongue);
            }
        });
        motherTonguePanel.add(radioButtons[0], cons1);
        cons1.gridy++;
        motherTonguePanel.add(radioButtons[1], cons1);
        cons1.gridx = 1;
        motherTonguePanel.add(motherTongueBox, cons1);
    } else {
        motherTonguePanel.add(new JLabel(messages.getString("guiMotherTongue")), cons);
        JComboBox<String> motherTongueBox = new JComboBox<>(getPossibleMotherTongues());
        if (config.getMotherTongue() != null) {
            motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages));
        }
        motherTongueBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    Language motherTongue;
                    if (motherTongueBox.getSelectedItem() instanceof String) {
                        motherTongue = getLanguageForLocalizedName(
                                motherTongueBox.getSelectedItem().toString());
                    } else {
                        motherTongue = (Language) motherTongueBox.getSelectedItem();
                    }
                    config.setMotherTongue(motherTongue);
                }
            }
        });
        motherTonguePanel.add(motherTongueBox, cons);
    }
    return motherTonguePanel;
}

From source file:org.nuclos.client.wizard.steps.NuclosEntityAttributeCommonPropertiesStep.java

@Override
protected void initComponents() {
    double size[][] = { { 150, 20, TableLayout.FILL },
            { 20, 20, 20, 20, 20, 20, 20, 20, 90, TableLayout.FILL } };

    TableLayout layout = new TableLayout(size);
    layout.setVGap(3);//from ww  w.ja v  a2s.co  m
    layout.setHGap(5);
    this.setLayout(layout);

    final LabeledComponentSupport support = new LabeledComponentSupport();

    lbLabel = new JLabel(
            SpringLocaleDelegate.getInstance().getMessage("wizard.step.attributeproperties.10", "Feldname")
                    + ": ");
    tfLabel = new JTextField();
    tfLabel.addFocusListener(NuclosWizardUtils.createWizardFocusAdapter());
    tfLabel.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.10", "Feldname"));

    lbDefaultValue = new JLabel(
            SpringLocaleDelegate.getInstance().getMessage("wizard.step.attributeproperties.11", "Standardwert")
                    + ": ");
    tfDefaultValue = new JTextField();
    tfDefaultValue.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.11", "Standardwert"));
    tfDefaultValue.addFocusListener(NuclosWizardUtils.createWizardFocusAdapter());

    cbxDefaultValue = new JComboBox();
    cbxDefaultValue.setVisible(false);
    cbxDefaultValue.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.11", "Standardwert"));

    lovDefaultValue = new ListOfValues();
    lovDefaultValue.setVisible(false);
    lovDefaultValue.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.11", "Standardwert"));

    dateDefaultValue = new DateChooser(support, true);
    dateDefaultValue.setVisible(false);
    dateDefaultValue.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.11", "Standardwert"));

    cbDefaultValue = new JCheckBox();
    cbDefaultValue.setVisible(false);
    cbDefaultValue.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.11", "Standardwert"));

    lbDistinct = new JLabel(
            SpringLocaleDelegate.getInstance().getMessage("wizard.step.attributeproperties.7", "Eindeutig")
                    + ": ");
    cbDistinct = new JCheckBox();
    cbDistinct.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.7", "Eindeutig"));

    lbLogBook = new JLabel(
            SpringLocaleDelegate.getInstance().getMessage("wizard.step.attributeproperties.8", "Logbuch")
                    + ": ");
    cbLogBook = new JCheckBox();
    cbLogBook.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.8", "Logbuch"));

    lbMandatory = new JLabel(
            SpringLocaleDelegate.getInstance().getMessage("wizard.step.attributeproperties.9", "Pflichtfeld")
                    + ": ");
    cbMandatory = new JCheckBox();
    cbMandatory.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.9", "Pflichtfeld"));

    tfMandatory = new JTextField();
    tfMandatory.addFocusListener(NuclosWizardUtils.createWizardFocusAdapter());
    tfMandatory.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.27", "Defaultwert fr Pflichtfeld"));

    cbxMandatory = new JComboBox();
    cbxMandatory.setVisible(false);
    cbxMandatory.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.27", "Defaultwert fr Pflichtfeld"));

    lovMandatory = new ListOfValues();
    lovMandatory.setVisible(false);
    lovMandatory.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.27", "Defaultwert fr Pflichtfeld"));

    dateMandatory = new DateChooser(support);
    dateMandatory.setVisible(false);
    dateMandatory.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.27", "Defaultwert fr Pflichtfeld"));

    cbMandatoryValue = new JCheckBox();
    cbMandatoryValue.setVisible(false);
    cbMandatoryValue.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.27", "Defaultwert fr Pflichtfeld"));

    lbDBFieldName = new JLabel(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.12", "DB-Spaltename"));
    tfDBFieldName = new JTextField();
    tfDBFieldName.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.12", "DB-Spaltename"));
    tfDBFieldName.addFocusListener(NuclosWizardUtils.createWizardFocusAdapter());

    lbDBFieldNameComplete = new JLabel(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.18", "Vollst\u00e4ndiger Spaltenname"));
    tfDBFieldNameComplete = new JTextField();
    tfDBFieldNameComplete.setEnabled(false);

    lbAttributeGroup = new JLabel(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.19", "Attributegruppe"));
    cbxAttributeGroup = new JComboBox();
    cbxAttributeGroup.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.19", "Attributegruppe"));

    lbCalcFunction = new JLabel(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.20", "Berechungsvorschrift"));
    cbxCalcFunction = new JComboBox();
    cbxCalcFunction.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.20", "Berechungsvorschrift"));

    lbCalculationScript = new JLabel(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.calculationscript.label", "Berechnungsausdruck"));
    lbCalculationScript.setToolTipText(SpringLocaleDelegate.getInstance().getMessage(
            "wizard.step.attributeproperties.calculationscript.description", "Berechnungsausdruck"));
    btCalculationScript = new JButton("...");
    btCalculationScript.setToolTipText(SpringLocaleDelegate.getInstance().getMessage(
            "wizard.step.attributeproperties.calculationscript.description", "Berechnungsausdruck"));
    btCalculationScript.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            ScriptEditor editor = new ScriptEditor();
            if (getModel().getAttribute().getCalculationScript() != null) {
                editor.setScript(getModel().getAttribute().getCalculationScript());
            }
            editor.run();
            NuclosScript script = editor.getScript();
            if (org.nuclos.common2.StringUtils.isNullOrEmpty(script.getSource())) {
                script = null;
            }
            getModel().getAttribute().setCalculationScript(script);
        }
    });

    lbIndexed = new JLabel(
            SpringLocaleDelegate.getInstance().getMessage("wizard.step.attributeproperties.26", "Indiziert"));
    cbIndexed = new JCheckBox();
    cbIndexed.setToolTipText(SpringLocaleDelegate.getInstance()
            .getMessage("wizard.step.attributeproperties.tooltip.26", "Indiziert"));

    pnlMoreOptions = new JPanel();

    double sizeMoreOptions[][] = { { 150, TableLayout.FILL }, { 20, 20, 20, TableLayout.FILL } };

    TableLayout tlMoreOptions = new TableLayout(sizeMoreOptions);
    tlMoreOptions.setVGap(3);
    tlMoreOptions.setHGap(5);

    pnlMoreOptions.setLayout(tlMoreOptions);
    pnlMoreOptions.add(lbDBFieldName, "0,0");
    pnlMoreOptions.add(tfDBFieldName, "1,0");
    pnlMoreOptions.add(lbDBFieldNameComplete, "0,1");
    pnlMoreOptions.add(tfDBFieldNameComplete, "1,1");
    pnlMoreOptions.add(lbIndexed, "0,2");
    pnlMoreOptions.add(cbIndexed, "1,2");

    MoreOptionPanel optionPanel = new MoreOptionPanel(pnlMoreOptions);

    this.add(lbLabel, "0,0");
    this.add(tfLabel, "1,0 , 2,0");
    this.add(lbDefaultValue, "0,1");
    this.add(tfDefaultValue, "1,1 , 2,1");
    this.add(cbxDefaultValue, "1,1 , 2,1");
    this.add(lovDefaultValue, "1,1 , 2,1");
    this.add(dateDefaultValue, "1,1 , 2,1");
    this.add(cbDefaultValue, "1,1");
    this.add(lbDistinct, "0,2");
    this.add(cbDistinct, "1,2");
    this.add(lbLogBook, "0,3");
    this.add(cbLogBook, "1,3");
    this.add(lbMandatory, "0,4");
    this.add(cbMandatory, "1,4");
    this.add(tfMandatory, "2,4");
    this.add(cbxMandatory, "2,4");
    this.add(lovMandatory, "2,4");
    this.add(dateMandatory, "2,4");
    this.add(cbMandatoryValue, "2,4");

    this.add(lbAttributeGroup, "0,5");
    this.add(cbxAttributeGroup, "1,5 , 2,5");
    this.add(lbCalcFunction, "0,6");
    this.add(cbxCalcFunction, "1,6 , 2,6");
    this.add(lbCalculationScript, "0,7");
    this.add(btCalculationScript, "1,7");

    this.add(optionPanel, "0,8, 2,8");

    tfLabel.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            doSomeWork();
        }

        @Override
        public void keyReleased(KeyEvent e) {
            doSomeWork();
        }

        @Override
        public void keyPressed(KeyEvent e) {
            doSomeWork();
        }

        protected void doSomeWork() {
            blnLabelModified = true;
        }

    });

    tfLabel.setDocument(new SpecialCharacterDocument());
    tfLabel.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        protected void doSomeWork(DocumentEvent e) {
            int size = e.getDocument().getLength();
            if (size > 0) {
                NuclosEntityAttributeCommonPropertiesStep.this.setComplete(true);
            } else {
                NuclosEntityAttributeCommonPropertiesStep.this.setComplete(false);
            }
            try {
                NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                        .setInternalName(e.getDocument().getText(0, e.getDocument().getLength()));
                if (!NuclosEntityAttributeCommonPropertiesStep.this.getModel().isEditMode()) {
                    String sPrefix = Attribute.getDBPrefix(
                            NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute());
                    tfDBFieldName.setText(sPrefix + e.getDocument().getText(0, e.getDocument().getLength()));
                }

            } catch (BadLocationException ex) {
                Errors.getInstance().showExceptionDialog(NuclosEntityAttributeCommonPropertiesStep.this, ex);
            }
        }
    });

    tfDefaultValue.getDocument().addDocumentListener(new DefaultValueDocumentListener());

    tfMandatory.getDocument().addDocumentListener(new MandatoryValueDocumentListener());
    tfMandatory.setLocale(SpringLocaleDelegate.getInstance().getLocale());

    tfDBFieldName.setDocument(new LimitCharacterDocument());
    tfDBFieldName.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        protected void doSomeWork(DocumentEvent e) {
            try {
                NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                        .setDbName(e.getDocument().getText(0, e.getDocument().getLength()));

                String s = e.getDocument().getText(0, e.getDocument().getLength());
                if (getModel().getAttribute().getMetaVO() != null
                        && getModel().getAttribute().getField() != null) {
                    s = "STRVALUE_" + s;
                } else if (getModel().getAttribute().getMetaVO() != null
                        && getModel().getAttribute().getField() == null) {
                    s = "INTID_" + s;
                }
                tfDBFieldNameComplete.setText(s);

            } catch (BadLocationException ex) {
                Errors.getInstance().showExceptionDialog(NuclosEntityAttributeCommonPropertiesStep.this, ex);
            }
        }
    });

    cbDistinct.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            final JCheckBox cb = (JCheckBox) e.getItem();
            NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                    .setDistinct(cb.isSelected());
            if (!cb.isSelected()) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        cbMandatory.setEnabled(true);
                    }
                });
            }
        }
    });

    cbLogBook.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            JCheckBox cb = (JCheckBox) e.getItem();
            NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                    .setLogBook(cb.isSelected());
        }
    });

    cbMandatory.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            final JCheckBox cb = (JCheckBox) e.getItem();
            NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                    .setMandatory(cb.isSelected());
            if (NuclosEntityAttributeCommonPropertiesStep.this.parentWizardModel.isEditMode() && cb.isSelected()
                    && !parentWizardModel.isVirtual()) {
                if (NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                        .getMandatoryValue() == null) {
                    (new Bubble(cb,
                            SpringLocaleDelegate.getInstance().getMessage(
                                    "wizard.step.attributeproperties.tooltip.28",
                                    "Bitte tragen Sie einen Wert ein mit dem das Feld vorbelegt werden kann!"),
                            3, Position.UPPER)).setVisible(true);
                }

            }
        }
    });

    cbIndexed.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            JCheckBox cb = (JCheckBox) e.getItem();
            NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                    .setIndexed(cb.isSelected());
        }
    });

    cbxDefaultValue.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                getModel().getAttribute().setIdDefaultValue((DefaultValue) e.getItem());
            }
        }
    });

    cbxMandatory.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                getModel().getAttribute().setMandatoryValue(((DefaultValue) e.getItem()).getId());
            }
        }
    });

    dateDefaultValue.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        protected void doSomeWork(DocumentEvent e) {
            try {
                String value = e.getDocument().getText(0, e.getDocument().getLength());
                if ("Heute".equalsIgnoreCase(value)) {
                    value = RelativeDate.today().toString();
                }
                NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute().setDefaultValue(value);
            } catch (BadLocationException ex) {
                Errors.getInstance().showExceptionDialog(NuclosEntityAttributeCommonPropertiesStep.this, ex);
            }
        }

    });

    cbDefaultValue.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            JCheckBox cb = (JCheckBox) e.getItem();
            if (cb.isSelected()) {
                NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute().setDefaultValue("ja");
            } else {
                NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                        .setDefaultValue("nein");
            }
        }
    });

    cbMandatoryValue.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            JCheckBox cb = (JCheckBox) e.getItem();
            if (cb.isSelected()) {
                NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                        .setMandatoryValue(Boolean.TRUE);
            } else {
                NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                        .setMandatoryValue(Boolean.FALSE);
            }
        }
    });

    cbxAttributeGroup.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                        .setAttributeGroup((String) e.getItem());
                NuclosEntityAttributeCommonPropertiesStep.this.setComplete(true);
            }
        }
    });

    cbxCalcFunction.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute()
                        .setCalcFunction((String) e.getItem());
            }
        }
    });

}

From source file:shuffle.fwk.service.teams.EditTeamService.java

private Component createTeamComponent(Species s) {
    Team curTeam = getCurrentTeam();//from www  . j ava2 s.  c om
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 2;
    Indicator<SpeciesPaint> ind = new Indicator<SpeciesPaint>(this);
    boolean isMega = megaProgress >= megaThreshold && s.getName().equals(curTeam.getMegaSlotName());
    SpeciesPaint paint = new SpeciesPaint(s, s.equals(Species.FREEZE), isMega);
    ind.setVisualized(paint);
    ret.add(ind, c);
    c.gridy += 1;
    c.gridwidth = 1;
    JButton removeButton = new JButton(getString(KEY_REMOVE));
    removeButton.setToolTipText(getString(KEY_REMOVE_TOOLTIP));
    removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            removeSpeciesFromTeam(s.getName());
            updateTeamPanel();
        }
    });
    removeButton.setEnabled(
            s.getEffect(getUser().getRosterManager()).isPickable() && !s.getType().equals(PkmType.NONE));
    ret.add(removeButton, c);

    c.gridx += 1;
    JComboBox<Character> keybindsComboBox = new JComboBox<Character>();
    Character curBinding = curTeam.getBinding(s);
    LinkedHashSet<Character> allBindingsFor = new LinkedHashSet<Character>(Arrays.asList(curBinding));
    LinkedHashSet<Character> availableBindings = myData.getAllAvailableBindingsFor(s.getName(), curTeam);
    allBindingsFor.addAll(availableBindings);
    for (Character ch : allBindingsFor) {
        keybindsComboBox.addItem(ch);
    }
    keybindsComboBox.setSelectedItem(curBinding);
    final ItemListener bindingListener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            JComboBox<?> source = (JComboBox<?>) e.getSource();
            int selectedIndex = source.getSelectedIndex();
            Character selected = (Character) source.getItemAt(selectedIndex);
            setBinding(s, selected);
            updateKeybindComboBoxes();
        }
    };
    nameToKeybindComboboxMap.put(s.getName(), keybindsComboBox);
    nameToItemListenerMap.put(s.getName(), bindingListener);
    keybindsComboBox.addItemListener(bindingListener);
    keybindsComboBox.setToolTipText(getString(KEY_KEYBINDS_TOOLTIP));
    ret.add(keybindsComboBox, c);

    MouseAdapter ma = new PressToggleMouseAdapter() {

        @Override
        protected void onRight(MouseEvent e) {
            doToggle();
        }

        @Override
        protected void onLeft(MouseEvent e) {
            doToggle();
        }

        private void doToggle() {
            toggleSupport(s);
            updateTeamPanel();
        }
    };
    ret.addMouseListener(ma);

    setBorderFor(ret, false, false);
    if (!Species.FIXED_SPECIES.contains(s)) {
        boolean isSupport = !curTeam.isNonSupport(s);
        Color indColor = isSupport ? Color.GREEN : Color.RED;
        ret.setBackground(indColor);
        ret.setOpaque(true);
    }
    return ret;
}

From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java

private JPanel createTickerPanel(int stentWidth) {
    // Load up the original values.
    originalShowTicker = !Boolean.FALSE.toString()
            .equals(controller.getModel().getUserPreference(ExchangeModel.TICKER_SHOW));
    originalExchange1 = controller.getModel().getUserPreference(ExchangeModel.TICKER_FIRST_ROW_EXCHANGE);
    originalCurrency1 = controller.getModel().getUserPreference(ExchangeModel.TICKER_FIRST_ROW_CURRENCY);
    // Map MtGox to Bitstamp + USD
    if (ExchangeData.MT_GOX_EXCHANGE_NAME.equalsIgnoreCase(originalExchange1)) {
        originalExchange1 = ExchangeData.BITSTAMP_EXCHANGE_NAME;
        controller.getModel().setUserPreference(ExchangeModel.TICKER_FIRST_ROW_EXCHANGE,
                ExchangeData.BITSTAMP_EXCHANGE_NAME);

        originalCurrency1 = "USD";
        controller.getModel().setUserPreference(ExchangeModel.TICKER_FIRST_ROW_CURRENCY, "USD");
    }// ww w  .j ava 2 s.c o  m
    originalShowSecondRow = Boolean.TRUE.toString()
            .equals(controller.getModel().getUserPreference(ExchangeModel.TICKER_SHOW_SECOND_ROW));
    originalExchange2 = controller.getModel().getUserPreference(ExchangeModel.TICKER_SECOND_ROW_EXCHANGE);
    originalCurrency2 = controller.getModel().getUserPreference(ExchangeModel.TICKER_SECOND_ROW_CURRENCY);
    // Map MtGox to Bitstamp
    if (ExchangeData.MT_GOX_EXCHANGE_NAME.equalsIgnoreCase(originalExchange2)) {
        originalExchange2 = ExchangeData.BITSTAMP_EXCHANGE_NAME;
        controller.getModel().setUserPreference(ExchangeModel.TICKER_SECOND_ROW_EXCHANGE,
                ExchangeData.BITSTAMP_EXCHANGE_NAME);

        originalCurrency2 = "USD";
        controller.getModel().setUserPreference(ExchangeModel.TICKER_SECOND_ROW_CURRENCY, "USD");
    }

    MultiBitTitledPanel tickerPanel = new MultiBitTitledPanel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.title2"),
            ComponentOrientation.getOrientation(controller.getLocaliser().getLocale()));
    GridBagConstraints constraints = new GridBagConstraints();

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 3;
    constraints.gridy = 3;
    constraints.weightx = 0.05;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.CENTER;
    tickerPanel.add(MultiBitTitledPanel.createStent(MultiBitTitledPanel.SEPARATION_BETWEEN_NAME_VALUE_PAIRS),
            constraints);

    String showTickerText = controller.getLocaliser().getString("multiBitFrame.ticker.show.text");
    if (showTickerText != null && showTickerText.length() >= 1) {
        // Capitalise text (this is to save adding a new I18n term.
        showTickerText = Character.toUpperCase(showTickerText.charAt(0))
                + showTickerText.toLowerCase().substring(1);
    }
    showTicker = new JCheckBox(showTickerText);
    showTicker.setOpaque(false);
    showTicker.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    showTicker.setSelected(originalShowTicker);

    exchangeInformationLabel = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.exchangeInformation"));
    exchangeInformationLabel.setVisible(originalShowBitcoinConvertedToFiat);

    showBitcoinConvertedToFiat = new JCheckBox(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.showBitcoinConvertedToFiat"));
    showBitcoinConvertedToFiat.setOpaque(false);
    showBitcoinConvertedToFiat.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    showBitcoinConvertedToFiat.setSelected(originalShowBitcoinConvertedToFiat);

    showBitcoinConvertedToFiat.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            boolean selectedChange = (e.getStateChange() == ItemEvent.SELECTED);
            boolean unSelectedChange = (e.getStateChange() == ItemEvent.DESELECTED);
            if (exchangeInformationLabel != null) {
                if (selectedChange) {
                    exchangeInformationLabel.setVisible(true);
                }
                if (unSelectedChange) {
                    exchangeInformationLabel.setVisible(false);
                }
            }
        }
    });

    showExchange = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.exchange"));
    showExchange.setOpaque(false);
    showExchange.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showCurrency = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.currency"));
    showCurrency.setOpaque(false);
    showCurrency.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showLastPrice = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.lastPrice"));
    showLastPrice.setOpaque(false);
    showLastPrice.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showBid = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.bid"));
    showBid.setOpaque(false);
    showBid.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    showAsk = new JCheckBox(controller.getLocaliser().getString("tickerTableModel.ask"));
    showAsk.setOpaque(false);
    showAsk.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());

    String tickerColumnsToShow = controller.getModel().getUserPreference(ExchangeModel.TICKER_COLUMNS_TO_SHOW);
    if (tickerColumnsToShow == null || tickerColumnsToShow.equals("")) {
        tickerColumnsToShow = TickerTableModel.DEFAULT_COLUMNS_TO_SHOW;
    }

    originalShowCurrency = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_CURRENCY);
    showCurrency.setSelected(originalShowCurrency);

    originalShowRate = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_LAST_PRICE);
    showLastPrice.setSelected(originalShowRate);

    originalShowBid = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_BID);
    showBid.setSelected(originalShowBid);

    originalShowAsk = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_ASK);
    showAsk.setSelected(originalShowAsk);

    originalShowExchange = tickerColumnsToShow.contains(TickerTableModel.TICKER_COLUMN_EXCHANGE);
    showExchange.setSelected(originalShowExchange);

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 4;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showTicker, constraints);

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 5;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 4;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showBitcoinConvertedToFiat, constraints);

    constraints.fill = GridBagConstraints.VERTICAL;
    constraints.gridx = 0;
    constraints.gridy = 6;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(1, 12), constraints);

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.columnsToShow"), 7, tickerPanel);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 8;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showExchange, constraints);

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 9;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showCurrency, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 10;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showLastPrice, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 11;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showBid, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 12;
    constraints.weightx = 0.2;
    constraints.weighty = 0.3;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showAsk, constraints);

    constraints.fill = GridBagConstraints.VERTICAL;
    constraints.gridx = 1;
    constraints.gridy = 13;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(1, 13), constraints);

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.firstRow"), 14, tickerPanel);

    MultiBitLabel exchangeLabel1 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.exchange"));
    exchangeLabel1.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 15;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(exchangeLabel1, constraints);

    String exchangeToUse1;
    if (originalExchange1 == null | "".equals(originalExchange1)) {
        exchangeToUse1 = ExchangeData.DEFAULT_EXCHANGE;
    } else {
        exchangeToUse1 = originalExchange1;
    }

    String exchangeToUse2;
    if (originalExchange2 == null | "".equals(originalExchange2)) {
        exchangeToUse2 = ExchangeData.DEFAULT_EXCHANGE;
    } else {
        exchangeToUse2 = originalExchange2;
    }

    exchangeComboBox1 = new JComboBox(ExchangeData.getAvailableExchanges());
    exchangeComboBox1.setSelectedItem(exchangeToUse1);

    exchangeComboBox1.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    exchangeComboBox1.setOpaque(false);

    FontMetrics fontMetrics = getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont());
    int textWidth = Math.max(fontMetrics.stringWidth(ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME),
            fontMetrics.stringWidth("USD")) + COMBO_WIDTH_DELTA;
    Dimension preferredSize = new Dimension(textWidth + TICKER_COMBO_WIDTH_DELTA,
            fontMetrics.getHeight() + EXCHANGE_COMBO_HEIGHT_DELTA);
    exchangeComboBox1.setPreferredSize(preferredSize);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 15;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.LINE_START;
    JPanel stent = MultiBitTitledPanel.createStent(stentWidth);
    tickerPanel.add(stent, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 15;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(exchangeComboBox1, constraints);

    oerMessageLabel1 = new MultiBitLabel(
            "    " + controller.getLocaliser().getString("showPreferencesPanel.getAppId.label"));
    oerMessageLabel1.setForeground(Color.GREEN.darker().darker());
    boolean showMessageLabel1 = isBrowserSupported()
            && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse1)
            && (originalOERApiCode == null || originalOERApiCode.trim().length() == 0);
    oerMessageLabel1.setVisible(showMessageLabel1);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 5;
    constraints.gridy = 15;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(oerMessageLabel1, constraints);

    MultiBitLabel currencyLabel1 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.currency"));
    currencyLabel1.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 16;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(currencyLabel1, constraints);

    // Make sure the exchange1 has been created and initialised the list of
    // currencies.
    if (mainFrame != null && mainFrame.getTickerTimerTask1() != null) {
        TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask1();
        synchronized (tickerTimerTask) {
            if (tickerTimerTask.getExchange() == null) {
                tickerTimerTask.createExchangeObjects(exchangeToUse1);
            }
        }
    }

    currencyComboBox1 = new JComboBox();
    Collection<String> currenciesToUse = ExchangeData.getAvailableCurrenciesForExchange(exchangeToUse1);
    if (currenciesToUse != null) {
        for (String currency : currenciesToUse) {
            String item = currency;
            String description = CurrencyConverter.INSTANCE.getCurrencyCodeToDescriptionMap().get(currency);
            if (description != null && description.trim().length() > 0) {
                item = item + " (" + description + ")";
            }
            currencyComboBox1.addItem(item);
            if (currency.equals(originalCurrency1)) {
                currencyComboBox1.setSelectedItem(item);
            }
        }
    }

    currencyComboBox1.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    currencyComboBox1.setOpaque(false);
    currencyComboBox1.setPreferredSize(preferredSize);

    exchangeComboBox1.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Object item = event.getItem();
                String exchangeShortName = item.toString();
                // Make sure the exchange1 has been created and initialised
                // the list of currencies.
                if (mainFrame != null && mainFrame.getTickerTimerTask1() != null) {
                    TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask1();
                    synchronized (tickerTimerTask) {
                        tickerTimerTask.createExchangeObjects(exchangeShortName);
                        currencyComboBox1.removeAllItems();
                        Collection<String> currenciesToUse = ExchangeData
                                .getAvailableCurrenciesForExchange(exchangeShortName);
                        if (currenciesToUse != null) {
                            for (String currency : currenciesToUse) {
                                String loopItem = currency;
                                String description = CurrencyConverter.INSTANCE
                                        .getCurrencyCodeToDescriptionMap().get(currency);
                                if (description != null && description.trim().length() > 0) {
                                    loopItem = loopItem + " (" + description + ")";
                                }
                                currencyComboBox1.addItem(loopItem);
                            }
                        }
                    }
                }

                // Enable the OpenExchangeRates App ID if required.
                boolean showOER = ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                        .equalsIgnoreCase(exchangeShortName)
                        || ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                                .equalsIgnoreCase((String) exchangeComboBox2.getSelectedItem());
                oerStent.setVisible(showOER);
                oerApiCodeLabel.setVisible(showOER);
                oerApiCodeTextField.setVisible(showOER);
                getOerAppIdButton.setVisible(showOER);

                boolean showMessageLabel = isBrowserSupported()
                        && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeShortName)
                        && (oerApiCodeTextField.getText() == null
                                || oerApiCodeTextField.getText().trim().length() == 0);
                oerMessageLabel1.setVisible(showMessageLabel);
            }
        }
    });

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 16;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(currencyComboBox1, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 17;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(12, 12), constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 18;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(fontMetrics.stringWidth(exchangeInformationLabel.getText()),
            fontMetrics.getHeight()), constraints);
    tickerPanel.add(exchangeInformationLabel, constraints);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 19;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(12, 12), constraints);

    MultiBitTitledPanel.addLeftJustifiedTextAtIndent(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.secondRow"), 20, tickerPanel);

    showSecondRowCheckBox = new JCheckBox(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.showSecondRow"));
    showSecondRowCheckBox.setOpaque(false);
    showSecondRowCheckBox.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    showSecondRowCheckBox.addItemListener(new ChangeTickerShowSecondRowListener());

    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 21;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 3;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(showSecondRowCheckBox, constraints);

    exchangeLabel2 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.exchange"));
    exchangeLabel2.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 22;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(exchangeLabel2, constraints);

    exchangeComboBox2 = new JComboBox(ExchangeData.getAvailableExchanges());
    exchangeComboBox2.setSelectedItem(exchangeToUse2);

    exchangeComboBox2.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    exchangeComboBox2.setOpaque(false);
    exchangeComboBox2.setPreferredSize(preferredSize);

    exchangeComboBox2.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                Object item = event.getItem();
                String exchangeShortName = item.toString();
                // Make sure the exchange2 has been created and initialised
                // the list of currencies.
                if (mainFrame != null && mainFrame.getTickerTimerTask2() != null) {
                    TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask2();
                    synchronized (tickerTimerTask) {
                        tickerTimerTask.createExchangeObjects(exchangeShortName);
                        currencyComboBox2.removeAllItems();
                        Collection<String> currenciesToUse = ExchangeData
                                .getAvailableCurrenciesForExchange(exchangeShortName);
                        if (currenciesToUse != null) {
                            for (String currency : currenciesToUse) {
                                String loopItem = currency;
                                String description = CurrencyConverter.INSTANCE
                                        .getCurrencyCodeToDescriptionMap().get(currency);
                                if (description != null && description.trim().length() > 0) {
                                    loopItem = loopItem + " (" + description + ")";
                                }
                                currencyComboBox2.addItem(loopItem);
                            }
                        }
                    }
                }

                // Enable the OpenExchangeRates App ID if required.
                boolean showOER = ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                        .equalsIgnoreCase(exchangeShortName)
                        || ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME
                                .equalsIgnoreCase((String) exchangeComboBox1.getSelectedItem());
                oerStent.setVisible(showOER);
                oerApiCodeLabel.setVisible(showOER);
                oerApiCodeTextField.setVisible(showOER);
                getOerAppIdButton.setVisible(showOER);

                boolean showMessageLabel = isBrowserSupported()
                        && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeShortName)
                        && (oerApiCodeTextField.getText() == null
                                || oerApiCodeTextField.getText().trim().length() == 0);
                oerMessageLabel2.setVisible(showMessageLabel);
            }
        }
    });

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 22;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(exchangeComboBox2, constraints);

    oerMessageLabel2 = new MultiBitLabel(
            "    " + controller.getLocaliser().getString("showPreferencesPanel.getAppId.label"));
    oerMessageLabel2.setForeground(Color.GREEN.darker().darker());
    boolean showMessageLabel2 = isBrowserSupported()
            && ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse2)
            && (originalOERApiCode == null || originalOERApiCode.trim().length() == 0);
    oerMessageLabel2.setVisible(showMessageLabel2);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 5;
    constraints.gridy = 22;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(oerMessageLabel2, constraints);

    currencyLabel2 = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.ticker.currency"));
    currencyLabel2.setHorizontalAlignment(JLabel.TRAILING);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.gridx = 1;
    constraints.gridy = 23;
    constraints.weightx = 0.3;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(currencyLabel2, constraints);

    // Make sure the exchange2 has been created and initialised the list of
    // currencies.
    if (mainFrame != null && mainFrame.getTickerTimerTask2() != null) {
        TickerTimerTask tickerTimerTask = mainFrame.getTickerTimerTask2();
        synchronized (tickerTimerTask) {
            if (tickerTimerTask.getExchange() == null) {
                tickerTimerTask.createExchangeObjects(exchangeToUse2);
            }
        }
    }
    currencyComboBox2 = new JComboBox();
    currenciesToUse = ExchangeData.getAvailableCurrenciesForExchange(exchangeToUse2);
    if (currenciesToUse != null) {
        for (String currency : currenciesToUse) {
            String loopItem = currency;
            String description = CurrencyConverter.INSTANCE.getCurrencyCodeToDescriptionMap().get(currency);
            if (description != null && description.trim().length() > 0) {
                loopItem = loopItem + " (" + description + ")";
            }
            currencyComboBox2.addItem(loopItem);
            if (currency.equals(originalCurrency2)) {
                currencyComboBox2.setSelectedItem(loopItem);
            }
        }
    }

    currencyComboBox2.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont());
    currencyComboBox2.setOpaque(false);
    currencyComboBox2.setPreferredSize(preferredSize);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 23;
    constraints.weightx = 0.8;
    constraints.weighty = 0.6;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(currencyComboBox2, constraints);

    showSecondRowCheckBox.setSelected(originalShowSecondRow);
    enableTickerSecondRow(originalShowSecondRow);

    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 24;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(MultiBitTitledPanel.createStent(12, 12), constraints);

    JPanel fill1 = new JPanel();
    fill1.setOpaque(false);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 5;
    constraints.gridy = 25;
    constraints.weightx = 20;
    constraints.weighty = 1;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(fill1, constraints);

    boolean showOerSignup = ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse1)
            || ExchangeData.OPEN_EXCHANGE_RATES_EXCHANGE_NAME.equalsIgnoreCase(exchangeToUse2);

    oerStent = MultiBitTitledPanel.createStent(12, 12);
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridx = 1;
    constraints.gridy = 26;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_START;
    oerStent.setVisible(showOerSignup);
    tickerPanel.add(oerStent, constraints);

    oerApiCodeLabel = new MultiBitLabel(
            controller.getLocaliser().getString("showPreferencesPanel.oerLabel.text"));
    oerApiCodeLabel.setToolTipText(HelpContentsPanel
            .createTooltipText(controller.getLocaliser().getString("showPreferencesPanel.oerLabel.tooltip")));
    oerApiCodeLabel.setVisible(showOerSignup);

    oerApiCodeTextField = new MultiBitTextField("", 25, controller);
    oerApiCodeTextField.setHorizontalAlignment(JLabel.LEADING);
    oerApiCodeTextField.setMinimumSize(new Dimension(API_CODE_FIELD_WIDTH, API_CODE_FIELD_HEIGHT));
    oerApiCodeTextField.setPreferredSize(new Dimension(API_CODE_FIELD_WIDTH, API_CODE_FIELD_HEIGHT));
    oerApiCodeTextField.setMaximumSize(new Dimension(API_CODE_FIELD_WIDTH, API_CODE_FIELD_HEIGHT));
    oerApiCodeTextField.setVisible(showOerSignup);
    oerApiCodeTextField.setText(originalOERApiCode);
    oerApiCodeTextField.addFocusListener(new FocusListener() {
        @Override
        public void focusGained(FocusEvent arg0) {
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            String apiCode = oerApiCodeTextField.getText();
            if (apiCode != null && !(WhitespaceTrimmer.trim(apiCode).length() == 0) && !apiCode.equals(
                    controller.getModel().getUserPreference(ExchangeModel.OPEN_EXCHANGE_RATES_API_CODE))) {
                // New API code.
                // Check its length
                if (!(apiCode.trim().length() == LENGTH_OF_OPEN_EXCHANGE_RATE_APP_ID)
                        && !apiCode.equals(haveShownErrorMessageForApiCode)) {
                    haveShownErrorMessageForApiCode = apiCode;
                    // Give user a message that App ID is not in the correct format.
                    JOptionPane.showMessageDialog(null,
                            new String[] { controller
                                    .getLocaliser().getString("showPreferencesPanel.oerValidationError.text1"),
                                    " ",
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text2"),
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text3") },
                            controller.getLocaliser().getString(
                                    "showPreferencesPanel.oerValidationError.title"),
                            JOptionPane.ERROR_MESSAGE,
                            ImageLoader.createImageIcon(ImageLoader.EXCLAMATION_MARK_ICON_FILE));
                    return;
                }
            }
            updateApiCode();
        }
    });
    oerApiCodeTextField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            String apiCode = oerApiCodeTextField.getText();
            if (apiCode != null && !(WhitespaceTrimmer.trim(apiCode).length() == 0) && !apiCode.equals(
                    controller.getModel().getUserPreference(ExchangeModel.OPEN_EXCHANGE_RATES_API_CODE))) {
                // New API code.
                // Check its length
                if (!(apiCode.trim().length() == LENGTH_OF_OPEN_EXCHANGE_RATE_APP_ID)
                        && !apiCode.equals(haveShownErrorMessageForApiCode)) {
                    haveShownErrorMessageForApiCode = apiCode;
                    // Give user a message that App ID is not in the correct format.
                    JOptionPane.showMessageDialog(null,
                            new String[] {
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text1"),
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text2"),
                                    controller.getLocaliser()
                                            .getString("showPreferencesPanel.oerValidationError.text3") },
                            controller.getLocaliser().getString(
                                    "showPreferencesPanel.oerValidationError.title"),
                            JOptionPane.ERROR_MESSAGE,
                            ImageLoader.createImageIcon(ImageLoader.EXCLAMATION_MARK_ICON_FILE));
                    return;
                }
            }
            updateApiCode();
        }
    });

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 1;
    constraints.gridy = 27;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 1;
    constraints.anchor = GridBagConstraints.LINE_END;
    tickerPanel.add(oerApiCodeLabel, constraints);

    constraints.fill = GridBagConstraints.NONE;
    constraints.gridx = 4;
    constraints.gridy = 27;
    constraints.weightx = 0.3;
    constraints.weighty = 0.3;
    constraints.gridwidth = 2;
    constraints.anchor = GridBagConstraints.LINE_START;
    tickerPanel.add(oerApiCodeTextField, constraints);

    if (isBrowserSupported()) {
        getOerAppIdButton = new MultiBitButton(
                controller.getLocaliser().getString("showPreferencesPanel.getAppId.text"));
        getOerAppIdButton
                .setToolTipText(controller.getLocaliser().getString("showPreferencesPanel.getAppId.tooltip"));
        getOerAppIdButton.setVisible(showOerSignup);

        getOerAppIdButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                try {
                    openURI(new URI(OPEN_EXCHANGE_RATES_SIGN_UP_URI));
                } catch (URISyntaxException e) {
                    log.debug(e.getMessage());
                }
            }
        });

        constraints.fill = GridBagConstraints.NONE;
        constraints.gridx = 4;
        constraints.gridy = 28;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.LINE_START;
        tickerPanel.add(getOerAppIdButton, constraints);
    }

    return tickerPanel;
}

From source file:com.declarativa.interprolog.gui.ListenerWindow.java

private void UpdategraphComponents2(Forest<String, Integer> graph) throws IOException {
    jLayeredPane5.removeAll();/*from w w w  .j a v  a 2 s  .  co  m*/

    /*     
             
     List<String> heads = new ArrayList<>();
     List<String> subgrph = new ArrayList<>();
     ArgBuildManager manag = new ArgBuildManager();
     Forest<String, Integer> graphGUI = new DelegateForest<>();
            
            
     graphGUI = manag.getGraphJung();
     */
    Forest<String, Integer> graphGUI = new DelegateForest<>();

    graphGUI = graph;

    System.out.println("\t \t NUM UF VERT:" + graphGUI.getVertexCount());

    //ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest));
    ObservableGraph g = new ObservableGraph(graphGUI);

    //Layout layout = new BalloonLayout(forest);
    Layout layout = new BalloonLayout(graphGUI);
    //Layout layout = new TreeLayout(forest, 70, 70);

    final BaseJungScene scene2 = new SceneImpl(g, layout);

    jLayeredPane5.setLayout(new BorderLayout());
    //jf.setLayout(new BorderLayout());

    jLayeredPane5.add(new JScrollPane(scene2.createView()), BorderLayout.CENTER);
    //jf.add(new JScrollPane(scene2.createView()), BorderLayout.CENTER);

    JToolBar bar = new JToolBar();
    bar.setMargin(new Insets(5, 5, 5, 5));
    bar.setLayout(new FlowLayout(5));
    DefaultComboBoxModel<Layout> mdl = new DefaultComboBoxModel<>();
    mdl.addElement(new KKLayout(g));
    mdl.addElement(layout);
    mdl.addElement(new BalloonLayout(forest));
    mdl.addElement(new RadialTreeLayout(forest));
    mdl.addElement(new CircleLayout(g));
    mdl.addElement(new FRLayout(g));
    mdl.addElement(new FRLayout2(g));
    mdl.addElement(new ISOMLayout(g));
    mdl.addElement(new edu.uci.ics.jung.algorithms.layout.SpringLayout(g));
    mdl.addElement(new SpringLayout2(g));
    mdl.addElement(new DAGLayout(g));
    mdl.addElement(new XLayout(g));
    mdl.setSelectedItem(layout);
    final JCheckBox checkbox = new JCheckBox("Animate iterative layouts");

    scene2.setLayoutAnimationFramesPerSecond(48);

    final JComboBox<Layout> layouts = new JComboBox(mdl);
    layouts.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> jlist, Object o, int i, boolean bln,
                boolean bln1) {
            o = o.getClass().getSimpleName();
            return super.getListCellRendererComponent(jlist, o, i, bln, bln1); //To change body of generated methods, choose Tools | Templates.
        }
    });
    bar.add(new JLabel(" Layout Type"));
    bar.add(layouts);
    layouts.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            Layout layout = (Layout) layouts.getSelectedItem();
            // These two layouts implement IterativeContext, but they do
            // not evolve toward anything, they just randomly rearrange
            // themselves.  So disable animation for these.
            if (layout instanceof ISOMLayout || layout instanceof DAGLayout) {
                checkbox.setSelected(false);
            }
            scene2.setGraphLayout(layout, true);
        }
    });

    bar.add(new JLabel(" Connection Shape"));
    DefaultComboBoxModel<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapes = new DefaultComboBoxModel<>();
    shapes.addElement(new EdgeShape.QuadCurve<String, Number>());
    shapes.addElement(new EdgeShape.BentLine<String, Number>());
    shapes.addElement(new EdgeShape.CubicCurve<String, Number>());
    shapes.addElement(new EdgeShape.Line<String, Number>());
    shapes.addElement(new EdgeShape.Box<String, Number>());
    shapes.addElement(new EdgeShape.Orthogonal<String, Number>());
    shapes.addElement(new EdgeShape.Wedge<String, Number>(10));

    final JComboBox<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapesBox = new JComboBox<>(
            shapes);
    shapesBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            Transformer<Context<Graph<String, Number>, Number>, Shape> xform = (Transformer<Context<Graph<String, Number>, Number>, Shape>) shapesBox
                    .getSelectedItem();
            scene2.setConnectionEdgeShape(xform);
        }
    });
    shapesBox.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList<?> jlist, Object o, int i, boolean bln,
                boolean bln1) {
            o = o.getClass().getSimpleName();
            return super.getListCellRendererComponent(jlist, o, i, bln, bln1); //To change body of generated methods, choose Tools | Templates.
        }
    });
    shapesBox.setSelectedItem(new EdgeShape.QuadCurve<>());
    bar.add(shapesBox);

    //jf.add(bar, BorderLayout.NORTH);
    bar.add(new ListenerWindow.MinSizePanel(scene2.createSatelliteView()));
    bar.setFloatable(false);
    bar.setRollover(true);

    final JLabel selectionLabel = new JLabel("<html>&nbsp;</html>");
    System.out.println("LOOKUP IS " + scene2.getLookup());
    Lookup.Result<String> selectedNodes = scene2.getLookup().lookupResult(String.class);
    LookupListener listener = new LookupListener() {
        @Override
        public void resultChanged(LookupEvent le) {
            System.out.println("RES CHANGED");
            Lookup.Result<String> res = (Lookup.Result<String>) le.getSource();
            StringBuilder sb = new StringBuilder("<html>");
            List<String> l = new ArrayList<>(res.allInstances());
            Collections.sort(l);
            for (String s : l) {
                if (sb.length() != 0) {
                    sb.append(", ");
                }
                sb.append(s);
            }
            sb.append("</html>");
            selectionLabel.setText(sb.toString());
            System.out.println("LOOKUP EVENT " + sb);
        }
    };
    selectedNodes.addLookupListener(listener);
    selectedNodes.allInstances();

    bar.add(selectionLabel);

    checkbox.setSelected(true);
    checkbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            scene2.setAnimateIterativeLayouts(checkbox.isSelected());
        }
    });
    bar.add(checkbox);
    jLayeredPane6.setLayout(new BorderLayout());

    jLayeredPane6.add(bar);
    //        jf.setSize(jf.getGraphicsConfiguration().getBounds().width - 120, 700);
    //        jf.setSize(new Dimension(1280, 720));
    //        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    // this.repaint();
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent we) {
            scene2.relayout(true);
            scene2.validate();
        }
    });

}

From source file:gui.images.ImageHubExplorer.java

/**
 * Initialize all the kNN graphs for visualization.
 *//*from w ww. ja  va  2 s.  co m*/
private void graphsInit() {
    neighborGraphs = new DirectedGraph[50];
    graphVServers = new VisualizationViewer[50];
    edges = new ArrayList[50];
    // For all the relevant neighborhood sizes.
    for (int kTmp = 0; kTmp < 50; kTmp++) {
        // Create a new graph.
        DirectedGraph graph = new DirectedSparseMultigraph<>();
        neighborGraphs[kTmp] = graph;
        Layout<ImageNode, NeighborLink> layout = new CircleLayout(neighborGraphs[kTmp]);
        layout.setSize(new Dimension(500, 500));
        // Set the rendering specification.
        VisualizationViewer<ImageNode, NeighborLink> vv = new VisualizationViewer<>(layout);
        vv.setPreferredSize(new Dimension(550, 550));
        vv.setMinimumSize(new Dimension(550, 550));
        vv.setDoubleBuffered(true);
        vv.setEnabled(true);
        graphVServers[kTmp] = vv;
        vv.getRenderContext().setVertexIconTransformer(new IconTransformer<ImageNode, Icon>());
        vv.getRenderContext().setVertexShapeTransformer(new ShapeTransformer<ImageNode, Shape>());
        vv.getRenderContext().setEdgeArrowPredicate(new DirectionDisplayPredicate());
        vv.getRenderContext().setEdgeLabelTransformer(new Transformer() {
            @Override
            public String transform(Object e) {
                return (e.toString());
            }
        });
        PluggableGraphMouse gm = new PluggableGraphMouse();
        gm.add(new PickingGraphMousePlugin());
        vv.setGraphMouse(gm);
        vv.setBackground(Color.WHITE);
        vv.setVisible(true);
        final PickedState<ImageNode> pickedState = vv.getPickedVertexState();
        // Add the selection listeners.
        pickedState.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                Object subject = e.getItem();
                if (subject instanceof ImageNode) {
                    ImageNode vertex = (ImageNode) subject;
                    if (pickedState.isPicked(vertex)) {
                        setSelectedImageForIndex(vertex.id);
                    }
                }
            }
        });
    }
    verticesHash = new HashMap<>(500);
    verticesNodeIndexHash = new HashMap<>(500);
    vertexIndexes = new ArrayList<>(200);
    vertices = new ArrayList<>(200);
    edges = new ArrayList[50];
    for (int kTmp = 0; kTmp < 50; kTmp++) {
        edges[kTmp] = new ArrayList<>(500);
    }
    // Refresh the display.
    graphVServers[neighborhoodSize - 1].revalidate();
    graphVServers[neighborhoodSize - 1].repaint();
    neighborGraphScrollPane.setViewportView(graphVServers[neighborhoodSize - 1]);
    neighborGraphScrollPane.setVisible(true);
    neighborGraphScrollPane.revalidate();
    neighborGraphScrollPane.repaint();
}

From source file:org.bigwiv.blastgraph.gui.BlastGraphFrame.java

/**
 * initialize LayoutCombox/*from w w  w  . java 2  s . co m*/
 * 
 * @return
 */
private JComboBox getLayoutComboBox() {
    if (layoutBox == null) {
        layoutBox = new JComboBox(new LayoutType[] { LayoutType.FRLayout, LayoutType.EWLayout });
        layoutBox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    LayoutType layoutType = (LayoutType) e.getItem();
                    setLayout(layoutType);
                }
            }
        });
    }
    layoutBox.setSelectedItem(LayoutType.FRLayout);
    return layoutBox;
}

From source file:org.bigwiv.blastgraph.gui.BlastGraphFrame.java

/**
 * initialize LayoutMenu/*from w  w w.  jav  a 2s .c  o  m*/
 * 
 * @return
 */
private JMenu getLayoutMenu() {
    if (layoutMenu == null) {

        layoutMenu = new JMenu();

        final JRadioButtonMenuItem frButton = new JRadioButtonMenuItem(LayoutType.FRLayout.toString());
        final JRadioButtonMenuItem ewButton = new JRadioButtonMenuItem(LayoutType.EWLayout.toString());

        ItemListener layoutMenuItemListener = new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (e.getItem().equals(frButton)) {
                        setLayout(LayoutType.FRLayout);
                        layoutBox.setSelectedItem(LayoutType.FRLayout);
                    } else if (e.getItem().equals(ewButton)) {
                        setLayout(LayoutType.EWLayout);
                        layoutBox.setSelectedItem(LayoutType.EWLayout);
                    }
                }
            }
        };

        frButton.addItemListener(layoutMenuItemListener);
        ewButton.addItemListener(layoutMenuItemListener);

        ButtonGroup radio = new ButtonGroup();
        radio.add(frButton);
        radio.add(ewButton);
        frButton.setSelected(true);
        layoutMenu.add(frButton);
        layoutMenu.add(ewButton);
        layoutMenu.setToolTipText("Menu for setting graph layout");

        // layoutMenu.addItemListener(layoutMenuItemListener);

        layoutBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    if (e.getItem().equals(LayoutType.FRLayout)) {
                        frButton.setSelected(true);
                    } else if (e.getItem().equals(LayoutType.EWLayout)) {
                        ewButton.setSelected(true);
                    }
                }
            }
        });
    }
    return layoutMenu;
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

private void addOptionListeners() {
    if (optionListener == null) {
        optionListener = new ItemListener() {
            @Override/*  ww w. j ava  2s  .co  m*/
            public void itemStateChanged(ItemEvent e) {
                updateFromOptions();
                updateTeamPanel();
            }
        };
    }
    megaChooser.addItemListener(optionListener);
    megaProgressChooser.addItemListener(optionListener);
    megaActive.addItemListener(optionListener);
    woodCheckBox.addItemListener(optionListener);
    metalCheckBox.addItemListener(optionListener);
    coinCheckBox.addItemListener(optionListener);
    freezeCheckBox.addItemListener(optionListener);
}