List of usage examples for javax.swing JComboBox getSelectedItem
public Object getSelectedItem()
From source file:ro.nextreports.designer.querybuilder.RuntimeParametersPanel.java
public Object getParameterValue(QueryParameter qp) throws RuntimeParameterException { String paramName = qp.getName(); String runtimeParamName = qp.getRuntimeName(); if ((runtimeParamName == null) || runtimeParamName.trim().equals("")) { runtimeParamName = paramName;/*from ww w . ja v a2 s . co m*/ } JComponent component = getComponent(qp); String type = qp.getValueClassName(); Object value = null; if (!qp.isIgnore()) { if (component instanceof JTextField) { value = ((JTextField) component).getText(); if (value.equals("")) { if (qp.isMandatory()) { throw new RuntimeParameterException( I18NSupport.getString("runtime.parameters.notentered", runtimeParamName)); } else { value = null; } } } else if (component instanceof JComboBox) { JComboBox combo = (JComboBox) component; if (combo.getSelectedIndex() == 0) { if (qp.isMandatory()) { throw new RuntimeParameterException( I18NSupport.getString("runtime.parameters.notselected", runtimeParamName)); } else { value = null; } } else { value = combo.getSelectedItem(); } } else if (component instanceof ListSelectionPanel) { value = ((ListSelectionPanel) component).getDestinationElements().toArray(); if (((Object[]) value).length == 0) { if (qp.isMandatory()) { throw new RuntimeParameterException( I18NSupport.getString("runtime.parameters.notselected", runtimeParamName)); } else { value = new Object[] { ParameterUtil.NULL }; } } } else if (component instanceof ListAddPanel) { value = ((ListAddPanel) component).getElements().toArray(); if (((Object[]) value).length == 0) { if (qp.isMandatory()) { throw new RuntimeParameterException( I18NSupport.getString("runtime.parameters.notselected", runtimeParamName)); } else { value = new Object[] { ParameterUtil.NULL }; } } } else if (component instanceof JDateTimePicker) { value = ((JDateTimePicker) component).getDate(); if (value == null) { if (qp.isMandatory()) { throw new RuntimeParameterException( I18NSupport.getString("runtime.parameters.notentered", runtimeParamName)); } } } else if (component instanceof JXDatePicker) { value = ((JXDatePicker) component).getDate(); if (value == null) { if (qp.isMandatory()) { throw new RuntimeParameterException( I18NSupport.getString("runtime.parameters.notentered", runtimeParamName)); } } } else if (component instanceof JCheckBox) { value = ((JCheckBox) component).isSelected(); } if (value != null) { if (value.getClass().getName().equals("java.lang.String")) { try { value = ParameterUtil.getParameterValueFromString(qp.getValueClassName(), (String) value); } catch (Exception e) { LOG.error(e.getMessage(), e); // the exception is thrown outside the for statement so that // all parameter values are saved throw new RuntimeParameterException("Invalid parameter value " + value + " for parameter " + runtimeParamName + " of type " + type + " ."); } } } } return value; }
From source file:se.streamsource.streamflow.client.ui.workspace.cases.general.forms.geo.GeoLocationFieldPanel.java
private JComboBox<MapType> createMapTypeSelector() { final JComboBox<MapType> mapTypeSelector = new JComboBox<MapType>(MapType.values()); mapTypeSelector.addItemListener(new ItemListener() { @Override//from w ww .j a v a2 s. co m public void itemStateChanged(ItemEvent e) { setMapType((MapType) mapTypeSelector.getSelectedItem()); } }); return mapTypeSelector; }
From source file:se.trixon.jota.client.ui.MainFrame.java
private void requestConnect() throws NotBoundException { String[] hosts = mOptions.getHosts().split(";"); Arrays.sort(hosts);/* w w w .ja va 2 s . c o m*/ DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(hosts); JComboBox hostComboBox = new JComboBox(comboBoxModel); hostComboBox.setEditable(true); hostComboBox.setSelectedItem(mClient.getHost()); JTextField portTextField = new JTextField(String.valueOf(mClient.getPortHost())); final JComponent[] inputs = new JComponent[] { new JLabel(Dict.HOST.toString()), hostComboBox, new JLabel(Dict.PORT.toString()), portTextField, }; Object[] options = { Dict.CONNECT.toString(), Dict.CANCEL.toString() }; int retval = JOptionPane.showOptionDialog(this, inputs, Dict.CONNECT_TO_HOST.toString(), JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (retval == 0) { String currentHost = mClient.getHost(); int currentPort = mClient.getPortHost(); String host = (String) hostComboBox.getSelectedItem(); String portString = portTextField.getText(); try { int port = Integer.valueOf(portString); mManager.disconnect(); mManager.connect(host, port); if (comboBoxModel.getIndexOf(host) == -1) { comboBoxModel.addElement(host); } mOptions.setHosts(SwingHelper.comboBoxModelToString(comboBoxModel)); } catch (NumberFormatException e) { Message.error(this, Dict.ERROR.toString(), String.format(Dict.INVALID_PORT.toString(), portString)); } catch (NotBoundException | MalformedURLException | RemoteException | SocketException ex) { Message.error(this, Dict.ERROR.toString(), ex.getLocalizedMessage()); mClient.setHost(currentHost); mClient.setPortHost(currentPort); } } }
From source file:uk.nhs.cfh.dsp.yasb.searchpanel.SearchPanel.java
/** * Creates the control panel.//from w w w. ja v a 2 s . c o m */ private synchronized void createControlPanel() { // set controls for rendering concept ids and labels in a collapsible pane controlsPane = new JXCollapsiblePane(new GridLayout(0, 1)); controlsPane.setName("controlsPane"); final JComboBox conceptTypeBox = new JComboBox(ConceptType.values()); // set default value to UNKNOWN, which will return all types conceptTypeBox.setSelectedItem(ConceptType.UNKNOWN); conceptTypeBox.setAction(new AbstractAction() { public void actionPerformed(ActionEvent e) { // get selected value Object selection = conceptTypeBox.getSelectedItem(); if (selection instanceof ConceptType) { selectedConceptType = (ConceptType) conceptTypeBox.getSelectedItem(); doSearch(); } } }); JPanel panel1 = new JPanel(); panel1.setLayout(new BoxLayout(panel1, BoxLayout.LINE_AXIS)); panel1.add(new JLabel("Concept Type")); panel1.add(Box.createHorizontalStrut(10)); panel1.add(conceptTypeBox); final JComboBox statusBox = new JComboBox(ComponentStatus.values()); statusBox.setSelectedItem(ComponentStatus.CURRENT); statusBox.setAction(new AbstractAction() { public void actionPerformed(ActionEvent arg0) { Object selection = statusBox.getSelectedItem(); if (selection instanceof ComponentStatus) { selectedConceptStatus = (ComponentStatus) statusBox.getSelectedItem(); doSearch(); } } }); JPanel panel2 = new JPanel(); panel2.setLayout(new BoxLayout(panel2, BoxLayout.LINE_AXIS)); panel2.add(new JLabel("Concept Status")); panel2.add(Box.createHorizontalStrut(10)); panel2.add(statusBox); // create stemming enabling checkbox final JCheckBox enableStemmingCheckBox = new JCheckBox(); enableStemmingCheckBox.setAction(new AbstractAction("Enable Stemming") { public void actionPerformed(ActionEvent arg0) { if (enableStemmingCheckBox.isSelected()) { // change analyser selectedAnalyzer = new SnowballAnalyzer("English"); logger.debug("Enabled Stemming"); doSearch(); } else { selectedAnalyzer = new StandardAnalyzer(); logger.debug("Disabled Stemming"); doSearch(); } } }); renderConceptIdsBox = new JCheckBox(new AbstractAction("Render Concept IDs") { public void actionPerformed(ActionEvent e) { // toggle status in tree cell renderer renderer.setRenderConceptId(renderConceptIdsBox.isSelected()); // refresh tree SwingUtilities.updateComponentTreeUI(resultsList); } }); renderConceptIdsBox.setName("preferFSNOverPTJCheckBox"); preferFSNOverPTJCheckBox = new JCheckBox(new AbstractAction("Prefer FSN over PT") { public void actionPerformed(ActionEvent e) { // toggle preference in renderer renderer.setPreferFSNOverPT(preferFSNOverPTJCheckBox.isSelected()); // refresh tree SwingUtilities.updateComponentTreeUI(resultsList); } }); preferFSNOverPTJCheckBox.setName("preferFSNOverPTJCheckBox"); // add panels to controlsPane controlsPane.add(panel1); controlsPane.add(panel2); controlsPane.add(enableStemmingCheckBox); controlsPane.add(renderConceptIdsBox); controlsPane.add(preferFSNOverPTJCheckBox); controlsPane.setCollapsed(true); }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Checks whether an input (query or connect string) is already in its * associated combo box. If not, the new information is added to the combo * list//from w w w .j a v a 2 s. com * * @param combo * JComboBox which has a list of the query statements or connect * strings. */ private void checkForNewString(JComboBox combo) { // String newString, foundString; Object newValue; int checkDups, matchAt; boolean match; // boolean newCommented, foundCommented; // newCommented = foundCommented = false; matchAt = -1; if (combo == querySelection) { newValue = new Query(queryText.getText(), whichModeValue()); // newString = queryText.getText(); // newString = newString.replace('\n', ' '); } else { // newString = (String)combo.getEditor().getItem(); newValue = combo.getEditor().getItem(); } // if (newString.startsWith(COMMENT_PREFIX)) { // newCommented = true; // newString = newString.substring(2); // } // if (newString.trim().length() > 0) { if (newValue.toString().length() > 0) { match = false; for (checkDups = 0; checkDups < combo.getItemCount() && !match; ++checkDups) { // if (combo == querySelection) { // foundString = ((Query)combo.getItemAt(checkDups)).getSQL(); // } else { // foundString = ((String)combo.getItemAt(checkDups)); // } // if (foundString.startsWith(COMMENT_PREFIX)) { // foundString = foundString.substring(2); // foundCommented = true; // } else { // foundCommented = false; // } // if (newString.equals(foundString)) { if (newValue.equals(combo.getItemAt(checkDups))) { match = true; if (combo == querySelection) { ((Query) combo.getItemAt(checkDups)).setMode(whichModeValue()); } combo.setSelectedIndex(checkDups); matchAt = checkDups; } } // if (newCommented) { // newString = COMMENT_PREFIX + newString; // } if (!match) { addToCombo(combo, newValue); if (combo == querySelection) { // addToCombo(combo, new Query(newString, whichModeValue())); combo.setSelectedIndex(combo.getModel().getSize() - 1); matchAt = combo.getSelectedIndex(); } } // if (foundCommented != newCommented) { // if (combo == querySelection) { // replaceInCombo(combo, matchAt, // new Query(newString, whichModeValue())); // } else { // replaceInCombo(combo, matchAt, newString); // } // } if (combo == querySelection) { if (((Query) newValue).isCommented() != ((Query) combo.getSelectedItem()).isCommented()) { replaceInCombo(combo, matchAt, newValue); } } } }
From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java
private JMenu createShortMenu() { JMenu shortMenu = new JMenu(); addDarkModeCallback(b -> {//from w w w . j a v a 2s .co m shortMenu.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE.brighter()); shortMenu.setForeground(b ? Color.WHITE : OPENBST_BLUE); }); shortMenu.setBackground(OPENBST_BLUE.brighter()); shortMenu.setForeground(OPENBST_BLUE); shortMenu.setText(Lang.get("banner.title")); shortMenu.setIcon(new ImageIcon(Icons.getImage("Logo", 16))); JMenuItem label = new JMenuItem(Lang.get("menu.title")); label.setEnabled(false); shortMenu.add(label); shortMenu.addSeparator(); shortMenu.add( new JMenuItem(new AbstractAction(Lang.get("menu.open"), new ImageIcon(Icons.getImage("Open", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { openStory(VisualsUtils.askForFile(OpenBSTGUI.this, Lang.get("file.title"))); } })); shortMenu.addSeparator(); shortMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.create"), new ImageIcon(Icons.getImage("Add Property", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { doNewEditor(); } })); JMenu additionalMenu = new JMenu(Lang.get("menu.advanced")); shortMenu.add(additionalMenu); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.package"), new ImageIcon(Icons.getImage("Open Archive", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { new PackageDialog(instance).setVisible(true); } })); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("langcheck"), new ImageIcon(Icons.getImage("LangCheck", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { final Map<String, String> languages = new Gson() .fromJson(new InputStreamReader( OpenBST.class.getResourceAsStream( "/utybo/branchingstorytree/swing/lang/langs.json"), StandardCharsets.UTF_8), new TypeToken<Map<String, String>>() { }.getType()); languages.remove("en"); languages.remove("default"); JComboBox<String> jcb = new JComboBox<>(new Vector<>(languages.keySet())); JPanel panel = new JPanel(); panel.add(new JLabel(Lang.get("langcheck.choose"))); panel.add(jcb); int result = JOptionPane.showOptionDialog(OpenBSTGUI.this, panel, Lang.get("langcheck"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) { Locale selected = new Locale((String) jcb.getSelectedItem()); if (!Lang.getMap().keySet().contains(selected)) { try { Lang.loadTranslationsFromFile(selected, OpenBST.class .getResourceAsStream("/utybo/branchingstorytree/swing/lang/" + languages.get(jcb.getSelectedItem().toString()))); } catch (UnrespectedModelException | IOException e1) { LOG.warn("Failed to load translation file", e1); } } ArrayList<String> list = new ArrayList<>(); Lang.getLocaleMap(Locale.ENGLISH).forEach((k, v) -> { if (!Lang.getLocaleMap(selected).containsKey(k)) { list.add(k + "\n"); } }); StringBuilder sb = new StringBuilder(); Collections.sort(list); list.forEach(s -> sb.append(s)); JDialog dialog = new JDialog(OpenBSTGUI.this, Lang.get("langcheck")); dialog.getContentPane().setLayout(new MigLayout()); dialog.getContentPane().add(new JLabel(Lang.get("langcheck.result")), "pushx, growx, wrap"); JTextArea area = new JTextArea(); area.setLineWrap(true); area.setWrapStyleWord(true); area.setText(sb.toString()); area.setEditable(false); area.setBorder(BorderFactory.createLoweredBevelBorder()); JScrollPane jsp = new JScrollPane(area); jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); dialog.getContentPane().add(jsp, "pushx, pushy, growx, growy"); dialog.setSize((int) (Icons.getScale() * 300), (int) (Icons.getScale() * 300)); dialog.setLocationRelativeTo(OpenBSTGUI.this); dialog.setModalityType(ModalityType.APPLICATION_MODAL); dialog.setVisible(true); } } })); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.debug"), new ImageIcon(Icons.getImage("Code", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { DebugInfo.launch(OpenBSTGUI.this); } })); JMenu includedFiles = new JMenu("Included BST files"); for (Entry<String, String> entry : OpenBST.getInternalFiles().entrySet()) { JMenuItem jmi = new JMenuItem(entry.getKey()); jmi.addActionListener(ev -> { String path = "/bst/" + entry.getValue(); InputStream is = OpenBSTGUI.class.getResourceAsStream(path); ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(OpenBSTGUI.this, "Extracting...", is); new Thread(() -> { try { File f = File.createTempFile("openbstinternal", ".bsp"); FileOutputStream fos = new FileOutputStream(f); IOUtils.copy(pmis, fos); openStory(f); } catch (final IOException e) { LOG.error("IOException caught", e); showException(Lang.get("file.error").replace("$e", e.getClass().getSimpleName()) .replace("$m", e.getMessage()), e); } }).start(); }); includedFiles.add(jmi); } additionalMenu.add(includedFiles); shortMenu.addSeparator(); JMenu themesMenu = new JMenu(Lang.get("menu.themes")); shortMenu.add(themesMenu); themesMenu.setIcon(new ImageIcon(Icons.getImage("Color Wheel", 16))); ButtonGroup themesGroup = new ButtonGroup(); JRadioButtonMenuItem jrbmi; jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.dark")); if (0 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(0, DARK_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.light")); if (1 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(1, LIGHT_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.debug")); if (2 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(2, DEBUG_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); JMenu additionalLightThemesMenu = new JMenu(Lang.get("menu.themes.morelight")); int j = 3; for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_LIGHT_THEMES.entrySet()) { int jf = j; jrbmi = new JRadioButtonMenuItem(entry.getKey()); if (j == selectedTheme) jrbmi.setSelected(true); jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue())); additionalLightThemesMenu.add(jrbmi); themesGroup.add(jrbmi); j++; } themesMenu.add(additionalLightThemesMenu); JMenu additionalDarkThemesMenu = new JMenu(Lang.get("menu.themes.moredark")); for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_DARK_THEMES.entrySet()) { int jf = j; jrbmi = new JRadioButtonMenuItem(entry.getKey()); if (j == selectedTheme) jrbmi.setSelected(true); jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue())); additionalDarkThemesMenu.add(jrbmi); themesGroup.add(jrbmi); j++; } themesMenu.add(additionalDarkThemesMenu); shortMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.about"), new ImageIcon(Icons.getImage("About", 16))) { /** * */ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { new AboutDialog(instance).setVisible(true); } })); return shortMenu; }
From source file:wigraph.ShortestPathRelation.java
private Component getSelectionBox(final boolean from) { Set<String> s = new TreeSet<String>(); for (String v : mGraph.getVertices()) { s.add(v);//from ww w .j a v a2 s . co m } final JComboBox choices = new JComboBox(s.toArray()); choices.setSelectedIndex(-1); choices.setBackground(Color.WHITE); choices.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String v = (String) choices.getSelectedItem(); if (from) { mFrom = v; } else { mTo = v; } drawShortest(); repaint(); } }); return choices; }