Example usage for javax.swing JCheckBoxMenuItem setAction

List of usage examples for javax.swing JCheckBoxMenuItem setAction

Introduction

In this page you can find the example usage for javax.swing JCheckBoxMenuItem 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:Main.java

/**
 * Creates a sub-menu for changing Look'n'Feel.
 * @param rootComponent the root component which Look'n'Feel should be changed (child component are processed recursively).
 * @return a menu item with sub-menu items for each Look'n'Feel
 * installed in the system with associated actions to change the
 * Look'n'Feel for the <code>rootComponent</root>.
 *//*from  www.ja v  a  2  s .  com*/
public static JMenu getLafMenu(final Component rootComponent) {
    JMenu jMenu = new JMenu("Look & Feel");
    ButtonGroup buttonGroup = new ButtonGroup();
    final UIManager.LookAndFeelInfo[] installedLFs = UIManager.getInstalledLookAndFeels();
    String currentLF = UIManager.getLookAndFeel().getName();
    for (int i = 0; i < installedLFs.length; i++) {
        JCheckBoxMenuItem jMenuItem = new JCheckBoxMenuItem(installedLFs[i].getName());
        jMenu.add(jMenuItem);
        buttonGroup.add(jMenuItem);
        jMenuItem.setState(currentLF.equals(installedLFs[i].getName()));
        class ChangeLF extends AbstractAction {
            private UIManager.LookAndFeelInfo iLF;

            public ChangeLF(UIManager.LookAndFeelInfo iLF) {
                super(iLF.getName());
                this.iLF = iLF;
            }

            public void actionPerformed(ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(iLF.getClassName());
                    SwingUtilities.updateComponentTreeUI(rootComponent);
                } catch (Exception ex) {
                    System.out.print("Could not set look and feel: " + ex.toString());
                }
            }
        }
        jMenuItem.setAction(new ChangeLF(installedLFs[i]));
    }
    return jMenu;
}

From source file:it.unibas.spicygui.widget.operators.ConnectionInfoCreator.java

public void createConfidenceLabel(JMenuItem itemConfidence, JCheckBoxMenuItem itemCheckImplied,
        BindingGroup bindingGroup, ConnectionInfo connectionInfo, ConnectionWidget connection) {
    // binding/*from  w  w  w.j a v a2 s  .co m*/
    Binding bindingImplied = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ,
            connectionInfo.getValueCorrespondence(), ELProperty.create("${implied}"), itemCheckImplied,
            BeanProperty.create("selected"));
    Binding bindingConfidence = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, connectionInfo,
            ELProperty.create("${confidence}"), itemConfidence, BeanProperty.create("text"));
    bindingGroup.addBinding(bindingConfidence);
    bindingGroup.addBinding(bindingImplied);
    //action
    itemCheckImplied.setAction(new ActionSetImplied(connectionInfo));
    itemConfidence.setAction(new MyEditProviderConfidence(connection, connectionInfo));
}

From source file:ffx.ui.MainMenu.java

