Example usage for javax.swing JComboBox getSelectedItem

List of usage examples for javax.swing JComboBox getSelectedItem

Introduction

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

Prototype

public Object getSelectedItem() 

Source Link

Document

Returns the current selected item.

Usage

From source file:idontwant2see.IDontWant2See.java

private AbstractAction getActionInputTitle(final Program p, final String part) {
    return new AbstractAction(mLocalizer.msg("menu.userEntered", "User entered value")) {
        public void actionPerformed(final ActionEvent e) {
            final JCheckBox caseSensitive = new JCheckBox(mLocalizer.msg("caseSensitive", "case sensitive"));
            String title = p.getTitle();
            ArrayList<String> items = new ArrayList<String>();
            if (!StringUtils.isEmpty(part)) {
                String shortTitle = title.trim().substring(0, title.length() - part.length()).trim();
                shortTitle = StringUtils.removeEnd(shortTitle, "-").trim();
                shortTitle = StringUtils.removeEnd(shortTitle, "(").trim();
                items.add(shortTitle + "*");
            }// www  .j  a  v a  2  s  .  c o  m
            int index = title.indexOf(" - ");
            if (index > 0) {
                items.add(title.substring(0, index).trim() + "*");
            }
            items.add(title);
            index = title.lastIndexOf(':');
            if (index > 0) {
                items.add(title.substring(0, index).trim() + "*");
            }
            final JComboBox input = new JComboBox(items.toArray(new String[items.size()]));
            input.setEditable(true);

            input.addAncestorListener(new AncestorListener() {
                public void ancestorAdded(final AncestorEvent event) {
                    event.getComponent().requestFocus();
                }

                public void ancestorMoved(final AncestorEvent event) {
                }

                public void ancestorRemoved(final AncestorEvent event) {
                }
            });

            if (JOptionPane.showConfirmDialog(UiUtilities.getLastModalChildOf(getParentFrame()),
                    new Object[] {
                            mLocalizer.msg("exclusionText",
                                    "What should be excluded? (You can use the wildcard *)"),
                            input, caseSensitive },
                    mLocalizer.msg("exclusionTitle", "Exclusion value entering"),
                    JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
                String test = "";

                String result = (String) input.getSelectedItem();
                if (result != null) {
                    test = result.replaceAll("\\*+", "\\*").trim();

                    if (test.length() >= 0 && !test.equals("*")) {
                        mSettings.getSearchList()
                                .add(new IDontWant2SeeListEntry(result, caseSensitive.isSelected()));
                        mSettings.setLastEnteredExclusionString(result);
                        updateFilter(!mSettings.isSwitchToMyFilter());
                    }
                }

                if (test.trim().length() <= 1) {
                    JOptionPane.showMessageDialog(UiUtilities.getLastModalChildOf(getParentFrame()),
                            mLocalizer.msg("notValid", "The entered text is not valid."),
                            Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    };
}

From source file:ffx.ui.ModelingPanel.java

/**
 * Create a string representing the modeling command to execute.
 *
 * @return the modeling command string./*from   ww  w  .j  a  va  2  s . com*/
 */
private String createCommandInput() {
    StringBuilder commandLineParams = new StringBuilder(activeCommand + " ");
    // Now append command line input to a TextArea, one option per line.
    // This TextArea gets dumped to an input file.
    commandTextArea.setText("");
    int numparams = optionsTabbedPane.getTabCount();
    for (int i = 0; i < numparams; i++) {
        // A few cases require that a newLine not be generated between
        // options.
        boolean newLine = true;
        // The optionString will collect the parameters for this Option,
        // then append them to the CommandTextArea.
        StringBuilder optionString = new StringBuilder();
        JPanel optionPanel = (JPanel) optionsTabbedPane.getComponentAt(i);
        int numOptions = optionPanel.getComponentCount();
        String title = optionsTabbedPane.getTitleAt(i);
        if (title.equalsIgnoreCase("Sequence")) {
            for (int k = 0; k < acidComboBox.getItemCount(); k++) {
                if (k != 0) {
                    optionString.append("\n");
                }
                String s = (String) acidComboBox.getItemAt(k);
                s = s.substring(s.indexOf(" "), s.length()).trim();
                optionString.append(s);
            }
            // Need an extra newline for Nucleic
            if (activeCommand.equalsIgnoreCase("NUCLEIC")) {
                optionString.append("\n");
            }
        } else {
            JPanel valuePanel = (JPanel) optionPanel.getComponent(numOptions - 1);
            int numValues = valuePanel.getComponentCount();
            for (int j = 0; j < numValues; j++) {
                Component value = valuePanel.getComponent(j);
                if (value instanceof JCheckBox) {
                    JCheckBox jcbox = (JCheckBox) value;
                    if (jcbox.isSelected()) {
                        optionString.append("-");
                        optionString.append(jcbox.getName());
                        optionString.append(" ");
                        optionString.append(jcbox.getText());
                    }
                } else if (value instanceof JTextField) {
                    JTextField jtfield = (JTextField) value;
                    optionString.append("-");
                    optionString.append(jtfield.getName());
                    optionString.append(" ");
                    optionString.append(jtfield.getText());
                } else if (value instanceof JComboBox) {
                    JComboBox jcb = (JComboBox) value;
                    Object object = jcb.getSelectedItem();
                    if (object instanceof FFXSystem) {
                        FFXSystem system = (FFXSystem) object;
                        File file = system.getFile();
                        if (file != null) {
                            String absolutePath = file.getAbsolutePath();
                            if (absolutePath.endsWith("xyz")) {
                                absolutePath = absolutePath + "_1";
                            }
                            optionString.append(absolutePath);
                        }
                    }
                } else if (value instanceof JRadioButton) {
                    JRadioButton jrbutton = (JRadioButton) value;
                    if (jrbutton.isSelected()) {
                        if (!jrbutton.getText().equalsIgnoreCase("NONE")) {
                            optionString.append("-");
                            optionString.append(jrbutton.getName());
                            optionString.append(" ");
                            optionString.append(jrbutton.getText());
                        }
                        if (title.equalsIgnoreCase("C-CAP")) {
                            optionString.append("\n");
                        }
                    }
                }
            }
            // Handle Conditional Options
            if (optionPanel.getComponentCount() == 3) {
                valuePanel = (JPanel) optionPanel.getComponent(1);
                // JLabel conditionalLabel = (JLabel)
                // valuePanel.getComponent(0);
                JTextField jtf = (JTextField) valuePanel.getComponent(1);
                if (jtf.isEnabled()) {
                    String conditionalInput = jtf.getText();
                    // Post-Process the Input into Atom Pairs
                    String postProcess = jtf.getName();
                    if (postProcess != null && postProcess.equalsIgnoreCase("ATOMPAIRS")) {
                        String tokens[] = conditionalInput.split(" +");
                        StringBuilder atomPairs = new StringBuilder();
                        int atomNumber = 0;
                        for (String token : tokens) {
                            atomPairs.append(token);
                            if (atomNumber++ % 2 == 0) {
                                atomPairs.append(" ");
                            } else {
                                atomPairs.append("\n");
                            }
                        }
                        conditionalInput = atomPairs.toString();
                    }
                    // Append a newline to "enter" the option string.
                    // Append "conditional" input.
                    optionString.append("\n").append(conditionalInput);
                }
            }
        }
        if (optionString.length() > 0) {
            commandTextArea.append(optionString.toString());
            if (newLine) {
                commandTextArea.append("\n");
            }
        }
    }
    String commandInput = commandTextArea.getText();
    if (commandInput != null && !commandInput.trim().equalsIgnoreCase("")) {
        commandLineParams.append(commandInput);
    }

    // The final token on the command line is the structure file name, except
    // for protein and nucleic.
    if (!activeCommand.equalsIgnoreCase("Protein") && !activeCommand.equalsIgnoreCase("Nucleic")) {
        File file = activeSystem.getFile();
        if (file != null) {
            String name = file.getName();
            commandLineParams.append(name);
            commandLineParams.append(" ");
        } else {
            return null;
        }
    }

    return commandLineParams.toString();
}

From source file:com.freedomotic.jfrontend.MainWindow.java

/**
 * /*from  ww w .ja va2 s.  co m*/
 * @param evt 
 */
private void mnuDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuDeleteActionPerformed
    EnvironmentLogic oldenv = drawer.getCurrEnv();

    JLabel confirmLbl = new JLabel(i18n.msg("confirm_env_delete"));
    JLabel selectLbl = new JLabel(i18n.msg("select_env_to_reassing_objects"));

    List<Object> possibilities = new ArrayList<>();
    possibilities.add(i18n.msg("delete_envobj_alongside_environment"));
    possibilities.addAll(api.environments().findAll());
    possibilities.remove(oldenv);

    JComboBox envCombo = new JComboBox(possibilities.toArray());

    int result = JOptionPane.showConfirmDialog(null, new Object[] { confirmLbl, selectLbl, envCombo },
            i18n.msg("confirm_deletion_title"), JOptionPane.OK_CANCEL_OPTION);

    if (result == JOptionPane.OK_OPTION) {
        if (envCombo.getSelectedItem() instanceof EnvironmentLogic) {
            // assign objects to new environment
            EnvironmentLogic env = (EnvironmentLogic) envCombo.getSelectedItem();
            for (EnvObjectLogic obj : api.things().findByEnvironment(oldenv)) {
                obj.setEnvironment(env);
            }
            setEnvironment(env);
        } else {
            // let objects be deleted and automatically select a new environment to show
            if (api.environments().findAll().get(0) != oldenv) {
                setEnvironment(api.environments().findAll().get(0));
            } else {
                setEnvironment(api.environments().findAll().get(1));
            }
        }
        api.environments().delete(oldenv);
        if (api.things().findAll().isEmpty()) {
            // add a new object placeholder
            ObjectPluginPlaceholder objp = (ObjectPluginPlaceholder) api.getClients("object").toArray()[0];
            objp.startOnEnv(oldenv);
        }
        setWindowedMode();
        checkDeletableEnvironments();
    }
}

From source file:org.adamkrajcik.gui.MainForm.java

private void createWineMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createWineMenuItemActionPerformed
    JTextField name = new JTextField();
    SpinnerNumberModel model = new SpinnerNumberModel((short) Calendar.getInstance().get(Calendar.YEAR),
            (short) 1700, (short) Calendar.getInstance().get(Calendar.YEAR), (short) 1);
    JSpinner vintage = new JSpinner(model);
    SpinnerNumberModel model2 = new SpinnerNumberModel(1, 1, Integer.MAX_VALUE, 1);
    JSpinner quantity = new JSpinner(model2);
    String[] wineTypes = { "RED", "WHITE", "ROSE" };
    JComboBox type = new JComboBox(wineTypes);

    List<String> myList = new ArrayList<String>();
    for (String countryCode : Locale.getISOCountries()) {

        Locale obj = new Locale("", countryCode);
        myList.add(obj.getDisplayCountry(Locale.ENGLISH));
    }/*  w  w  w.ja v  a2  s . co m*/
    String[] x = new String[myList.size()];
    myList.toArray(x);
    JComboBox countryList = new JComboBox(x);

    Object[] message = { "Name:", name, "Country:", countryList, "Vintage:", vintage, "Quantity", quantity,
            "Type", type, };

    int option = JOptionPane.showConfirmDialog(null, message, "New Wine", JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE);
    if (option == JOptionPane.OK_OPTION) {
        if (name.getText().length() == 0) {
            JOptionPane.showConfirmDialog(null, langResource.getString("errorName"),
                    langResource.getString("errorName"), JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);
            createWineMenuItemActionPerformed(null);
            return;
        }
        new CreateWineSwingWorker(newWine(name.getText(), (String) countryList.getSelectedItem(),
                (short) ((int) vintage.getValue()), (int) quantity.getValue(),
                WineType.valueOf((String) type.getSelectedItem()))).execute();
    }
}

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

private void graphComponents() throws IOException {

    Forest<String, Integer> forest = new DelegateForest<>();
    ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest));

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

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

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

    jLayeredPane1.add(new JScrollPane(scene.createView()), BorderLayout.CENTER);
    //jf.add(new JScrollPane(scene.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);/*  w  w w.j a  v  a 2 s.  com*/
    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 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");

    scene.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);
            }
            scene.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();
            scene.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 MinSizePanel(scene.createSatelliteView()));
    bar.setFloatable(false);
    bar.setRollover(true);

    final JLabel selectionLabel = new JLabel("<html>&nbsp;</html>");
    System.out.println("LOOKUP IS " + scene.getLookup());
    Lookup.Result<String> selectedNodes = scene.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) {
            scene.setAnimateIterativeLayouts(checkbox.isSelected());
        }
    });
    bar.add(checkbox);
    jLayeredPane3.setLayout(new BorderLayout());

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

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

}

