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:org.eobjects.datacleaner.panels.DatabaseDriversPanel.java

private void updateComponents() {
    this.removeAll();
    final JToolBar toolBar = WidgetFactory.createToolBar();
    toolBar.add(WidgetFactory.createToolBarSeparator());

    final JButton addDriverButton = new JButton("Add database driver",
            imageManager.getImageIcon(IconUtils.ACTION_ADD));
    addDriverButton.addActionListener(new ActionListener() {
        @Override//from   ww  w  . j  a  v a 2 s . c  o m
        public void actionPerformed(ActionEvent e) {

            final JMenu menu = new JMenu("Automatic download and install");
            menu.setIcon(imageManager.getImageIcon("images/actions/download.png"));

            final List<DatabaseDriverDescriptor> drivers = _databaseDriverCatalog.getDatabaseDrivers();
            for (DatabaseDriverDescriptor dd : drivers) {
                final String[] urls = dd.getDownloadUrls();
                if (urls != null && _databaseDriverCatalog.getState(dd) == DatabaseDriverState.NOT_INSTALLED) {
                    final JMenuItem downloadAndInstallMenuItem = WidgetFactory
                            .createMenuItem(dd.getDisplayName(), dd.getIconImagePath());
                    downloadAndInstallMenuItem.addActionListener(createDownloadActionListener(dd));
                    menu.add(downloadAndInstallMenuItem);
                }
            }

            if (menu.getMenuComponentCount() == 0) {
                menu.setEnabled(false);
            }

            final JMenuItem localJarFilesMenuItem = WidgetFactory.createMenuItem("Local JAR file(s)...",
                    "images/filetypes/archive.png");
            localJarFilesMenuItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    AddDatabaseDriverDialog dialog = new AddDatabaseDriverDialog(_databaseDriverCatalog,
                            DatabaseDriversPanel.this, _windowContext, _userPreferences);
                    dialog.setVisible(true);
                }
            });

            final JPopupMenu popup = new JPopupMenu();
            popup.add(menu);
            popup.add(localJarFilesMenuItem);
            popup.show(addDriverButton, 0, addDriverButton.getHeight());
        }
    });
    toolBar.add(addDriverButton);

    final DCTable table = getDatabaseDriverTable();
    this.add(toolBar, BorderLayout.NORTH);
    this.add(table.toPanel(), BorderLayout.CENTER);
}

From source file:org.jcurl.demo.tactics.TacticsApp.java

private JMenuBar createMenu() {
    final JMenuBar bar = new JMenuBar();
    {/*from w  w  w . j  a v a2 s. c o m*/
        final JMenu menu = bar.add(new JMenu("File"));
        menu.setMnemonic('F');
        menu.add(this.newMI("New", null, 'N', -1, this, "cmdNew"));
        menu.add(this.newMI("Open", null, 'O', KeyEvent.VK_O, this, "cmdOpen"));
        menu.addSeparator();
        menu.add(this.newMI("Export Png", null, 'P', KeyEvent.VK_E, this, "cmdExportPng"));
        menu.addSeparator();
        menu.add(this.newMI("Save", null, 'S', KeyEvent.VK_S, this, "cmdSave"));
        menu.add(this.newMI("Save As", null, 'A', -1, this, "cmdSaveAs"));
        menu.addSeparator();
        menu.add(this.newMI("Exit", null, 'x', -1, this, "cmdExit"));
    }
    {
        final JMenu menu = bar.add(new JMenu("View"));
        menu.setMnemonic('V');
        menu.add(this.newMI("Zoom", null, 'z', -1, this, "cmdZoom"));
    }
    {
        final JMenu menu = bar.add(new JMenu("Play"));
        menu.setMnemonic('P');
        menu.setEnabled(false);
        // menu.add(newMI('a', -1, bStart.getAction()));
        // menu.add(newMI('P', -1, bPause.getAction()));
        // menu.add(newMI('o', -1, bStop.getAction()));
    }
    {
        final JMenu menu = bar.add(new JMenu("Help"));
        menu.setMnemonic('H');
        menu.add(this.newMI("About", null, 'a', -1, this, "cmdAbout"));
    }
    return bar;
}

From source file:org.tinymediamanager.ui.MainWindow.java

/**
 * Create the application./*  w  w  w  . j  av a 2  s  .c o m*/
 * 
 * @param name
 *          the name
 */