private JCheckBoxMenuItem addCBMenuItem(JMenu menu, String icon, String actionCommand, int mnemonic,
        int accelerator, final ActionListener actionListener) {

    final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem();

    Action a = new AbstractAction() {
        @Override/*from w  w w . j a va2  s .  co m*/
        public void actionPerformed(ActionEvent e) {
            /**
             * If the ActionEvent is from a ToolBar button, pass it through
             * the JCheckBoxMenuItem.
             */
            if (e.getSource() != menuItem) {
                menuItem.doClick();
                return;
            }
            actionListener.actionPerformed(e);
        }
    };
    configureAction(a, icon, actionCommand, mnemonic, accelerator);
    menuItem.setAction(a);
    menu.add(menuItem);
    return menuItem;
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/**
 * Helper method to create the Zoom menu. 
 * /*from  w  w  w. j a va2  s  .c  o  m*/
 * @param pref  The user preferences.
 * @param full  Pass <code>true</code> to create a full menu, 
 *             <code>false</code> to create a partial menu.
 * @return See above.
 */
private JMenu createZoomMenu(ViewerPreferences pref, boolean full) {
    ViewerAction action;
    JCheckBoxMenuItem item;
    if (model.isBigImage()) {
        action = controller.getAction(ImViewerControl.ZOOM_100);
        item = new JCheckBoxMenuItem();
        item.setAction(action);
        zoomMenu.add(item);
        action = controller.getAction(ImViewerControl.ZOOM_125);
        item = new JCheckBoxMenuItem();
        item.setAction(action);
        zoomMenu.add(item);
        action = controller.getAction(ImViewerControl.ZOOM_150);
        item = new JCheckBoxMenuItem();
        item.setAction(action);
        zoomMenu.add(item);
        action = controller.getAction(ImViewerControl.ZOOM_175);
        item = new JCheckBoxMenuItem();
        item.setAction(action);
        zoomMenu.add(item);
        return zoomMenu;
    }
    action = controller.getAction(ImViewerControl.ZOOM_25);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_50);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_75);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_100);
    item = new JCheckBoxMenuItem();
    item.setAction(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    //if (full) {
    action = controller.getAction(ImViewerControl.ZOOM_125);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_150);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_175);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_200);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_225);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_250);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_275);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    action = controller.getAction(ImViewerControl.ZOOM_300);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    //}

    action = controller.getAction(ImViewerControl.ZOOM_FIT_TO_WINDOW);
    item = new JCheckBoxMenuItem(action);
    zoomMenu.add(item);
    zoomingGroup.add(item);
    int index = ZoomAction.DEFAULT_ZOOM_INDEX;
    double factor = ZoomAction.DEFAULT_ZOOM_FACTOR;
    if (pref != null) {
        if (pref.isFieldSelected(ViewerPreferences.ZOOM_FACTOR)) {
            index = pref.getZoomIndex();
            factor = ZoomAction.getZoomFactor(index);
        }
    }
    setZoomFactor(factor, index);

    item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.ZOOM_GRID_25));
    zoomGridMenu.add(item);
    zoomingGridGroup.add(item);
    item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.ZOOM_GRID_50));
    zoomGridMenu.add(item);
    zoomingGridGroup.add(item);
    item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.ZOOM_GRID_75));
    zoomGridMenu.add(item);
    zoomingGridGroup.add(item);
    item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.ZOOM_GRID_100));
    zoomGridMenu.add(item);
    zoomingGridGroup.add(item);
    setGridMagnificationFactor(ZoomGridAction.DEFAULT_ZOOM_FACTOR);
    return zoomMenu;
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/**
 * Updates UI components when a zooming factor is selected.
 * /*from  w w w .  j  a va  2 s.com*/
 * @param factor   The magnification factor.
 * @param zoomIndex The index of the selected zoomFactor.
 */
void setZoomFactor(double factor, int zoomIndex) {
    setMagnificationStatus(factor, zoomIndex);
    JCheckBoxMenuItem b;
    Enumeration e;
    Action a;
    if (zoomingGroup == null)
        return;
    for (e = zoomingGroup.getElements(); e.hasMoreElements();) {
        b = (JCheckBoxMenuItem) e.nextElement();
        a = b.getAction();
        if (a instanceof ZoomAction) {
            b.removeActionListener(a);
            b.setSelected(((ZoomAction) a).getIndex() == zoomIndex);
            b.setAction(a);
        }
    }
    controlPane.setZoomFactor(zoomIndex);
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/** 
 * Sets the magnification for the grid view.
 * // www  . j  a  v a 2  s  .c o  m
 * @param factor The value to set.
 */
void setGridMagnificationFactor(double factor) {
    if (model.getTabbedIndex() == ImViewer.GRID_INDEX)
        setMagnificationStatus(factor, ZoomAction.getIndex(factor));
    JCheckBoxMenuItem b;
    Enumeration e;
    Action a;
    int zoomIndex = ZoomGridAction.getIndex(factor);
    for (e = zoomingGridGroup.getElements(); e.hasMoreElements();) {
        b = (JCheckBoxMenuItem) e.nextElement();
        a = b.getAction();
        if (a instanceof ZoomGridAction) {
            b.removeActionListener(a);
            b.setSelected(((ZoomGridAction) a).getIndex() == zoomIndex);
            b.setAction(a);
        }
    }
    controlPane.setGridMagnificationFactor((int) (factor * 10));
}