Search in sources :

Example 6 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project libgdx by libgdx.

the class EffectUtil method optionValue.

/** Returns a value that represents a fixed number of options. All options are strings.
	 * @param options The first array has an entry for each option. Each entry is either a String[1] that is both the display value
	 *           and actual value, or a String[2] whose first element is the display value and second element is the actual value. */
public static Value optionValue(String name, final String currentValue, final String[][] options, final String description) {
    return new DefaultValue(name, currentValue.toString()) {

        public void showDialog() {
            int selectedIndex = -1;
            DefaultComboBoxModel model = new DefaultComboBoxModel();
            for (int i = 0; i < options.length; i++) {
                model.addElement(options[i][0]);
                if (getValue(i).equals(currentValue))
                    selectedIndex = i;
            }
            JComboBox comboBox = new JComboBox(model);
            comboBox.setSelectedIndex(selectedIndex);
            if (showValueDialog(comboBox, description))
                value = getValue(comboBox.getSelectedIndex());
        }

        private String getValue(int i) {
            if (options[i].length == 1)
                return options[i][0];
            return options[i][1];
        }

        public String toString() {
            for (int i = 0; i < options.length; i++) if (getValue(i).equals(value))
                return options[i][0].toString();
            return "";
        }

        public Object getObject() {
            return value;
        }
    };
}
Also used : JComboBox(javax.swing.JComboBox) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 7 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project gephi by gephi.

the class UIExporterPDFPanel method setup.

public void setup(PDFExporter pdfExporter) {
    DefaultComboBoxModel comboBoxModel = (DefaultComboBoxModel) pageSizeCombo.getModel();
    PageSizeItem pageSize = new PageSizeItem(pdfExporter.getPageSize());
    int index = 0;
    if ((index = comboBoxModel.getIndexOf(pageSize)) == -1) {
        comboBoxModel.setSelectedItem(customSizeString);
    } else {
        pageSize = (PageSizeItem) comboBoxModel.getElementAt(index);
        comboBoxModel.setSelectedItem(pageSize);
    }
    setPageSize(pageSize);
    setMargins(pdfExporter.getMarginTop(), pdfExporter.getMarginBottom(), pdfExporter.getMarginLeft(), pdfExporter.getMarginRight());
    setOrientation(pdfExporter.isLandscape());
}
Also used : DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 8 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project gephi by gephi.

the class ReportPanel method initGraphTypeCombo.

private void initGraphTypeCombo(final Container[] containers) {
    final String directedStr = NbBundle.getMessage(ReportPanel.class, "ReportPanel.graphType.directed");
    final String undirectedStr = NbBundle.getMessage(ReportPanel.class, "ReportPanel.graphType.undirected");
    final String mixedStr = NbBundle.getMessage(ReportPanel.class, "ReportPanel.graphType.mixed");
    EdgeDirectionDefault edd = null;
    for (Container container : containers) {
        EdgeDirectionDefault d = container.getUnloader().getEdgeDefault();
        if (edd == null) {
            edd = d;
        } else if (d.equals(EdgeDirectionDefault.UNDIRECTED) && !edd.equals(EdgeDirectionDefault.UNDIRECTED)) {
            edd = EdgeDirectionDefault.MIXED;
        } else if (d.equals(EdgeDirectionDefault.DIRECTED) && !edd.equals(EdgeDirectionDefault.DIRECTED)) {
            edd = EdgeDirectionDefault.MIXED;
        }
    }
    final EdgeDirectionDefault dir = edd;
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            DefaultComboBoxModel comboModel = new DefaultComboBoxModel();
            switch(dir) {
                case DIRECTED:
                    comboModel.addElement(directedStr);
                    comboModel.addElement(undirectedStr);
                    comboModel.addElement(mixedStr);
                    comboModel.setSelectedItem(directedStr);
                    break;
                case UNDIRECTED:
                    comboModel.addElement(undirectedStr);
                    comboModel.addElement(mixedStr);
                    comboModel.setSelectedItem(undirectedStr);
                    break;
                case MIXED:
                    comboModel.addElement(directedStr);
                    comboModel.addElement(undirectedStr);
                    comboModel.addElement(mixedStr);
                    comboModel.setSelectedItem(mixedStr);
                    break;
            }
            graphTypeCombo.setModel(comboModel);
        }
    });
    graphTypeCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                Object g = e.getItem();
                if (g.equals(directedStr)) {
                    for (Container container : containers) {
                        container.getLoader().setEdgeDefault(EdgeDirectionDefault.DIRECTED);
                    }
                } else if (g.equals(undirectedStr)) {
                    for (Container container : containers) {
                        container.getLoader().setEdgeDefault(EdgeDirectionDefault.UNDIRECTED);
                    }
                } else if (g.equals(mixedStr)) {
                    for (Container container : containers) {
                        container.getLoader().setEdgeDefault(EdgeDirectionDefault.MIXED);
                    }
                }
            }
        }
    });
}
Also used : Container(org.gephi.io.importer.api.Container) ItemEvent(java.awt.event.ItemEvent) ItemListener(java.awt.event.ItemListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) EdgeDirectionDefault(org.gephi.io.importer.api.EdgeDirectionDefault)

