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;
}
};
}
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());
}
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);
}
}
}
}
});
}
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);
}
}
}
}
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());
}
}
Aggregations