From source file:org.nuclos.client.layout.wysiwyg.component.properties.PropertyChartPropertyDomainStep.java

@Override
public void prepare() {
    super.prepare();

    chart = model.getChart();/*from ww w. j av a2s . c  o m*/
    wysiwygChart = model.getWYSIWYGChart();

    String sPrefix = getChartProperty(Chart.PROPERTY_COMBINED_PREFIXES);
    combinedPrefixes = (sPrefix == null) ? new StringBuffer("") : new StringBuffer(sPrefix);

    panel = new JPanel();
    panel.setLayout(new BorderLayout());

    final ChartFunction chartFunction = getChartFunction();

    if (!chartFunction.isCombinedChart()) {
        panel.add(getPanelComponent(chartFunction, ""), BorderLayout.CENTER);
    } else {
        JPanel editorType = new JPanel();
        editorType.setLayout(new GridBagLayout());
        JLabel propTypeValue = new JLabel(
                //SpringLocaleDelegate.getInstance().getMessage("wysiwyg.chart.wizard.domain.value",
                "Diagramm hinzufgen:"/*)*/);
        editorType.add(propTypeValue, new GridBagConstraints(0, 0, 0, 1, 1D, 1D, GridBagConstraints.NORTHWEST,
                GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
        final JComboBox propTypeComponent = new JComboBox(chartFunction.getCombinedChartFunctions());
        editorType.add(propTypeComponent, new GridBagConstraints(0, 1, 1, 1, 1D, 1D,
                GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 15, 0), 0, 0));

        final JTabbedPane tabbedPane = new JTabbedPane();

        JButton removeButton = new JButton(iconRemove);
        removeButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (tabbedPane.getSelectedIndex() != -1) {
                    PanelComponent panelComponent = (PanelComponent) tabbedPane.getSelectedComponent();
                    combinedPrefixes = new StringBuffer(
                            combinedPrefixes.toString().replaceAll(panelComponent.prefix, ""));
                    tabbedPane.remove(panelComponent);
                }
            }
        });
        editorType.add(removeButton, new GridBagConstraints(1, 1, 1, 1, 1D, 1D, GridBagConstraints.NORTHEAST,
                GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0));
        JButton addButton = new JButton(iconAdd);
        addButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ChartFunction cFunction = (ChartFunction) propTypeComponent.getSelectedItem();
                String prefix = cFunction.name() + "." + (Math.random() + "").replaceAll("\\.", "") + ":";

                combinedPrefixes.append(prefix);
                tabbedPane.add(cFunction.name(), getPanelComponent(cFunction, prefix));
                tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
            }
        });
        editorType.add(addButton, new GridBagConstraints(2, 1, 1, 1, 1D, 1D, GridBagConstraints.NORTHWEST,
                GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0));

        String[] prefixes = combinedPrefixes.toString().split(":");
        for (String prefix : prefixes) {
            if (prefix.length() > 0) {
                try {
                    ChartFunction cFunction = ChartFunction.valueOf(prefix.split("\\.")[0]);
                    tabbedPane.add(cFunction.name(), getPanelComponent(cFunction, prefix + ":"));
                } catch (Exception e) {
                    // ignore.
                }
            }
        }
        panel.add(editorType, BorderLayout.NORTH);
        panel.add(tabbedPane, BorderLayout.CENTER);
    }
}

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

