Example usage for javax.swing JMenuItem setVisible

List of usage examples for javax.swing JMenuItem setVisible

Introduction

In this page you can find the example usage for javax.swing JMenuItem 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:com.projity.menu.MenuManager.java

public void setActionVisible(String id, boolean enable) {
    Collection buttons = toolBarFactory.getButtonsFromId(id);
    if (buttons != null) {
        Iterator i = buttons.iterator();
        while (i.hasNext()) {
            AbstractButton button = (AbstractButton) i.next();
            if (button != null)
                button.setVisible(enable);
        }//from   w  ww. ja  v  a2  s  . co  m
    }
    JMenuItem menuItem = menuFactory.getMenuItemFromId(id);
    if (menuItem != null)
        menuItem.setVisible(enable);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopPopupButton.java

protected void initAction(final Action action, final JMenuItem menuItem) {
    if (initializedActions.contains(action))
        return;//from   w w  w .j  a  va 2 s . c o  m

    action.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (Action.PROP_CAPTION.equals(evt.getPropertyName())) {
                menuItem.setText(action.getCaption());
            } else if (Action.PROP_ENABLED.equals(evt.getPropertyName())) {
                menuItem.setEnabled(action.isEnabled());
            } else if (Action.PROP_VISIBLE.equals(evt.getPropertyName())) {
                menuItem.setVisible(action.isVisible());
            }
        }
    });

    initializedActions.add(action);
}

From source file:edu.ku.brc.specify.tasks.SystemSetupTask.java

