Example usage for javax.swing JCheckBoxMenuItem setVisible

List of usage examples for javax.swing JCheckBoxMenuItem setVisible

Introduction

In this page you can find the example usage for javax.swing JCheckBoxMenuItem setVisible.

Prototype

@BeanProperty(hidden = true, visualUpdate = true)
public void setVisible(boolean aFlag) 

Source Link

Document

Makes the component visible or invisible.

Usage

From source file:ee.ioc.cs.vsle.editor.Editor.java

/**
 * Build menu./*from   w w  w .  j a v a2  s.  c  o m*/
 */
public void makeMenu() {
    JMenuItem menuItem;

    JMenu menu;
    JMenu submenu;

    menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    menu = new JMenu(Menu.MENU_FILE);
    menu.setMnemonic(KeyEvent.VK_F);
    menuItem = new JMenuItem(Menu.NEW_SCHEME, KeyEvent.VK_N);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.LOAD_SCHEME, KeyEvent.VK_O);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.RELOAD_SCHEME, KeyEvent.VK_R);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.SAVE_SCHEME, KeyEvent.VK_S);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.SAVE_SCHEME_AS);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.DELETE_SCHEME, KeyEvent.VK_D);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    submenu = new JMenu(Menu.EXPORT_MENU);
    menu.add(submenu);
    //submenu.setMnemonic( KeyEvent.VK_E );

    SchemeExporter.makeSchemeExportMenu(submenu, getActionListener());

    // Export window graphics
    submenu.add(GraphicsExporter.getExportMenu());

    menu.addSeparator();
    menuItem = new JMenuItem(Menu.PRINT, KeyEvent.VK_P);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menu.addSeparator();
    menuItem = new JMenuItem(Menu.EXIT, KeyEvent.VK_X);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuBar.add(menu);
    menu = new JMenu(Menu.MENU_EDIT);
    menu.setMnemonic(KeyEvent.VK_E);

    menu.add(undoAction);
    menu.add(redoAction);
    menu.add(cloneAction);

    menuItem = new JMenuItem(Menu.SCHEME_FIND, KeyEvent.VK_F);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.SELECT_ALL, KeyEvent.VK_A);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.CLEAR_ALL, KeyEvent.VK_C);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    final JCheckBoxMenuItem painterEnabled = new JCheckBoxMenuItem(Menu.CLASSPAINTER, true);
    painterEnabled.addActionListener(getActionListener());
    menu.add(painterEnabled);

    menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            Canvas canvas = Editor.getInstance().getCurrentCanvas();
            if (canvas == null || !canvas.getPackage().hasPainters()) {
                painterEnabled.setVisible(false);
            } else {
                painterEnabled.setVisible(true);
                painterEnabled.setSelected(canvas.isEnableClassPainter());
            }
        }

    });

    menuBar.add(menu);

    menu = new JMenu(Menu.MENU_VIEW);
    menu.setMnemonic(KeyEvent.VK_V);
    gridCheckBox = new JCheckBoxMenuItem(Menu.GRID, RuntimeProperties.isShowGrid());
    gridCheckBox.setMnemonic('G');
    gridCheckBox.addActionListener(getActionListener());
    menu.add(gridCheckBox);

    ctrlCheckBox = new JCheckBoxMenuItem(Menu.CONTROL_PANEL, RuntimeProperties.isShowControls());
    ctrlCheckBox.setMnemonic('C');
    ctrlCheckBox.addActionListener(getActionListener());
    menu.add(ctrlCheckBox);

    showPortCheckBox = new JCheckBoxMenuItem(Menu.SHOW_PORTS, true);
    showPortCheckBox.addActionListener(getActionListener());
    menu.add(showPortCheckBox);

    showObjectNamesCheckBox = new JCheckBoxMenuItem(Menu.SHOW_NAMES, false);
    showObjectNamesCheckBox.addActionListener(getActionListener());
    menu.add(showObjectNamesCheckBox);

    //sync View with current canvas
    menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            Canvas canvas;

            if ((canvas = getCurrentCanvas()) == null)
                return;

            gridCheckBox.setSelected(canvas.isGridVisible());
            ctrlCheckBox.setSelected(canvas.isCtrlPanelVisible());
            showPortCheckBox.setSelected(canvas.isDrawPorts());
            showObjectNamesCheckBox.setSelected(canvas.isShowObjectNames());
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

    });

    menuBar.add(menu);

    menu = new JMenu(Menu.MENU_PACKAGE);
    menu.setMnemonic(KeyEvent.VK_P);
    menuItem = new JMenuItem(Menu.LOAD, KeyEvent.VK_L);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.RELOAD, KeyEvent.VK_R);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.INFO, KeyEvent.VK_I);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    if (Desktop.isDesktopSupported()) {
        menuItem = new JMenuItem(Menu.BROWSE_PACKAGE, KeyEvent.VK_B);
        menuItem.addActionListener(getActionListener());
        menu.add(menuItem);
    }
    menuItem = new JMenuItem(Menu.CLOSE, KeyEvent.VK_C);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuItem = new JMenuItem(Menu.CLOSE_ALL);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
    menuBar.add(menu);
    menu.add(new JSeparator());
    final JMenu submenuRecent = new JMenu(Menu.RECENT);
    submenuRecent.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        final JMenuItem empty = new JMenuItem("Empty");

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {

            makeRecentSubMenu(submenuRecent);

            if (submenuRecent.getMenuComponentCount() == 0) {

                submenuRecent.add(empty);
                empty.setEnabled(false);

            } else {
                if (!((submenuRecent.getMenuComponentCount() == 1)
                        && (submenuRecent.getPopupMenu().getComponentIndex(empty) >= -1))) {
                    submenuRecent.remove(empty);
                }
            }

        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

    });
    menu.add(submenuRecent);
    final JMenu menuScheme = new JMenu(Menu.MENU_SCHEME);
    menuScheme.setMnemonic(KeyEvent.VK_S);
    makeSchemeMenu(menuScheme);

    menuScheme.getPopupMenu().addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {

            makeSchemeMenu(menuScheme);

        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // ignore
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // ignore
        }

    });

    /*
     * menuItem = new JMenuItem("Planner");
     * menuItem.addActionListener(aListener); menuScheme.add(menuItem);
     * menuItem = new JMenuItem("Plan, compile, run");
     * menuItem.setActionCommand("Run");
     * menuItem.addActionListener(aListener); menuScheme.add(menuItem);
     */
    // menuScheme.setMnemonic(KeyEvent.VK_A);
    menuBar.add(menuScheme);
    menu = new JMenu(Menu.MENU_OPTIONS);
    menu.setMnemonic(KeyEvent.VK_O);

    menuItem = new JMenuItem(Menu.SETTINGS, KeyEvent.VK_S);
    menuItem.addActionListener(getActionListener());
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK));
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.FONTS);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    menuItem = new JMenuItem(Menu.SAVE_SETTINGS);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);

    submenu = new JMenu(Menu.MENU_LAF);
    submenu.setMnemonic(KeyEvent.VK_L);
    Look.getInstance().createMenuItems(submenu);
    menu.add(submenu);
    menuBar.add(menu);

    makeToolsMenu(menuBar);

    menu = new JMenu(Menu.MENU_HELP);
    menu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(menu);
    menuItem = new JMenuItem(Menu.DOCS, KeyEvent.VK_D);
    menuItem.addActionListener(getActionListener());
    menu.add(menuItem);
}

