Example usage for javax.swing JCheckBox setAction

List of usage examples for javax.swing JCheckBox setAction

Introduction

In this page you can find the example usage for javax.swing JCheckBox setAction.

Prototype

@BeanProperty(visualUpdate = true, description = "the Action instance connected with this ActionEvent source")
public void setAction(Action a) 

Source Link

Document

Sets the Action.

Usage

From source file:biomine.bmvis2.pipeline.EdgeLabelOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = c.HORIZONTAL;//from w w w  .j av  a 2 s .c  om
    c.weightx = 1;
    c.weighty = 0;
    c.gridy = 0;
    final Set<String> avail = graph.getAvailableEdgeLabels();

    for (final String str : avail) {
        final JCheckBox box = new JCheckBox();
        box.setSelected(enabledLabels.contains(str));
        box.setAction(new AbstractAction(str) {
            public void actionPerformed(ActionEvent arg0) {
                if (box.isSelected() != enabledLabels.contains(str)) {
                    if (box.isSelected())
                        enabledLabels.add(str);
                    else
                        enabledLabels.remove(str);
                    v.settingsChanged(false);
                }
            }
        });
        ret.add(box, c);
        c.gridy++;
    }

    return ret;
}

From source file:biomine.bmvis2.pipeline.NodeLabelOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback v, VisualGraph graph) {
    JPanel ret = new JPanel();
    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;/*  ww  w.j a  v  a 2  s. co  m*/
    c.weighty = 0;
    c.gridy = 0;
    final Set<String> avail = graph.getAvailableNodeLabels();

    for (final String str : avail) {
        final JCheckBox box = new JCheckBox();
        box.setSelected(enabledLabels.contains(str));
        box.setAction(new AbstractAction(str) {
            public void actionPerformed(ActionEvent arg0) {
                if (box.isSelected() != enabledLabels.contains(str)) {
                    if (box.isSelected())
                        enabledLabels.add(str);
                    else
                        enabledLabels.remove(str);
                    v.settingsChanged(false);
                }
            }
        });
        ret.add(box, c);
        c.gridy++;
    }

    return ret;
}