Example 9 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project gephi by gephi.

the class PreviewSettingsTopComponent method setup.

public void setup(PreviewUIModel previewModel) {
    propertySheet.setNodes(new Node[] { new PreviewNode(propertySheet) });
    PreviewUIController previewUIController = Lookup.getDefault().lookup(PreviewUIController.class);
    if (previewModel != null) {
        ratioSlider.setValue((int) (previewModel.getVisibilityRatio() * 100));
    }
    //Presets
    if (previewModel == null) {
        saveButton.setEnabled(false);
        labelPreset.setEnabled(false);
        presetComboBox.setEnabled(false);
        presetComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
    } else {
        saveButton.setEnabled(true);
        labelPreset.setEnabled(true);
        presetComboBox.setEnabled(true);
        DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
        defaultPresetLimit = 0;
        for (PreviewPreset preset : previewUIController.getDefaultPresets()) {
            comboBoxModel.addElement(preset);
            defaultPresetLimit++;
        }
        PreviewPreset[] userPresets = previewUIController.getUserPresets();
        if (userPresets.length > 0) {
            comboBoxModel.addElement(NO_SELECTION);
            for (PreviewPreset preset : userPresets) {
                comboBoxModel.addElement(preset);
            }
        }
        presetComboBox.setSelectedItem(previewModel.getCurrentPreset());
        presetComboBox.setModel(comboBoxModel);
    }
    //Refresh tabs
    int tabCount = tabbedPane.getTabCount();
    for (int i = 2; i < tabCount; i++) {
        //Start at 2, not removing settings and renderer manager tabs
        tabbedPane.removeTabAt(i);
    }
    for (PreviewUI pui : Lookup.getDefault().lookupAll(PreviewUI.class)) {
        pui.unsetup();
    }
    if (previewModel != null) {
        PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
        PreviewModel pModel = previewController.getModel();
        //Add new tabs
        for (PreviewUI pui : Lookup.getDefault().lookupAll(PreviewUI.class)) {
            pui.setup(pModel);
            JPanel pluginPanel = pui.getPanel();
            if (UIUtils.isAquaLookAndFeel()) {
                pluginPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
            }
            if (pui.getIcon() != null) {
                tabbedPane.addTab(pui.getPanelTitle(), pui.getIcon(), pluginPanel);
            } else {
                tabbedPane.addTab(pui.getPanelTitle(), pluginPanel);
            }
        }
    }
}
Also used : JPanel(javax.swing.JPanel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) PreviewUI(org.gephi.preview.spi.PreviewUI) PreviewController(org.gephi.preview.api.PreviewController) PreviewPreset(org.gephi.preview.api.PreviewPreset) PreviewModel(org.gephi.preview.api.PreviewModel) PreviewUIController(org.gephi.desktop.preview.api.PreviewUIController) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 10 with DefaultComboBoxModel

use of javax.swing.DefaultComboBoxModel in project gephi by gephi.

the class LayoutPanel method refreshChooser.

private void refreshChooser() {
    DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
    comboBoxModel.addElement(NO_SELECTION);
    comboBoxModel.setSelectedItem(NO_SELECTION);
    if (model != null) {
        List<LayoutBuilder> builders = new ArrayList<>(Lookup.getDefault().lookupAll(LayoutBuilder.class));
        Collections.sort(builders, new Comparator() {

            @Override
            public int compare(Object o1, Object o2) {
                return ((LayoutBuilder) o1).getName().compareTo(((LayoutBuilder) o2).getName());
            }
        });
        for (LayoutBuilder builder : builders) {
            LayoutBuilderWrapper item = new LayoutBuilderWrapper(builder);
            comboBoxModel.addElement(item);
            if (model.getSelectedLayout() != null && builder == model.getSelectedBuilder()) {
                comboBoxModel.setSelectedItem(item);
            }
        }
    }
    layoutCombobox.setModel(comboBoxModel);
    if (model != null) {
        layoutCombobox.setEnabled(!model.isRunning());
    }
}
Also used : LayoutBuilder(org.gephi.layout.spi.LayoutBuilder) ArrayList(java.util.ArrayList) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) Comparator(java.util.Comparator)

Aggregations

DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)63 JPanel (javax.swing.JPanel)16 JLabel (javax.swing.JLabel)13 JButton (javax.swing.JButton)12 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)11 JComboBox (javax.swing.JComboBox)11 Insets (java.awt.Insets)10 GridBagConstraints (java.awt.GridBagConstraints)9 GridBagLayout (java.awt.GridBagLayout)8 JScrollPane (javax.swing.JScrollPane)8 JTextField (javax.swing.JTextField)7 BorderLayout (java.awt.BorderLayout)5 Dimension (java.awt.Dimension)5 ItemEvent (java.awt.event.ItemEvent)5 ItemListener (java.awt.event.ItemListener)5 ArrayList (java.util.ArrayList)5 Vector (java.util.Vector)5 JCheckBox (javax.swing.JCheckBox)5 FlowLayout (java.awt.FlowLayout)4