public MainWindow(String name) {
    super(name);
    setName("mainWindow");
    setMinimumSize(new Dimension(1000, 700));

    instance = this;

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnTmm = new JMenu("tinyMediaManager");
    mnTmm.setMnemonic(KeyEvent.VK_T);
    menuBar.add(mnTmm);

    if (!Globals.isDonator()) {
        mnTmm.add(new RegisterDonatorVersionAction());
    }

    mnTmm.add(new SettingsAction());
    mnTmm.addSeparator();
    mnTmm.add(new LaunchUpdaterAction());
    mnTmm.addSeparator();
    mnTmm.add(new ExitAction());
    initialize();

    // tools menu
    JMenu tools = new JMenu(BUNDLE.getString("tmm.tools")); //$NON-NLS-1$
    tools.setMnemonic(KeyEvent.VK_O);
    tools.add(new ClearDatabaseAction());

    JMenu cache = new JMenu(BUNDLE.getString("tmm.cache")); //$NON-NLS-1$
    cache.setMnemonic(KeyEvent.VK_C);
    tools.add(cache);
    JMenuItem clearImageCache = new JMenuItem(new ClearImageCacheAction());
    clearImageCache.setMnemonic(KeyEvent.VK_I);
    cache.add(clearImageCache);

    JMenuItem rebuildImageCache = new JMenuItem(new RebuildImageCacheAction());
    rebuildImageCache.setMnemonic(KeyEvent.VK_R);
    cache.add(rebuildImageCache);

    JMenuItem tmmFolder = new JMenuItem(BUNDLE.getString("tmm.gotoinstalldir")); //$NON-NLS-1$
    tmmFolder.setMnemonic(KeyEvent.VK_I);
    tools.add(tmmFolder);
    tmmFolder.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            Path path = Paths.get(System.getProperty("user.dir"));
            try {
                // check whether this location exists
                if (Files.exists(path)) {
                    TmmUIHelper.openFile(path);
                }
            } catch (Exception ex) {
                LOGGER.error("open filemanager", ex);
                MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, path,
                        "message.erroropenfolder", new String[] { ":", ex.getLocalizedMessage() }));
            }
        }
    });

    JMenuItem tmmLogs = new JMenuItem(BUNDLE.getString("tmm.errorlogs")); //$NON-NLS-1$
    tmmLogs.setMnemonic(KeyEvent.VK_L);
    tools.add(tmmLogs);
    tmmLogs.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            JDialog logDialog = new LogDialog();
            logDialog.setLocationRelativeTo(MainWindow.getActiveInstance());
            logDialog.setVisible(true);
        }
    });

    JMenuItem tmmMessages = new JMenuItem(BUNDLE.getString("tmm.messages")); //$NON-NLS-1$
    tmmMessages.setMnemonic(KeyEvent.VK_L);
    tools.add(tmmMessages);
    tmmMessages.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            JDialog messageDialog = MessageHistoryDialog.getInstance();
            messageDialog.setVisible(true);
        }
    });

    tools.addSeparator();
    final JMenu menuWakeOnLan = new JMenu(BUNDLE.getString("tmm.wakeonlan")); //$NON-NLS-1$
    menuWakeOnLan.setMnemonic(KeyEvent.VK_W);
    menuWakeOnLan.addMenuListener(new MenuListener() {
        @Override
        public void menuCanceled(MenuEvent arg0) {
        }

        @Override
        public void menuDeselected(MenuEvent arg0) {
        }

        @Override
        public void menuSelected(MenuEvent arg0) {
            menuWakeOnLan.removeAll();
            for (final WolDevice device : Globals.settings.getWolDevices()) {
                JMenuItem item = new JMenuItem(device.getName());
                item.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        Utils.sendWakeOnLanPacket(device.getMacAddress());
                    }
                });
                menuWakeOnLan.add(item);
            }
        }
    });
    tools.add(menuWakeOnLan);

    // activate/deactivate WakeOnLan menu item
    tools.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            if (Globals.settings.getWolDevices().size() > 0) {
                menuWakeOnLan.setEnabled(true);
            } else {
                menuWakeOnLan.setEnabled(false);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });

    if (Globals.isDebug()) {
        final JMenu debugMenu = new JMenu("Debug"); //$NON-NLS-1$

        JMenuItem trace = new JMenuItem("set Logger to TRACE"); //$NON-NLS-1$
        trace.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
                lc.getLogger("org.tinymediamanager").setLevel(Level.TRACE);
                MessageManager.instance.pushMessage(new Message("Trace levels set!", ""));
                LOGGER.trace("if you see that, we're now on TRACE logging level ;)");
            }
        });

        debugMenu.add(trace);
        tools.add(debugMenu);
    }

    menuBar.add(tools);

    mnTmm = new JMenu(BUNDLE.getString("tmm.contact")); //$NON-NLS-1$
    mnTmm.setMnemonic(KeyEvent.VK_C);
    mnTmm.add(new FeedbackAction()).setMnemonic(KeyEvent.VK_F);
    mnTmm.add(new BugReportAction()).setMnemonic(KeyEvent.VK_B);
    menuBar.add(mnTmm);

    mnTmm = new JMenu(BUNDLE.getString("tmm.help")); //$NON-NLS-1$
    mnTmm.setMnemonic(KeyEvent.VK_H);
    menuBar.add(mnTmm);

    mnTmm.add(new WikiAction()).setMnemonic(KeyEvent.VK_W);
    mnTmm.add(new FaqAction()).setMnemonic(KeyEvent.VK_F);
    mnTmm.add(new ForumAction()).setMnemonic(KeyEvent.VK_O);
    mnTmm.addSeparator();

    mnTmm.add(new AboutAction()).setMnemonic(KeyEvent.VK_A);

    menuBar.add(Box.createGlue());

    if (!Globals.isDonator()) {
        JButton btnDonate = new JButton(new DonateAction());
        btnDonate.setBorderPainted(false);
        btnDonate.setFocusPainted(false);
        btnDonate.setContentAreaFilled(false);
        menuBar.add(btnDonate);
    }

    checkForUpdate();
}