private void graphComponents() throws IOException {

    Forest<String, Integer> forest = new DelegateForest<>();
    ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest));

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

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

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

    jLayeredPane1.add(new JScrollPane(scene.createView()), BorderLayout.CENTER);
    //jf.add(new JScrollPane(scene.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);//  w  w w  .j  a va 2  s.  c  o  m
    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 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");

    scene.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);
            }
            scene.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();
            scene.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 MinSizePanel(scene.createSatelliteView()));
    bar.setFloatable(false);
    bar.setRollover(true);

    final JLabel selectionLabel = new JLabel("<html>&nbsp;</html>");
    System.out.println("LOOKUP IS " + scene.getLookup());
    Lookup.Result<String> selectedNodes = scene.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) {
            scene.setAnimateIterativeLayouts(checkbox.isSelected());
        }
    });
    bar.add(checkbox);
    jLayeredPane3.setLayout(new BorderLayout());

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

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

}

From source file:brainflow.app.toplevel.BrainFlow.java

private IImageSource specialHandling(IImageSource dataSource) {

    if (dataSource.getFileFormat().equals("Analyze7.5")) {
        JPanel panel = new JPanel();
        JLabel messageLabel = new JLabel("Please select correct image orientation from menu: ");
        java.util.List<Anatomy3D> choices = Anatomy3D.getInstanceList();
        JComboBox choiceBox = new JComboBox(choices.toArray());

        //todo hackery alert
        Anatomy anatomy = dataSource.getImageInfo().getAnatomy();
        choiceBox.setSelectedItem(anatomy);

        FormLayout layout = new FormLayout("4dlu, l:p, p:g, 4dlu", "6dlu, p, 10dlu, p, 6dlu");
        CellConstraints cc = new CellConstraints();
        panel.setLayout(layout);//from   ww  w  .j  a v a  2  s  .c o m
        panel.add(messageLabel, cc.xyw(2, 2, 2));
        panel.add(choiceBox, cc.xyw(2, 4, 2));

        JOptionPane.showMessageDialog(brainFrame, panel, "Analyze 7.5 image format ...",
                JOptionPane.WARNING_MESSAGE);
        Anatomy selectedAnatomy = (Anatomy) choiceBox.getSelectedItem();
        if (selectedAnatomy != anatomy) {
            //todo hackery alert
            dataSource.getImageInfo().setAnatomy((Anatomy3D) selectedAnatomy);
            dataSource.releaseData();
        }
    }

    return dataSource;

}