From source file:org.rdv.viz.image.HighResImageViz.java

public void buildPopupMenu(JPopupMenu menu, MouseEvent e) {
    super.buildPopupMenu(menu, e);

    ActionListener setTimerangeAction = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            double newScale = Double.parseDouble(ae.getActionCommand());
            setLocalTimescale(newScale);
        }/*from w  w  w  .  j a v a  2  s.  c  o m*/
    };

    // regenerate new menu
    JMenu timeRangeMenu = new JMenu("Set Timerange");
    ButtonGroup timeRangeGroup = new ButtonGroup();
    JRadioButtonMenuItem range = new JRadioButtonMenuItem(TimeScale.TIME_SCALE_UNDEFINED_DESC);
    range.setActionCommand(String.valueOf(TimeScale.TIME_SCALE_UNDEFINED));
    range.addActionListener(setTimerangeAction);
    timeRangeGroup.add(range);
    timeRangeMenu.add(range);
    if (localTimeScale_ == TimeScale.TIME_SCALE_UNDEFINED)
        range.setSelected(true);

    Double timeScales[] = TimeScale.getGlobalTimeScales();
    for (int i = 0; i < timeScales.length; i++) {
        range = new JRadioButtonMenuItem(DataViewer.formatSeconds(timeScales[i]));
        range.setActionCommand(String.valueOf(timeScales[i]));
        range.addActionListener(setTimerangeAction);
        timeRangeGroup.add(range);
        timeRangeMenu.add(range);
        if (localTimeScale_ == timeScales[i])
            range.setSelected(true);
    }

    menu.add(timeRangeMenu);
    menu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem copyImageMenuItem = new JMenuItem("Copy");
    copyImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            copyImage();
        }
    });
    menu.add(copyImageMenuItem);
    menu.addSeparator();

    // create a popup to save an image
    final JMenuItem saveImageMenuItem = new JMenuItem("Save as...");
    saveImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveImage();
        }
    });
    menu.add(saveImageMenuItem);

    menu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem printImageMenuItem = new JMenuItem("Print...");
    printImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            printImage();
        }
    });
    menu.add(printImageMenuItem);

    menu.addSeparator();

    final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in");
    zoomInMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomIn();
        }
    });
    menu.add(zoomInMenuItem);

    final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out");
    zoomOutMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomOut();
        }
    });
    menu.add(zoomOutMenuItem);

    final JSeparator zoomMenuSeparator = new JPopupMenu.Separator();
    menu.add(zoomMenuSeparator);

    final JCheckBoxMenuItem autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", imagePanel.isAutoScaling());
    autoScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setAutoScale(autoScaleMenuItem.isSelected());
        }
    });
    menu.add(autoScaleMenuItem);

    final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale");
    resetScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            imagePanel.setScale(1);
        }
    });
    menu.add(resetScaleMenuItem);

    final JCheckBoxMenuItem showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image",
            imagePanel.isNavigationImageEnabled());
    showNavigationImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setShowNavigationImage(showNavigationImageMenuItem.isSelected());
        }
    });
    menu.add(showNavigationImageMenuItem);

    //menu.addSeparator();

    final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image",
            useThumbnailImage);
    useThumbnailImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setUseThumbnailImage(useThumbnailImageMenuItem.isSelected());
        }
    });
    menu.add(useThumbnailImageMenuItem);

    boolean hasImage = displayedImageData != null;
    saveImageMenuItem.setEnabled(hasImage);
    copyImageMenuItem.setEnabled(hasImage);
    printImageMenuItem.setEnabled(hasImage);

    boolean enableZoom = hasImage;
    zoomInMenuItem.setEnabled(enableZoom);
    zoomInMenuItem.setVisible(true);
    zoomOutMenuItem.setEnabled(enableZoom);
    zoomOutMenuItem.setVisible(true);
    zoomMenuSeparator.setVisible(true);

    autoScaleMenuItem.setVisible(true);
    resetScaleMenuItem.setVisible(true);
    showNavigationImageMenuItem.setVisible(true);

    useThumbnailImageMenuItem.setSelected(useThumbnailImage);
    useThumbnailImageMenuItem.setVisible(imageHasThumbnail());

}