From source file:biomine.bmvis2.pipeline.BestPathHiderOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback settingsChangeCallback,
        final VisualGraph graph) {
    long nodeCount = graph.getAllNodes().size();

    if (oldCount != 0) {
        long newTarget = (target * nodeCount) / oldCount;
        this.target = Math.max(newTarget, target);
    } else/*from  w  w  w.j av  a  2 s . co m*/
        this.target = nodeCount;

    this.oldCount = nodeCount;

    JPanel ret = new JPanel();

    // if int overflows, we're fucked
    final JSlider sl = new JSlider(0, (int) nodeCount, (int) Math.min(target, nodeCount));
    sl.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            if (target == sl.getValue())
                return;
            target = sl.getValue();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = 0;
    //c.gridwidth=2;

    ret.add(sl, c);
    c.gridy++;

    int choices = graph.getNodesOfInterest().size() + 1;

    Object[] items = new Object[choices];
    items[0] = "All PoIs";

    for (int i = 1; i < choices; i++) {
        items[i] = i + " nearest";
    }
    final JComboBox pathTypeBox = new JComboBox(items);
    pathTypeBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            int i = pathTypeBox.getSelectedIndex();
            grader.setPathK(i);
            settingsChangeCallback.settingsChanged(false);
        }
    });

    ret.add(new JLabel("hide by best path quality to:"), c);
    c.gridy++;
    ret.add(pathTypeBox, c);
    c.gridy++;

    System.out.println("new confpane nodeCount = " + nodeCount);

    final JCheckBox useMatchingColoring = new JCheckBox();
    ret.add(useMatchingColoring, c);

    useMatchingColoring.setAction(new AbstractAction("Use matching coloring") {
        public void actionPerformed(ActionEvent arg0) {
            matchColoring = useMatchingColoring.isSelected();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    useMatchingColoring.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    c.gridy++;

    final JCheckBox labelsBox = new JCheckBox();
    ret.add(labelsBox, c);

    labelsBox.setAction(new AbstractAction("Show goodness in node labels") {
        public void actionPerformed(ActionEvent arg0) {
            showLabel = labelsBox.isSelected();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    return ret;
}

From source file:pl.otros.logview.gui.LogViewMainFrame.java

private void initExperimental() {
    JMenu menu = new JMenu("Experimental");
    menu.add(new JLabel("Experimental features, can have bugs", Icons.LEVEL_WARNING, SwingConstants.LEADING));
    menu.add(new JSeparator());
    boolean storeOnDisk = StringUtils.equalsIgnoreCase(System.getProperty("cacheEvents"), "true");
    JRadioButtonMenuItem radioButtonMemory = new JRadioButtonMenuItem("Memory - faster, more memory required",
            !storeOnDisk);//from  w  w w . j a  v a  2  s.c om
    radioButtonMemory.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.setProperty("cacheEvents", Boolean.FALSE.toString());
        }
    });
    JRadioButtonMenuItem radioButtonDisk = new JRadioButtonMenuItem(
            "Disk with caching - slower, less memory required", storeOnDisk);
    radioButtonDisk.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.setProperty("cacheEvents", Boolean.TRUE.toString());
        }
    });
    final ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(radioButtonDisk);
    buttonGroup.add(radioButtonMemory);
    menu.add(new JSeparator(JSeparator.VERTICAL));
    menu.add(new JLabel("Keep parsed log events store:"));
    menu.add(radioButtonMemory);
    menu.add(radioButtonDisk);
    final JCheckBox soapFormatterRemoveMultirefsCbx = new JCheckBox();
    soapFormatterRemoveMultirefsCbx
            .setSelected(configuration.getBoolean(ConfKeys.FORMATTER_SOAP_REMOVE_MULTIREFS, false));
    AbstractAction enableMultiRefRemoveFeature = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SoapMessageFormatter soapMessageFormatter = (SoapMessageFormatter) AllPluginables.getInstance()
                    .getMessageFormatters().getElement(SoapMessageFormatter.class.getName());
            soapMessageFormatter.setRemoveMultiRefs(soapFormatterRemoveMultirefsCbx.isSelected());
            configuration.setProperty(ConfKeys.FORMATTER_SOAP_REMOVE_MULTIREFS,
                    soapFormatterRemoveMultirefsCbx.isSelected());
        }
    };
    enableMultiRefRemoveFeature.putValue(Action.NAME, "Remove mulitRefs from SOAP messages");
    soapFormatterRemoveMultirefsCbx.setAction(enableMultiRefRemoveFeature);
    enableMultiRefRemoveFeature.actionPerformed(null);
    final JCheckBox soapFormatterRemoveXsiForNilElementsCbx = new JCheckBox();
    soapFormatterRemoveXsiForNilElementsCbx
            .setSelected(configuration.getBoolean(FORMATTER_SOAP_REMOVE_XSI_FOR_NIL, false));
    AbstractAction soapFormatterRemoveXsiFromNilAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SoapMessageFormatter soapMessageFormatter = (SoapMessageFormatter) AllPluginables.getInstance()
                    .getMessageFormatters().getElement(SoapMessageFormatter.class.getName());
            soapMessageFormatter
                    .setRemoveXsiForNilElements(soapFormatterRemoveXsiForNilElementsCbx.isSelected());
            configuration.setProperty(FORMATTER_SOAP_REMOVE_XSI_FOR_NIL,
                    soapFormatterRemoveXsiForNilElementsCbx.isSelected());
        }
    };
    soapFormatterRemoveXsiFromNilAction.putValue(Action.NAME,
            "Remove xsi for for NIL elements from SOAP messages");
    soapFormatterRemoveXsiForNilElementsCbx.setAction(soapFormatterRemoveXsiFromNilAction);
    soapFormatterRemoveXsiFromNilAction.actionPerformed(null);
    menu.add(soapFormatterRemoveMultirefsCbx);
    menu.add(soapFormatterRemoveXsiForNilElementsCbx);
    getJMenuBar().add(menu);
    QueryFilter queryFilter = new QueryFilter();
    allPluginables.getLogFiltersContainer().addElement(queryFilter);
    JButton b = new JButton("Throw exception");
    b.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (System.currentTimeMillis() % 2 == 0) {
                throw new RuntimeException("Exception swing action!");
            } else {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        throw new RuntimeException("Exception from tread!");
                    }
                }).start();
            }
        }
    });
    menu.add(b);
}

From source file:uk.nhs.cfh.dsp.yasb.searchpanel.SearchPanel.java

/**
 * Creates the control panel./*from   w w w .ja va 2s. 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);
}