Example usage for javax.swing JMenu setEnabled

List of usage examples for javax.swing JMenu setEnabled

Introduction

In this page you can find the example usage for javax.swing JMenu setEnabled.

Prototype

@BeanProperty(preferred = true, description = "The enabled state of the component.")
public void setEnabled(boolean b) 

Source Link

Document

Enables or disables the menu item.

Usage

From source file:de.tud.kom.p2psim.impl.skynet.visualization.SkyNetVisualization.java

private SkyNetVisualization() {
    super("Metric-Visualization");
    createLookAndFeel();/*from   w  w  w .jav  a  2  s.c  o  m*/
    displayedMetrics = new HashMap<String, MetricsPlot>();
    setLayout(new GridLayout(1, 1));
    addWindowListener(this);
    graphix = new JPanel(new GridBagLayout());
    graphix.setLayout(new BoxLayout(graphix, BoxLayout.PAGE_AXIS));
    mb = new JMenuBar();
    JScrollPane scroller = new JScrollPane(graphix, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // calculating the size of the application-window as well as of all
    // components, that depend on the size of the window
    Toolkit kit = Toolkit.getDefaultToolkit();
    int appWidth = kit.getScreenSize().width * 3 / 4;
    int appHeight = kit.getScreenSize().height * 3 / 4;
    scroller.setPreferredSize(new Dimension(appWidth, appHeight));
    getContentPane().add(scroller);
    maxPlotsPerRow = 1;
    while ((maxPlotsPerRow + 1) * PLOT_WIDTH < appWidth) {
        maxPlotsPerRow++;
    }
    log.warn("Creating the visualization...");
    mb.add(new JMenu("File"));
    JMenu met = new JMenu("Available Metrics");
    met.setEnabled(false);
    mb.add(met);
    setJMenuBar(mb);
}

From source file:de.tud.kom.p2psim.impl.skynet.visualization.SkyNetVisualization.java

public void setAvailableMetrics(Vector<String> names) {
    Vector<String> temp = new Vector<String>();
    temp.addAll(names);//  ww w  .j  ava  2 s. c o m
    temp.add("Online Peers");
    temp.add("Available Attributes");
    temp.add("Memory Usage");
    Collections.sort(temp);

    JMenu met = mb.getMenu(1);
    met.setEnabled(true);
    JMenu avgMet = new JMenu("Average Metrics");
    JMenu genMet = new JMenu("General Metrics");
    JMenu recMet = new JMenu("Metrics for Receiving");
    JMenu sentMet = new JMenu("Metrics for Sending");
    JCheckBoxMenuItem item = null;
    for (String name : temp) {
        if (name.startsWith("Aver")) {
            item = new JCheckBoxMenuItem(name, false);
            item.addActionListener(this);
            avgMet.add(item);
        } else if (name.startsWith("Rec")) {
            item = new JCheckBoxMenuItem(name, false);
            item.addActionListener(this);
            recMet.add(item);
        } else if (name.startsWith("Sent")) {
            item = new JCheckBoxMenuItem(name, false);
            item.addActionListener(this);
            sentMet.add(item);
        } else {
            item = new JCheckBoxMenuItem(name, false);
            item.addActionListener(this);
            genMet.add(item);
        }
    }
    avgMet.add(new JSeparator(SwingConstants.HORIZONTAL));
    avgMet.add(createMenuItem("Display all Average Metrics"));
    avgMet.add(createMenuItem("Remove all Average Metrics"));

    genMet.add(new JSeparator(SwingConstants.HORIZONTAL));
    genMet.add(createMenuItem("Display all General Metrics"));
    genMet.add(createMenuItem("Remove all General Metrics"));

    recMet.add(new JSeparator(SwingConstants.HORIZONTAL));
    recMet.add(createMenuItem("Display all Metrics for Receiving"));
    recMet.add(createMenuItem("Remove all Metrics for Receiving"));

    sentMet.add(new JSeparator(SwingConstants.HORIZONTAL));
    sentMet.add(createMenuItem("Display all Metrics for Sending"));
    sentMet.add(createMenuItem("Remove all Metrics for Sending"));

    met.add(avgMet);
    met.add(genMet);
    met.add(recMet);
    met.add(sentMet);

    met.add(new JSeparator(SwingConstants.HORIZONTAL));
    met.add(createMenuItem("Display all Metrics"));
    met.add(createMenuItem("Remove all Metrics"));

    mb.add(met);
    repaint();
    log.warn("Created Menu 'Available Metrics'");
}

From source file:org.peerfact.impl.service.aggregation.skyeye.visualization.SkyNetVisualization.java

private SkyNetVisualization() {
    super("Metric-Visualization");
    createLookAndFeel();/*from  w ww  .  j  a  va 2s  .  co m*/
    displayedMetrics = new LinkedHashMap<String, MetricsPlot>();
    setLayout(new GridLayout(1, 1));
    addWindowListener(this);
    graphix = new JPanel(new GridBagLayout());
    graphix.setLayout(new BoxLayout(graphix, BoxLayout.PAGE_AXIS));
    mb = new JMenuBar();
    JScrollPane scroller = new JScrollPane(graphix, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // calculating the size of the application-window as well as of all
    // components, that depend on the size of the window
    Toolkit kit = Toolkit.getDefaultToolkit();
    int appWidth = kit.getScreenSize().width * 3 / 4;
    int appHeight = kit.getScreenSize().height * 3 / 4;
    scroller.setPreferredSize(new Dimension(appWidth, appHeight));
    getContentPane().add(scroller);
    maxPlotsPerRow = 1;
    while ((maxPlotsPerRow + 1) * PLOT_WIDTH < appWidth) {
        maxPlotsPerRow++;
    }
    log.warn("Creating the visualization...");
    mb.add(new JMenu("File"));
    JMenu met = new JMenu("Available Metrics");
    met.setEnabled(false);
    mb.add(met);
    setJMenuBar(mb);
}

From source file:au.org.ala.delta.editor.ui.image.ImageOverlayEditorController.java

public JPopupMenu buildPopupMenu() {
    disableActions();/*from  w  ww.  j  av a2  s . c  o m*/
    boolean itemImage = (_selection.getSelectedImage().getSubject() instanceof Item);
    List<String> popupMenuActions = new ArrayList<String>();
    if (_selection.getSelectedOverlay() != null) {
        popupMenuActions.add("editSelectedOverlay");
        popupMenuActions.add("deleteSelectedOverlay");
        popupMenuActions.add("-");
    }
    popupMenuActions.add("deleteAllOverlays");
    popupMenuActions.add("-");
    popupMenuActions.add("displayImageSettings");
    popupMenuActions.add("-");
    popupMenuActions.add("cancelPopup");

    JPopupMenu popup = new JPopupMenu();
    MenuBuilder.buildMenu(popup, popupMenuActions, _actions);

    if (_selection.getSelectedOverlay() != null) {
        List<String> stackOverlayMenuActions = new ArrayList<String>();
        stackOverlayMenuActions.add("stackSelectedOverlayHigher");
        stackOverlayMenuActions.add("stackSelectedOverlayLower");
        stackOverlayMenuActions.add("stackSelectedOverlayOnTop");
        stackOverlayMenuActions.add("stackSelectedOverlayOnBottom");
        JMenu stackOverlayMenu = new JMenu(_resources.getString("overlayPopup.stackOverlayMenu"));
        MenuBuilder.buildMenu(stackOverlayMenu, stackOverlayMenuActions, _actions);
        popup.add(stackOverlayMenu, 2);
    }
    List<String> insertOverlayMenuActions = new ArrayList<String>();
    insertOverlayMenuActions.add("addTextOverlay");
    if (itemImage) {
        insertOverlayMenuActions.add("addItemDescriptionOverlay");
    }
    insertOverlayMenuActions.add("-");
    if (!itemImage) {
        insertOverlayMenuActions.add("addAllUsualOverlays");
        insertOverlayMenuActions.add("addFeatureDescriptionOverlay");
        insertOverlayMenuActions.add("addStateOverlay");
        insertOverlayMenuActions.add("addHotspot");
        insertOverlayMenuActions.add("-");
    }
    insertOverlayMenuActions.add("addOkOverlay");
    insertOverlayMenuActions.add("addCancelOverlay");
    if (!itemImage) {
        insertOverlayMenuActions.add("addNotesOverlay");
    } else {
        insertOverlayMenuActions.add("addImageNotesOverlay");
    }

    JMenu insertOverlayMenu = new JMenu(_resources.getString("overlayPopup.insertOverlayMenu"));
    MenuBuilder.buildMenu(insertOverlayMenu, insertOverlayMenuActions, _actions);
    int indexModifier = _selection.getSelectedOverlay() == null ? 4 : 0;
    popup.add(insertOverlayMenu, 5 - indexModifier);

    List<String> alignButtonsMenuActions = new ArrayList<String>();
    alignButtonsMenuActions.add("useDefaultButtonAlignment");
    alignButtonsMenuActions.add("*alignButtonsVertically");
    alignButtonsMenuActions.add("*alignButtonsHorizontally");
    alignButtonsMenuActions.add("*dontAlignButtons");
    JMenu alignButtonsMenu = new JMenu(_resources.getString("overlayPopup.alignButtonsMenu"));
    alignButtonsMenu.setEnabled(getButtonOverlays().size() > 0);
    JMenuItem[] items = MenuBuilder.buildMenu(alignButtonsMenu, alignButtonsMenuActions, _actions);
    switch (_alignment) {
    case NO_ALIGN:
        items[3].setSelected(true);
        break;
    case ALIGN_HORIZONTALLY:
        items[2].setSelected(true);
        break;
    case ALIGN_VERTICALLY:
        items[1].setSelected(true);
        break;
    }

    popup.add(alignButtonsMenu, 7 - indexModifier);

    return popup;
}

From source file:net.sf.jabref.gui.RightClickMenu.java

/**
 * @param move For add: if true, remove from previous groups
 *//*from  w w w .j  av a  2s. c o  m*/
private void insertNodes(JMenu menu, GroupTreeNode node, BibEntry[] selection, boolean add, boolean move) {
    final AbstractAction action = getAction(node, selection, add, move);

    if (node.getChildCount() == 0) {
        JMenuItem menuItem = new JMenuItem(action);
        setGroupFontAndIcon(menuItem, node.getGroup());
        menu.add(menuItem);
        if (action.isEnabled()) {
            menu.setEnabled(true);
        }
        return;
    }

    JMenu submenu;
    if (node.getGroup() instanceof AllEntriesGroup) {
        for (int i = 0; i < node.getChildCount(); ++i) {
            insertNodes(menu, (GroupTreeNode) node.getChildAt(i), selection, add, move);
        }
    } else {
        submenu = new JMenu('[' + node.getGroup().getName() + ']');
        setGroupFontAndIcon(submenu, node.getGroup());
        // setEnabled(true) is done above/below if at least one menu
        // entry (item or submenu) is enabled
        submenu.setEnabled(action.isEnabled());
        JMenuItem menuItem = new JMenuItem(action);
        setGroupFontAndIcon(menuItem, node.getGroup());
        submenu.add(menuItem);
        submenu.add(new Separator());
        for (int i = 0; i < node.getChildCount(); ++i) {
            insertNodes(submenu, (GroupTreeNode) node.getChildAt(i), selection, add, move);
        }
        menu.add(submenu);
        if (submenu.isEnabled()) {
            menu.setEnabled(true);
        }
    }
}

From source file:com.frostwire.gui.library.LibraryDeviceTableMediator.java

private JMenu createSearchSubMenu(LibraryDeviceTableDataLine dl) {
    JMenu menu = new SkinMenu(I18n.tr("Search"));

    if (dl != null) {
        String str = buildQueryString(dl.getInitializeObject());
        String keywords = QueryUtils.createQueryString(str);
        if (keywords.length() > 0)
            menu.add(new SkinMenuItem(new SearchAction(keywords)));
    }//from   w  w w.j a v  a  2s.  c  o m

    if (menu.getItemCount() == 0)
        menu.setEnabled(false);

    return menu;
}

From source file:com.opendoorlogistics.studio.appframe.AppFrame.java

private void initMenus(ActionFactory actionBuilder, MenuFactory menuBuilder, List<? extends Action> fileActions,
        List<? extends Action> editActions) {
    final JMenuBar menuBar = new JMenuBar();
    class AddSpace {
        void add() {
            JMenu dummy = new JMenu();
            dummy.setEnabled(false);
            menuBar.add(dummy);/*w w  w .j  a  v  a2 s  .co  m*/
        }
    }
    AddSpace addSpace = new AddSpace();

    // add file menu ... build on the fly for recent files..
    setJMenuBar(menuBar);
    final JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    mnFile.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            initFileMenu(mnFile, fileActions, actionBuilder, menuBuilder);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void menuCanceled(MenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    initFileMenu(mnFile, fileActions, actionBuilder, menuBuilder);
    menuBar.add(mnFile);
    addSpace.add();

    // add edit menu
    JMenu mnEdit = new JMenu("Edit");
    mnEdit.setMnemonic('E');
    menuBar.add(mnEdit);
    addSpace.add();
    for (Action action : editActions) {
        mnEdit.add(action);
        //         if (action.accelerator != null) {
        //            item.setAccelerator(action.accelerator);
        //         }
    }

    // add run scripts menu (hidden until a datastore is loaded)
    mnScripts = new JMenu(appPermissions.isScriptEditingAllowed() ? "Run script" : "Run");
    mnScripts.setMnemonic('R');
    mnScripts.setVisible(false);
    mnScripts.addMenuListener(new MenuListener() {

        private void addScriptNode(JMenu parentMenu, boolean usePopupForChildren, ScriptNode node) {
            if (node.isAvailable() == false) {
                return;
            }
            if (node.isRunnable()) {
                parentMenu.add(new AbstractAction(node.getDisplayName(), node.getIcon()) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        postScriptExecution(node.getFile(), node.getLaunchExecutorId());
                    }
                });
            } else if (node.getChildCount() > 0) {
                JMenu newParent = parentMenu;
                if (usePopupForChildren) {
                    newParent = new JMenu(node.getDisplayName());
                    parentMenu.add(newParent);
                }
                ;
                for (int i = 0; i < node.getChildCount(); i++) {
                    addScriptNode(newParent, true, (ScriptNode) node.getChildAt(i));
                }
            }
        }

        @Override
        public void menuSelected(MenuEvent e) {
            mnScripts.removeAll();
            ScriptNode[] scripts = scriptsPanel.getScripts();
            for (final ScriptNode item : scripts) {
                addScriptNode(mnScripts, scripts.length > 1, item);
            }
            mnScripts.validate();
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    menuBar.add(mnScripts);
    addSpace.add();

    // add create script menu
    if (appPermissions.isScriptEditingAllowed()) {
        JMenu scriptsMenu = menuBuilder.createScriptCreationMenu(this, scriptManager);
        if (scriptsMenu != null) {
            menuBar.add(scriptsMenu);
        }
        addSpace.add();
    }

    // tools menu
    JMenu tools = new JMenu("Tools");
    menuBar.add(tools);
    JMenu memoryCache = new JMenu("Memory cache");
    tools.add(memoryCache);
    memoryCache.add(new AbstractAction("View cache statistics") {

        @Override
        public void actionPerformed(ActionEvent e) {
            TextInformationDialog dlg = new TextInformationDialog(AppFrame.this, "Memory cache statistics",
                    ApplicationCache.singleton().getUsageReport());
            dlg.setMinimumSize(new Dimension(400, 400));
            dlg.setLocationRelativeTo(AppFrame.this);
            dlg.setVisible(true);
        }
    });
    memoryCache.add(new AbstractAction("Clear memory cache") {

        @Override
        public void actionPerformed(ActionEvent e) {
            ApplicationCache.singleton().clearCache();
        }
    });
    addSpace.add();

    // add window menu
    JMenu mnWindow = menuBuilder.createWindowsMenu(this);
    mnWindow.add(new AbstractAction("Show all tables") {

        @Override
        public void actionPerformed(ActionEvent e) {
            tileTables();
        }
    });

    JMenu mnResizeTo = new JMenu("Resize application to...");
    for (final int[] size : new int[][] { new int[] { 1280, 720 }, new int[] { 1920, 1080 } }) {
        mnResizeTo.add(new AbstractAction("" + size[0] + " x " + size[1]) {

            @Override
            public void actionPerformed(ActionEvent e) {
                // set standard layout
                setSize(size[0], size[1]);
                splitterMain.setDividerLocation(0.175);
                splitterLeftSide.setDividerLocation(0.3);
            }
        });
    }
    mnWindow.add(mnResizeTo);
    menuBar.add(mnWindow);
    addSpace.add();

    menuBar.add(menuBuilder.createHelpMenu(actionBuilder, this));

    addSpace.add();

}

From source file:com.opendoorlogistics.studio.AppFrame.java

private void initMenus() {
    final JMenuBar menuBar = new JMenuBar();
    class AddSpace {
        void add() {
            JMenu dummy = new JMenu();
            dummy.setEnabled(false);
            menuBar.add(dummy);/*from   www.ja  v a2  s .  c  om*/
        }
    }
    AddSpace addSpace = new AddSpace();

    // add file menu ... build on the fly for recent files..
    setJMenuBar(menuBar);
    final JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    mnFile.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            initFileMenu(mnFile);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void menuCanceled(MenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    initFileMenu(mnFile);
    menuBar.add(mnFile);
    addSpace.add();

    // add edit menu
    JMenu mnEdit = new JMenu("Edit");
    mnEdit.setMnemonic('E');
    menuBar.add(mnEdit);
    addSpace.add();
    for (MyAction action : editActions) {
        JMenuItem item = mnEdit.add(action);
        if (action.accelerator != null) {
            item.setAccelerator(action.accelerator);
        }
    }

    // add run scripts menu (hidden until a datastore is loaded)
    mnScripts = new JMenu("Run script");
    mnScripts.setMnemonic('R');
    mnScripts.setVisible(false);
    mnScripts.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            mnScripts.removeAll();
            for (final ScriptNode item : scriptsPanel.getScripts()) {
                if (item.isAvailable() == false) {
                    continue;
                }
                if (item.isRunnable()) {
                    mnScripts.add(new AbstractAction(item.getDisplayName(), item.getIcon()) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            scriptManager.executeScript(item.getFile(), item.getLaunchExecutorId());
                        }
                    });
                } else if (item.getChildCount() > 0) {
                    JMenu popup = new JMenu(item.getDisplayName());
                    mnScripts.add(popup);
                    for (int i = 0; i < item.getChildCount(); i++) {
                        final ScriptNode child = (ScriptNode) item.getChildAt(i);
                        if (child.isRunnable()) {
                            popup.add(new AbstractAction(child.getDisplayName(), child.getIcon()) {

                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    scriptManager.executeScript(child.getFile(), child.getLaunchExecutorId());
                                }
                            });
                        }

                    }
                }
            }
            mnScripts.validate();
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    menuBar.add(mnScripts);
    addSpace.add();

    // add create script menu
    menuBar.add(initCreateScriptsMenu());
    addSpace.add();

    // add window menu
    JMenu mnWindow = new JMenu("Window");
    mnWindow.setMnemonic('W');
    menuBar.add(mnWindow);
    addSpace.add();
    initWindowMenus(mnWindow);

    menuBar.add(initHelpMenu());

    addSpace.add();

}

From source file:com.limegroup.gnutella.gui.library.LibraryTableMediator.java

private JMenu createAdvancedMenu(LibraryTableDataLine dl) {
    JMenu menu = new JMenu(GUIMediator.getStringResource("GENERAL_ADVANCED_SUB_MENU"));
    if (dl != null) {
        menu.add(new JMenuItem(LICENSE_ACTION));
        menu.add(new JMenuItem(BITZI_LOOKUP_ACTION));
        menu.add(new JMenuItem(MAGNET_LOOKUP_ACTION));
        menu.add(new JMenuItem(COPY_MAGNET_TO_CLIPBOARD_ACTION));
        File file = getFile(TABLE.getSelectedRow());
        menu.setEnabled(RouterService.getFileManager().isFileShared(file));
    }/* w  w  w . j ava2 s  .  c  om*/

    if (menu.getItemCount() == 0)
        menu.setEnabled(false);

    return menu;
}