List of usage examples for javax.swing JComboBox setAction
@BeanProperty(visualUpdate = true, description = "the Action instance connected with this ActionEvent source") public void setAction(Action a)
Action
for the ActionEvent
source. From source file:uk.nhs.cfh.dsp.yasb.searchpanel.SearchPanel.java
/** * Creates the control panel.//from w w w . java 2 s . c om */ 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); }