public List<MenuItemDesc> getMenuItems() {
    final String COLSETUP_MENU = "Specify.COLSETUP_MENU";
    final String TREES_MENU = "Specify.TREES_MENU";
    final String SYSTEM_MENU = "Specify.SYSTEM_MENU";
    final String FULL_SYSTEM_MENU = SYSTEM_MENU + "/" + COLSETUP_MENU;
    final String FULL_TREE_MENU = SYSTEM_MENU + "/" + TREES_MENU;
    SecurityMgr secMgr = SecurityMgr.getInstance();

    menuItems = new Vector<MenuItemDesc>();

    MenuItemDesc mid;//from w ww. ja  v a 2 s. c o m
    String titleArg;
    String mneu;
    JMenuItem mi;

    String menuDesc = getResourceString(TREES_MENU);

    JMenu formsMenu = UIHelper.createLocalizedMenu("Specify.FORMS_MENU", "Specify.FORMS_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$
    mid = new MenuItemDesc(formsMenu, SYSTEM_MENU);
    mid.setPosition(MenuItemDesc.Position.Top, menuDesc);
    mid.setSepPosition(MenuItemDesc.Position.After);
    menuItems.add(mid);

    JMenu treesMenu = UIHelper.createLocalizedMenu("Specify.TREES_MENU", "Specify.TREES_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$
    mid = new MenuItemDesc(treesMenu, SYSTEM_MENU);
    mid.setPosition(MenuItemDesc.Position.Top, menuDesc);
    menuItems.add(mid);

    JMenu setupMenu = UIHelper.createLocalizedMenu("Specify.COLSETUP_MENU", "Specify.COLSETUP_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$
    mid = new MenuItemDesc(setupMenu, SYSTEM_MENU);
    mid.setPosition(MenuItemDesc.Position.Top, menuDesc);
    menuItems.add(mid);

    if (!AppContextMgr.isSecurityOn() || (getPermissions() != null && getPermissions().canAdd())) {
        titleArg = getI18NKey("COLL_CONFIG");
        mneu = getI18NKey("COLL_CONFIG_MNEU");
        mi = UIHelper.createLocalizedMenuItem(titleArg, mneu, titleArg, true, null);
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                SystemSetupTask.this.requestContext();
            }
        });
        mid = new MenuItemDesc(mi, FULL_SYSTEM_MENU);
        mid.setPosition(MenuItemDesc.Position.Top, FULL_SYSTEM_MENU);
        menuItems.add(mid);
    }

    if (!AppContextMgr.isSecurityOn() || SpecifyUser.isCurrentUserType(UserType.Manager)) {
        Vector<BaseTreeTask<?, ?, ?>> trees = new Vector<BaseTreeTask<?, ?, ?>>(
                TreeTaskMgr.getInstance().getTreeTasks());
        Collections.sort(trees, new Comparator<BaseTreeTask<?, ?, ?>>() {
            @Override
            public int compare(BaseTreeTask<?, ?, ?> arg0, BaseTreeTask<?, ?, ?> arg1) {
                return arg0.getTitle().compareTo(arg1.getTitle());
            }
        });

        for (final BaseTreeTask<?, ?, ?> tree : trees) {
            titleArg = getResourceString(getI18NKey("Tree_MENU")) + " " + tree.getTitle(); //$NON-NLS-1$
            mneu = getI18NKey("Trees_MNU"); //$NON-NLS-1$
            mi = UIHelper.createMenuItemWithAction((JMenu) null, titleArg, mneu, titleArg, true, null);
            mi.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            doTreeUpdate(tree);
                        }
                    });
                }
            });
            mi.setVisible(tree.isTreeOnByDefault());
            treeUpdateMenuItems.add(new Pair<BaseTreeTask<?, ?, ?>, JMenuItem>(tree, mi));
            mid = new MenuItemDesc(mi, FULL_TREE_MENU);
            mid.setPosition(MenuItemDesc.Position.After, menuDesc);

            menuItems.add(mid);
        }
    }

    String securityName = buildTaskPermissionName(RESIMPORTEXPORT_SECURITY);
    if (!AppContextMgr.isSecurityOn() || (secMgr.getPermission(securityName) != null
            && !secMgr.getPermission(securityName).hasNoPerm())) {
        titleArg = getI18NKey("RIE_MENU"); //$NON-NLS-1$
        mneu = getI18NKey("RIE_MNU"); //$NON-NLS-1$
        mi = UIHelper.createLocalizedMenuItem(titleArg, mneu, titleArg, true, null);
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                doResourceImportExport();
            }
        });
        mid = new MenuItemDesc(mi, SYSTEM_MENU);
        mid.setPosition(MenuItemDesc.Position.Bottom, menuDesc);
        mid.setSepPosition(MenuItemDesc.Position.After);
        menuItems.add(mid);
    }

    securityName = buildTaskPermissionName(SCHEMACONFIG_SECURITY);
    if (!AppContextMgr.isSecurityOn()
            || (secMgr.getPermission(securityName) != null && secMgr.getPermission(securityName).canView())) {
        titleArg = getI18NKey("SCHEMA_CONFIG_MENU"); //$NON-NLS-1$
        mneu = getI18NKey("SCHEMA_CONFIG_MNU"); //$NON-NLS-1$
        mi = UIHelper.createLocalizedMenuItem(titleArg, mneu, titleArg, true, null);
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                doSchemaConfig(SpLocaleContainer.CORE_SCHEMA, DBTableIdMgr.getInstance());
            }
        });
        mid = new MenuItemDesc(mi, SYSTEM_MENU);
        mid.setPosition(MenuItemDesc.Position.Bottom);
        menuItems.add(mid);

        AppPreferences localPrefs = AppPreferences.getLocalPrefs();
        if (localPrefs.getBoolean("QCBX_EDITOR", false)) {
            menuDesc = getResourceString(titleArg);
            titleArg = getI18NKey("QCBXEDITOR_MENU");
            mneu = getI18NKey("QCBXEDITOR_MNEU");
            mi = UIHelper.createLocalizedMenuItem(titleArg, mneu, titleArg, true, null);
            mi.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    TypeSearchForQueryFactory.getInstance().save();

                    QueryComboboxEditor tse = new QueryComboboxEditor();
                    UIHelper.centerAndShow(tse);
                }
            });
            mid = new MenuItemDesc(mi, SYSTEM_MENU);
            mid.setPosition(MenuItemDesc.Position.Bottom);
            menuItems.add(mid);
        }
    }

    if (!AppContextMgr.isSecurityOn() || (secMgr.getPermission(WBSCHEMACONFIG_SECURITY) != null
            && secMgr.getPermission(WBSCHEMACONFIG_SECURITY).canAdd())) {
        titleArg = getI18NKey("WBSCHEMA_CONFIG_MENU"); //$NON-NLS-1$
        mneu = getI18NKey("WBSCHEMA_CONFIG_MNU"); //$NON-NLS-1$
        mi = UIHelper.createLocalizedMenuItem(titleArg, mneu, titleArg, true, null);
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                doWorkBenchSchemaConfig();
            }
        });
        mid = new MenuItemDesc(mi, SYSTEM_MENU);
        mid.setPosition(MenuItemDesc.Position.Bottom, menuDesc);
        menuItems.add(mid);
    }

    return menuItems;
}

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);
        }//  w  ww  .j ava  2 s . c  om
    };

    // 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();/* w ww. j  a  v  a2  s  . c  o m*/
        }
    });
    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() {
    });
}

From source file:processing.app.Base.java

private void filterVisibilityOfSubsequentBoardMenus(List<JMenu> boardsCustomMenus, TargetBoard board,
        int fromIndex) {
    for (int i = fromIndex; i < boardsCustomMenus.size(); i++) {
        JMenu menu = boardsCustomMenus.get(i);
        for (int m = 0; m < menu.getItemCount(); m++) {
            JMenuItem menuItem = menu.getItem(m);
            menuItem.setVisible(menuItem.getAction().getValue("board").equals(board));
        }/*from   www  . j a v a  2s.c  o  m*/
        menu.setVisible(ifThereAreVisibleItemsOn(menu));

        if (menu.isVisible()) {
            JMenuItem visibleSelectedOrFirstMenuItem = selectVisibleSelectedOrFirstMenuItem(menu);
            if (!visibleSelectedOrFirstMenuItem.isSelected()) {
                visibleSelectedOrFirstMenuItem.setSelected(true);
                visibleSelectedOrFirstMenuItem.getAction().actionPerformed(null);
            }
        }
    }
}