From source file:ucar.unidata.idv.control.JythonControl.java

/**
 * Make the developer UI contents//from   w  ww .  j ava  2  s . com
 * @return  UI for developer code
 */
private JComponent doMakeDeveloperContents() {

    labelFld = new JTextField((myName != null) ? myName : "", 15);
    labelFld.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setMyName(labelFld.getText().trim());
        }
    });

    Vector probeItems = new Vector();
    for (int i = 0; i < PROBES.length; i++) {
        probeItems.add(new TwoFacedObject(PROBE_NAMES[i], PROBES[i]));
    }
    final JComboBox probeCbx = new JComboBox(probeItems);
    probeCbx.setSelectedItem(new TwoFacedObject(getProbeName(probeType), probeType));
    probeCbx.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                probeType = ((TwoFacedObject) probeCbx.getSelectedItem()).getId().toString();
                doMakeProbe();
            } catch (Exception exc) {
                logException("Changing probe type", exc);
            }
        }
    });

    displayCategoryFld = new JTextField(jythonDisplayCategory, 15);

    categoriesFld = new JTextArea("", 4, 20);
    if (dataCategories != null) {
        categoriesFld.setText(dataCategories);
    }

    Component[] comps = { GuiUtils.rLabel("Display name: "), GuiUtils.left(labelFld),
            GuiUtils.rLabel("Display Category:"), GuiUtils.left(displayCategoryFld),
            GuiUtils.top(GuiUtils.rLabel("Data Categories:")), GuiUtils.left(new JScrollPane(categoriesFld)),
            GuiUtils.rLabel("Probe Type:"), GuiUtils.left(GuiUtils.hflow(Misc.newList(probeCbx,
                    GuiUtils.rLabel("  Probe Color: "), doMakeColorControl(getColor())))) };

    GuiUtils.tmpInsets = GuiUtils.INSETS_5;
    JPanel fldPanel = GuiUtils.doLayout(comps, 2, GuiUtils.WT_NYN, GuiUtils.WT_N);

    try {
        if (jythonCode == null) {
            jythonCode = IOUtil.readContents("/ucar/unidata/idv/control/jythoncontrol.py", "");
        }

        jythonEditor = new JPythonEditor();
        jythonEditor.setText(jythonCode);
        jythonEditor.setPreferredSize(new Dimension(400, 300));
    } catch (VisADException exc) {
        logException("Creating Jython editor", exc);
    }
    JComponent jythonPanel = new JScrollPane(jythonEditor);
    JTabbedPane tab = GuiUtils.getNestedTabbedPane();
    tab.add("Settings", GuiUtils.top(fldPanel));
    List buttons = Misc.newList(GuiUtils.makeButton("Evaluate Init", this, "execJython", "handleInit"),
            GuiUtils.makeButton("Evaluate Data", this, "execJython", "handleData"));

    JPanel buttonPanel = GuiUtils.left(GuiUtils.hbox(buttons));
    tab.add("Jython", GuiUtils.topCenter(buttonPanel, jythonPanel));
    tab.add("Result GUI", jythonContainer);
    return tab;
}