From source file:org.rdv.viz.image.ImageViz.java

private void initPopupMenu() {
    final JPopupMenu popupMenu = new JPopupMenu();

    // create a popup to copy an image to the clipboard
    final JMenuItem copyImageMenuItem = new JMenuItem("Copy");
    copyImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            copyImage();/*  ww w  . j a  va2s  .  c  om*/
        }
    });
    popupMenu.add(copyImageMenuItem);

    popupMenu.addSeparator();

    // create a popup to save an image
    final JMenuItem saveImageMenuItem = new JMenuItem("Save as...");
    saveImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveImage();
        }
    });
    popupMenu.add(saveImageMenuItem);

    popupMenu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem printImageMenuItem = new JMenuItem("Print...");
    printImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            printImage();
        }
    });
    popupMenu.add(printImageMenuItem);

    popupMenu.addSeparator();

    final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in");
    zoomInMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomIn();
        }
    });
    popupMenu.add(zoomInMenuItem);

    final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out");
    zoomOutMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomOut();
        }
    });
    popupMenu.add(zoomOutMenuItem);

    final JSeparator zoomMenuSeparator = new JPopupMenu.Separator();
    popupMenu.add(zoomMenuSeparator);

    autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", true);
    autoScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setAutoScale(autoScaleMenuItem.isSelected());
        }
    });
    popupMenu.add(autoScaleMenuItem);

    final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale");
    resetScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            imagePanel.setScale(1);
        }
    });
    popupMenu.add(resetScaleMenuItem);

    showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image",
            imagePanel.isNavigationImageEnabled());
    showNavigationImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setShowNavigationImage(showNavigationImageMenuItem.isSelected());
        }
    });
    popupMenu.add(showNavigationImageMenuItem);

    final JMenu maximumFilmstripImagesMenu = new JMenu("Maximum number of images");
    maximumFilmstripImagesButtonGroup = new ButtonGroup();
    for (final int maximumFilmstripImagesValue : MAXIMUM_FILMSTRIP_IMAGES_VALUES) {
        boolean selected = filmstripPanel.getMaximumImages() == maximumFilmstripImagesValue;
        JMenuItem maximumFilmStripImagesMenuItem = new JRadioButtonMenuItem(
                Integer.toString(maximumFilmstripImagesValue), selected);
        maximumFilmStripImagesMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                filmstripPanel.setMaximumImages(maximumFilmstripImagesValue);
            }
        });
        maximumFilmstripImagesButtonGroup.add(maximumFilmStripImagesMenuItem);
        maximumFilmstripImagesMenu.add(maximumFilmStripImagesMenuItem);
    }
    popupMenu.add(maximumFilmstripImagesMenu);

    popupMenu.addSeparator();

    final JCheckBoxMenuItem showAsFilmstripMenuItem = new JCheckBoxMenuItem("Show as filmstrip", filmstripMode);
    showAsFilmstripMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            boolean filmstripMode = showAsFilmstripMenuItem.isSelected();
            setFilmstripMode(filmstripMode);
        }
    });
    popupMenu.add(showAsFilmstripMenuItem);

    final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image",
            useThumbnailImage);
    useThumbnailImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setUseThumbnailImage(useThumbnailImageMenuItem.isSelected());
        }
    });
    popupMenu.add(useThumbnailImageMenuItem);

    hideRoboticControlsMenuItem = new JCheckBoxMenuItem("Disable robotic controls", false);
    hideRoboticControlsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setRoboticControls();
        }
    });
    popupMenu.add(hideRoboticControlsMenuItem);

    // enable the save image popup if an image is being displayed
    popupMenu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
            boolean hasImage = displayedImageData != null;
            saveImageMenuItem.setEnabled(hasImage);
            copyImageMenuItem.setEnabled(hasImage);
            printImageMenuItem.setEnabled(hasImage);

            boolean enableZoom = hasImage && !filmstripMode;
            zoomInMenuItem.setEnabled(enableZoom);
            zoomInMenuItem.setVisible(!filmstripMode);
            zoomOutMenuItem.setEnabled(enableZoom);
            zoomOutMenuItem.setVisible(!filmstripMode);
            zoomMenuSeparator.setVisible(!filmstripMode);

            autoScaleMenuItem.setVisible(!filmstripMode);
            resetScaleMenuItem.setVisible(!filmstripMode);
            showNavigationImageMenuItem.setVisible(!filmstripMode);
            maximumFilmstripImagesMenu.setVisible(filmstripMode);

            showAsFilmstripMenuItem.setSelected(filmstripMode);

            useThumbnailImageMenuItem.setSelected(useThumbnailImage);
            useThumbnailImageMenuItem.setVisible(imageHasThumbnail());

            hideRoboticControlsMenuItem.setVisible(flexTPSStream != null);
        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }

        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }
    });

    // set component popup and mouselistener to trigger it
    panel.setComponentPopupMenu(popupMenu);
    imagePanel.setComponentPopupMenu(popupMenu);
    filmstripPanel.setComponentPopupMenu(popupMenu);
    panel.addMouseListener(new MouseInputAdapter() {
    });
}