List of usage examples for javax.swing JComboBox setSelectedItem
@BeanProperty(bound = false, preferred = true, description = "Sets the selected item in the JComboBox.") public void setSelectedItem(Object anObject)
From source file:nl.ru.ai.projects.parrot.biomav.editor.BehaviorEditor.java
private void setNewSelectedParameterControlInterface(ParameterControlInterface pcInterface) { pcInterfacePanelContents.removeAll(); selectedPCInterface = null;//from w ww . j a va 2 s. co m if (pcInterface != null) { selectedPCInterface = pcInterface; final ParameterControlInterface fpcInterface = pcInterface; String[] parameterNames = pcInterface.getParameterNames(); ParameterControlInterface.ParameterTypes[] parameterTypes = pcInterface.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { JLabel label = new JLabel(parameterNames[i]); pcInterfacePanelContents.add(label); final int index = i; switch (parameterTypes[i]) { case OPTIONS: final JComboBox optionComboBox = new JComboBox(pcInterface.getParameterOptions(i)); optionComboBox.setEditable(false); optionComboBox.setSelectedItem(pcInterface.getParameterValue(i)); optionComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fpcInterface.setParameterValue(index, optionComboBox.getSelectedItem()); repaint(); } }); pcInterfacePanelContents.add(optionComboBox); break; } } } pcInterfacePanel.validate(); }
From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java
private JPanel getExecutionTypePanel(final ModelGraph graph, final ViewState state) { JPanel panel = new JPanel(); panel.setBorder(new EtchedBorder()); panel.setLayout(new BorderLayout()); panel.add(new JLabel("ExecutionType:"), BorderLayout.WEST); JComboBox comboBox = new JComboBox(); if (graph.hasChildren()) { comboBox.addItem("parallel"); comboBox.addItem("sequential"); } else if (graph.getModel().getExecutionType().equals("task")) { comboBox.addItem("parallel"); comboBox.addItem("sequential"); comboBox.addItem("task"); } else if (graph.isCondition() || graph.getModel().getExecutionType().equals("condition")) { comboBox.addItem("parallel"); comboBox.addItem("sequential"); comboBox.addItem("condition"); } else {//w ww . ja v a 2 s . co m comboBox.addItem("parallel"); comboBox.addItem("sequential"); comboBox.addItem("task"); } comboBox.setSelectedItem(graph.getModel().getExecutionType()); comboBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (!graph.getModel().getExecutionType().equals(e.getItem())) { graph.getModel().setExecutionType((String) e.getItem()); DefaultPropView.this.notifyListeners(); DefaultPropView.this.refreshView(state); } } }); panel.add(comboBox, BorderLayout.CENTER); return panel; }
From source file:org.csml.tommo.sugar.modules.QualityHeatMapsPerTileAndBase.java
public ActionListener createThresholdChangedListener() { return new ActionListener() { @Override//from w w w.j av a 2 s .co m public void actionPerformed(ActionEvent event) { JComboBox qualityCombo = (JComboBox) event.getSource(); Integer threshold = (Integer) qualityCombo.getSelectedItem(); QualityHeatMapsPerTileAndBase qualityHeatMapsPerTileAndBase = QualityHeatMapsPerTileAndBase.this; if (qualityHeatMapsPerTileAndBase.changeQualityMatrixMap(threshold)) { // loaded successfully // do nothing // the table will be updated in propertChanged() listener } else { // load failed // display info JOptionPane.showMessageDialog(SugarApplication.getApplication(), "Failed to load module from cache for threshold: " + threshold, "Load Error", JOptionPane.ERROR_MESSAGE); // delete the failed threshold qualityCombo.removeItem(threshold); QCModule[] module = new QCModule[] { qualityHeatMapsPerTileAndBase }; // revert to old value int originalThreshold = qualityHeatMapsPerTileAndBase.getQualityThreshold(); int matrixSize = qualityHeatMapsPerTileAndBase.getMatrixSize(); File file = SugarApplication.getApplication().getSelectedSequenceFile().getFile(); OpenedFileCache.getInstance().readModulesFromCache(file, module, null, matrixSize, originalThreshold); qualityCombo.setSelectedItem(originalThreshold); } } }; }
From source file:org.encog.workbench.tabs.visualize.bayesian.BayesianStructureTab.java
public BayesianStructureTab(BayesianNetwork method) { super(null);//from w ww .j a v a2 s . co m // Graph<V, E> where V is the type of the vertices // and E is the type of the edges this.graph = buildGraph(method); Layout<DrawnEvent, DrawnEventConnection> layout = new KKLayout(graph); vv = new VisualizationViewer<DrawnEvent, DrawnEventConnection>(layout); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<DrawnEvent>()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.N); vv.setVertexToolTipTransformer(new Transformer<DrawnEvent, String>() { public String transform(DrawnEvent edge) { return edge.getToolTip(); } }); Transformer<DrawnEvent, Paint> vertexPaint = new Transformer<DrawnEvent, Paint>() { public Paint transform(DrawnEvent neuron) { return Color.white; } }; final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); this.setLayout(new BorderLayout()); add(panel, BorderLayout.CENTER); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); final ScalingControl scaler = new CrossoverScalingControl(); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity(); } }); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener()); JPanel controls = new JPanel(); controls.setLayout(new FlowLayout(FlowLayout.LEFT)); controls.add(plus); controls.add(minus); controls.add(reset); controls.add(modeBox); controls.add(jcb); Border border = BorderFactory.createEtchedBorder(); controls.setBorder(border); add(controls, BorderLayout.NORTH); }
From source file:org.esa.snap.ui.tooladapter.dialogs.ToolParameterEditorDialog.java
public JPanel createMainPanel() { GridBagLayout layout = new GridBagLayout(); layout.columnWidths = new int[] { 100, 390 }; mainPanel = new JPanel(layout); addTextPropertyEditor(mainPanel, "Name: ", "name", parameter.getName(), 0, true); addTextPropertyEditor(mainPanel, "Alias: ", "alias", parameter.getAlias(), 1, true); //dataType//from w w w.j a v a2 s . c o m mainPanel.add(new JLabel("Type"), getConstraints(2, 0, 1)); JComboBox comboEditor = new JComboBox(typesMap.keySet().toArray()); comboEditor.setSelectedItem(typesMap.getKey(parameter.getDataType())); comboEditor.addActionListener(ev -> { JComboBox cb = (JComboBox) ev.getSource(); String typeName = (String) cb.getSelectedItem(); if (!parameter.getDataType().equals(typesMap.get(typeName))) { parameter.setDataType((Class<?>) typesMap.get(typeName)); //reset value set parameter.setValueSet(null); paramContext.getPropertySet().getProperty(parameter.getName()).getDescriptor().setValueSet(null); try { valuesContext.getPropertySet().getProperty("valueSet").setValue(null); } catch (ValidationException e) { logger.warning(e.getMessage()); } //editor must updated try { if (editorComponent != null) { mainPanel.remove(editorComponent); } editorComponent = uiWrapper.reloadUIComponent((Class<?>) typesMap.get(typeName)); if (!("File".equals(typeName) || "List".equals(typeName))) { editorComponent.setInputVerifier(new TypedValueValidator( "The value entered is not of the specified data type", parameter.getDataType())); } mainPanel.add(editorComponent, getConstraints(3, 1, 1)); mainPanel.revalidate(); } catch (Exception e) { logger.warning(e.getMessage()); Dialogs.showError(e.getMessage()); } } }); mainPanel.add(comboEditor, getConstraints(2, 1, 1)); //defaultValue mainPanel.add(new JLabel("Default value"), getConstraints(3, 0, 1)); try { editorComponent = uiWrapper.getUIComponent(); mainPanel.add(editorComponent, getConstraints(3, 1, 1)); } catch (Exception e) { e.printStackTrace(); } addTextPropertyEditor(mainPanel, "Description: ", "description", parameter.getDescription(), 4, false); addTextPropertyEditor(mainPanel, "Label: ", "label", parameter.getLabel(), 5, false); addTextPropertyEditor(mainPanel, "Unit: ", "unit", parameter.getUnit(), 6, false); addTextPropertyEditor(mainPanel, "Interval: ", "interval", parameter.getInterval(), 7, false); JComponent valueSetEditor = addTextPropertyEditor(mainPanel, "Value set: ", "valueSet", StringUtils.join(parameter.getValueSet(), ArrayConverter.SEPARATOR), 8, false); valueSetEditor.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { } @Override public void focusLost(FocusEvent ev) { //the value set may impact the editor try { String newValueSet = ((JTextField) valueSetEditor).getText(); if (newValueSet.isEmpty()) { parameter.setValueSet(null); valuesContext.getPropertySet().getProperty("valueSet").setValue(null); } else { parameter.setValueSet(newValueSet.split(ArrayConverter.SEPARATOR)); valuesContext.getPropertySet().getProperty("valueSet") .setValue(newValueSet.split(ArrayConverter.SEPARATOR)); } if (editorComponent != null) { mainPanel.remove(editorComponent); } createContextForValueEditor(); if (!(File.class.equals(parameter.getDataType()) || parameter.getDataType().isArray())) { editorComponent.setInputVerifier(new TypedValueValidator( "The value entered is not of the specified data type", parameter.getDataType())); } mainPanel.add(editorComponent, getConstraints(3, 1, 1)); mainPanel.revalidate(); } catch (Exception e) { logger.warning(e.getMessage()); Dialogs.showError(e.getMessage()); } } }); addTextPropertyEditor(mainPanel, "Condition: ", "condition", parameter.getCondition(), 9, false); addTextPropertyEditor(mainPanel, "Pattern: ", "pattern", parameter.getPattern(), 10, false); addTextPropertyEditor(mainPanel, "Format: ", "format", parameter.getFormat(), 11, false); addBoolPropertyEditor(mainPanel, "Not null", "notNull", parameter.isNotNull(), 12); addBoolPropertyEditor(mainPanel, "Not empty", "notEmpty", parameter.isNotEmpty(), 13); addTextPropertyEditor(mainPanel, "ItemAlias: ", "itemAlias", parameter.getItemAlias(), 14, false); addBoolPropertyEditor(mainPanel, "Deprecated", "deprecated", parameter.isDeprecated(), 15); return mainPanel; }
From source file:org.gcaldaemon.gui.config.MainConfig.java
public static final boolean selectItem(JComboBox combo, String value) { if (value == null || combo == null || value.length() == 0) { return false; }//from w w w . j a v a2 s .c o m ComboBoxModel model = combo.getModel(); if (model != null) { int n, size = model.getSize(); n = value.indexOf(" - "); if (n != -1) { value = value.substring(n + 3); } String test; for (int i = 0; i < size; i++) { test = (String) model.getElementAt(i); if (test != null) { n = test.indexOf(" - "); if (n != -1) { test = test.substring(n + 3); } if (test.equals(value)) { combo.setSelectedIndex(i); combo.setToolTipText((String) model.getElementAt(i)); return true; } } } } if (combo.isEditable()) { combo.setSelectedItem(value); combo.setToolTipText(value); return true; } return false; }
From source file:org.graphwalker.GUI.App.java
@SuppressWarnings("serial") private void addButtons(JToolBar toolBar) { loadButton = makeNavigationButton("open", LOAD, "Load a model (graphml file)", "Load", true); toolBar.add(loadButton);//w w w. j a v a2s. c o m reloadButton = makeNavigationButton("reload", RELOAD, "Reload/Restart already loaded Model", "Reload", false); toolBar.add(reloadButton); firstButton = makeNavigationButton("first", FIRST, "Start at the beginning", "First", false); toolBar.add(firstButton); backButton = makeNavigationButton("back", BACK, "Backs a step", "Back", false); toolBar.add(backButton); runButton = makeNavigationButton("run", RUN, "Starts the execution/Take a step forward in the log", "Run", false); toolBar.add(runButton); pauseButton = makeNavigationButton("pause", PAUSE, "Pauses the execution", "Pause", false); toolBar.add(pauseButton); nextButton = makeNavigationButton("next", NEXT, "Walk a step in the model/Go to the end of log", "Next", false); toolBar.add(nextButton); soapButton = makeNavigationCheckBoxButton("soap", SOAP, "Run MBT in SOAP(Web Services) mode", "Soap"); soapButton.setSelected(Util.readSoapGuiStartupState()); toolBar.add(soapButton); centerOnVertexButton = makeNavigationCheckBoxButton("centerOnVertex", CENTERONVERTEX, "Center the layout on the current vertex", "Center on current vertex"); toolBar.add(centerOnVertexButton); @SuppressWarnings("rawtypes") Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, getVv())); jcb.setSelectedItem(StaticLayout.class); toolBar.add(jcb); }
From source file:org.jets3t.gui.UserInputFields.java
/** * Builds a user input panel matching the fields specified in the uploader.properties file. * * @param fieldsPanel//from ww w . j a v a2 s . co m * the panel component to add prompt and user input components to. * @param uploaderProperties * properties specific to the Uploader application that includes the field.* settings * necessary to build the User Inputs screen. * * @return * true if there is at least one valid user input field, false otherwise. */ public boolean buildFieldsPanel(JPanel fieldsPanel, Jets3tProperties uploaderProperties) { int fieldIndex = 0; for (int fieldNo = 0; fieldNo < 100; fieldNo++) { String fieldName = uploaderProperties.getStringProperty("field." + fieldNo + ".name", null); String fieldType = uploaderProperties.getStringProperty("field." + fieldNo + ".type", null); String fieldPrompt = uploaderProperties.getStringProperty("field." + fieldNo + ".prompt", null); String fieldOptions = uploaderProperties.getStringProperty("field." + fieldNo + ".options", null); String fieldDefault = uploaderProperties.getStringProperty("field." + fieldNo + ".default", null); if (fieldName == null) { log.debug("No field with index number " + fieldNo); continue; } else { if (fieldType == null || fieldPrompt == null) { log.warn("Field '" + fieldName + "' missing .type or .prompt properties"); continue; } if ("message".equals(fieldType)) { JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); } else if ("radio".equals(fieldType)) { if (fieldOptions == null) { log.warn( "Radio button field '" + fieldName + "' is missing the required .options property"); continue; } JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JPanel optionsPanel = skinsFactory.createSkinnedJPanel("OptionsPanel"); optionsPanel.setLayout(new GridBagLayout()); int columnOffset = 0; ButtonGroup buttonGroup = new ButtonGroup(); StringTokenizer st = new StringTokenizer(fieldOptions, ","); while (st.hasMoreTokens()) { String option = st.nextToken(); JRadioButton radioButton = skinsFactory.createSkinnedJRadioButton(fieldName); radioButton.setText(option); buttonGroup.add(radioButton); if (fieldDefault != null && fieldDefault.equals(option)) { // This option is the default one. radioButton.setSelected(true); } else if (buttonGroup.getButtonCount() == 1) { // Make first button the default. radioButton.setSelected(true); } optionsPanel.add(radioButton, new GridBagConstraints(columnOffset++, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0)); } fieldsPanel.add(optionsPanel, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsNone, 0, 0)); userInputComponentsMap.put(fieldName, buttonGroup); } else if ("selection".equals(fieldType)) { if (fieldOptions == null) { log.warn( "Radio button field '" + fieldName + "' is missing the required .options property"); continue; } JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JComboBox comboBox = skinsFactory.createSkinnedJComboBox(fieldName); StringTokenizer st = new StringTokenizer(fieldOptions, ","); while (st.hasMoreTokens()) { String option = st.nextToken(); comboBox.addItem(option); } if (fieldDefault != null) { comboBox.setSelectedItem(fieldDefault); } fieldsPanel.add(comboBox, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); userInputComponentsMap.put(fieldName, comboBox); } else if ("text".equals(fieldType)) { JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JTextField textField = skinsFactory.createSkinnedJTextField(fieldName); if (fieldDefault != null) { textField.setText(fieldDefault); } fieldsPanel.add(textField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); userInputComponentsMap.put(fieldName, textField); } else if ("password".equals(fieldType)) { JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JPasswordField passwordField = skinsFactory.createSkinnedJPasswordField(fieldName); if (fieldDefault != null) { passwordField.setText(fieldDefault); } fieldsPanel.add(passwordField, new GridBagConstraints(0, fieldIndex++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); userInputComponentsMap.put(fieldName, passwordField); } else if (fieldType.equals("textarea")) { JHtmlLabel label = skinsFactory.createSkinnedJHtmlLabel(fieldName); label.setText(fieldPrompt); label.setHyperlinkeActivatedListener(hyperlinkListener); fieldsPanel.add(label, new GridBagConstraints(0, fieldIndex++, 2, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); JTextArea textArea = skinsFactory.createSkinnedJTextArea(fieldName); textArea.setLineWrap(true); if (fieldDefault != null) { textArea.setText(fieldDefault); } JScrollPane scrollPane = skinsFactory.createSkinnedJScrollPane(fieldName); scrollPane.setViewportView(textArea); fieldsPanel.add(scrollPane, new GridBagConstraints(0, fieldIndex++, 2, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.BOTH, insetsDefault, 0, 0)); userInputComponentsMap.put(fieldName, textArea); } else { log.warn("Unrecognised .type setting for field '" + fieldName + "'"); } } } return isUserInputFieldsAvailable(); }
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;// w ww . j a va 2 s . com 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.ui.collect.component.AbstractCollectableComponent.java
/** * @param result/*w w w. j a va 2s . com*/ * @param clctcomp */ private static void addRightOperandToPopupMenu(JPopupMenu result, final AbstractCollectableComponent clctcomp) { result.addSeparator(); final ButtonGroup btngrpCompareWith = new ButtonGroup(); final SpringLocaleDelegate localeDelegate = SpringLocaleDelegate.getInstance(); final JRadioButtonMenuItem miValue = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.17", "Wertvergleich")); miValue.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.10", "Dieses Feld mit einem festen Wert vergleichen")); result.add(miValue); btngrpCompareWith.add(miValue); miValue.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { clctcomp.resetWithComparison(); clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } }); final JRadioButtonMenuItem miOtherField = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.12", "Feldvergleich...")); miOtherField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.9", "Dieses Feld mit dem Inhalt eines anderen Felds vergleichen")); result.add(miOtherField); btngrpCompareWith.add(miOtherField); miOtherField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { assert clctcomp.clcte != null; // select entity field with the same data type: final List<CollectableEntityField> lstclctefFiltered = CollectionUtils.select( CollectableUtils.getCollectableEntityFields(clctcomp.clcte), new Predicate<CollectableEntityField>() { @Override public boolean evaluate(CollectableEntityField clctef) { return clctef.getJavaClass() == clctcomp.clctef.getJavaClass(); } }); // and sort by label: final List<CollectableEntityField> lstclctefSorted = CollectionUtils.sorted(lstclctefFiltered, new CollectableEntityField.LabelComparator()); final JComboBox cmbbx = new JComboBox(lstclctefSorted.toArray()); cmbbx.setSelectedItem(clctcomp.getComparisonOtherField()); final int iBtn = JOptionPane .showConfirmDialog(clctcomp.getJComponent(), new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.6", "Anderes Feld: "), cmbbx }, localeDelegate.getMessage("AbstractCollectableComponent.15", "Vergleich mit anderem Feld"), JOptionPane.OK_CANCEL_OPTION); if (iBtn == JOptionPane.OK_OPTION) { clctcomp.setWithComparison((CollectableEntityField) cmbbx.getSelectedItem()); if (clctcomp.getComparisonOtherField() != null) { // clear the view: clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField())); if (clctcomp.compop.getOperandCount() < 2) { // If the user selects "other field" and forgot to set the operator, we assume "EQUAL": clctcomp.compop = ComparisonOperator.EQUAL; } } clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } } }); final List<ComparisonParameter> compatibleParameters = ComparisonParameter .getCompatibleParameters(clctcomp.getEntityField()); final JRadioButtonMenuItem miParameterField = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.18", null)); miParameterField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.19", null)); btngrpCompareWith.add(miParameterField); if (compatibleParameters.size() > 0) { result.add(miParameterField); miParameterField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { ResourceIdMapper<ComparisonParameter> mapper = new ResourceIdMapper<ComparisonParameter>( compatibleParameters); JComboBox cmbbx = new JComboBox(CollectionUtils.sorted(compatibleParameters, mapper).toArray()); cmbbx.setRenderer(new DefaultListRenderer(mapper)); cmbbx.setSelectedItem(clctcomp.getComparisonParameter()); final int opt = JOptionPane.showConfirmDialog(clctcomp.getJComponent(), new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.20", null), cmbbx }, localeDelegate.getMessage("AbstractCollectableComponent.19", null), JOptionPane.OK_CANCEL_OPTION); if (opt == JOptionPane.OK_OPTION) { clctcomp.setWithComparison((ComparisonParameter) cmbbx.getSelectedItem()); if (clctcomp.getComparisonParameter() != null) { clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField())); if (clctcomp.compop.getOperandCount() < 2) { clctcomp.compop = ComparisonOperator.EQUAL; } } clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } } }); } result.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent ev) { if (clctcomp.getComparisonParameter() != null) { miParameterField.setSelected(true); } else if (clctcomp.getComparisonOtherField() == null || clctcomp.getComparisonOperator().getOperandCount() < 2) { miValue.setSelected(true); } else { miOtherField.setSelected(true); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) { } @Override public void popupMenuCanceled(PopupMenuEvent ev) { } }); }