From source file:com.freedomotic.jfrontend.MainWindow.java

/**
 * //w  w w . ja va 2s. co m
 * @param evt 
 */
private void mnuLanguageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuLanguageActionPerformed
    //JDK 1,7 version: JComboBox<i18n.ComboLanguage> combo = new JComboBox<i18n.ComboLanguage>(I18n.getAvailableLocales());
    //JDK 1.6 version: next line
    Vector<ComboLanguage> languages = new Vector<ComboLanguage>();
    for (Locale loc : i18n.getAvailableLocales()) {
        languages.add(new ComboLanguage(
                loc.getDisplayCountry(i18n.getDefaultLocale()) + " - " + loc.getDisplayLanguage(loc),
                loc.toString(), loc));
    }
    Collections.sort(languages);
    languages.add(new ComboLanguage("Automatic", "auto", Locale.ENGLISH));

    JComboBox combo = new JComboBox(languages);

    for (ComboLanguage cmb : languages) {
        if (cmb.getValue().equals(i18n.getDefaultLocale())) {
            combo.setSelectedItem(cmb);
            break;
        }
    }
    JLabel lbl = new JLabel(i18n.msg("language"));
    int result = JOptionPane.showConfirmDialog(this, new Object[] { lbl, combo }, i18n.msg("language"),
            JOptionPane.OK_CANCEL_OPTION);
    if (result == JOptionPane.OK_OPTION) {
        ComboLanguage selected = (ComboLanguage) combo.getSelectedItem();
        i18n.setDefaultLocale(selected.getValue());
        updateStrings();
    }
}