Search in sources :

Example 51 with MenuItem

use of java.awt.MenuItem in project i2p.i2p by i2p.

the class InternalTrayManager method getMainMenu.

public synchronized PopupMenu getMainMenu() {
    PopupMenu popup = new PopupMenu();
    final MenuItem statusItem = new MenuItem("");
    final MenuItem browserLauncher;
    if (CONSOLE_ENABLED) {
        browserLauncher = new MenuItem(_t("Launch I2P Browser"));
        browserLauncher.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new SwingWorker<Object, Object>() {

                    @Override
                    protected Object doInBackground() throws Exception {
                        return null;
                    }

                    @Override
                    protected void done() {
                        launchBrowser();
                    }
                }.execute();
            }
        });
    } else {
        browserLauncher = null;
    }
    PopupMenu desktopguiConfigurationLauncher = new PopupMenu(_t("Configure I2P System Tray"));
    MenuItem configSubmenu = new MenuItem(_t("Disable"));
    configSubmenu.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            new SwingWorker<Object, Object>() {

                @Override
                protected Object doInBackground() throws Exception {
                    configureDesktopgui(false);
                    return null;
                }
            }.execute();
        }
    });
    final MenuItem restartItem;
    if (_context.hasWrapper()) {
        restartItem = new MenuItem(_t("Restart I2P"));
        restartItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new SwingWorker<Object, Object>() {

                    @Override
                    protected Object doInBackground() throws Exception {
                        RouterManager.restartGracefully(_context);
                        return null;
                    }
                }.execute();
            }
        });
    } else {
        restartItem = null;
    }
    final MenuItem stopItem = new MenuItem(_t("Stop I2P"));
    stopItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            new SwingWorker<Object, Object>() {

                @Override
                protected Object doInBackground() throws Exception {
                    RouterManager.shutDownGracefully(_context);
                    return null;
                }
            }.execute();
        }
    });
    final MenuItem restartItem2;
    if (_context.hasWrapper()) {
        restartItem2 = new MenuItem(_t("Restart I2P Immediately"));
        restartItem2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent arg0) {
                new SwingWorker<Object, Object>() {

                    @Override
                    protected Object doInBackground() throws Exception {
                        RouterManager.restart(_context);
                        return null;
                    }
                }.execute();
            }
        });
    } else {
        restartItem2 = null;
    }
    final MenuItem stopItem2 = new MenuItem(_t("Stop I2P Immediately"));
    stopItem2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            new SwingWorker<Object, Object>() {

                @Override
                protected Object doInBackground() throws Exception {
                    RouterManager.shutDown(_context);
                    return null;
                }
            }.execute();
        }
    });
    final MenuItem cancelItem = new MenuItem(_t("Cancel I2P Shutdown"));
    cancelItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            new SwingWorker<Object, Object>() {

                @Override
                protected Object doInBackground() throws Exception {
                    RouterManager.cancelShutdown(_context);
                    return null;
                }
            }.execute();
        }
    });
    popup.add(statusItem);
    popup.addSeparator();
    if (CONSOLE_ENABLED) {
        popup.add(browserLauncher);
        popup.addSeparator();
    }
    desktopguiConfigurationLauncher.add(configSubmenu);
    popup.add(desktopguiConfigurationLauncher);
    popup.addSeparator();
    if (_context.hasWrapper())
        popup.add(restartItem);
    popup.add(stopItem);
    if (_context.hasWrapper())
        popup.add(restartItem2);
    popup.add(stopItem2);
    popup.add(cancelItem);
    _statusItem = statusItem;
    _browserItem = browserLauncher;
    _configItem = desktopguiConfigurationLauncher;
    _restartItem = restartItem;
    _stopItem = stopItem;
    _restartHardItem = restartItem2;
    _stopHardItem = stopItem2;
    _cancelItem = cancelItem;
    return popup;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) SwingWorker(javax.swing.SwingWorker) MenuItem(java.awt.MenuItem) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) PopupMenu(java.awt.PopupMenu)

Example 52 with MenuItem

use of java.awt.MenuItem in project cryptomator by cryptomator.

the class TrayMenuController method buildSubmenu.

private Menu buildSubmenu(Vault vault) {
    Menu submenu = new Menu(vault.getDisplayName());
    if (vault.isLocked()) {
        MenuItem unlockItem = new MenuItem(resourceBundle.getString("traymenu.vault.unlock"));
        unlockItem.addActionListener(createActionListenerForVault(vault, this::unlockVault));
        submenu.add(unlockItem);
    } else if (vault.isUnlocked()) {
        MenuItem lockItem = new MenuItem(resourceBundle.getString("traymenu.vault.lock"));
        lockItem.addActionListener(createActionListenerForVault(vault, this::lockVault));
        submenu.add(lockItem);
        MenuItem revealItem = new MenuItem(resourceBundle.getString("traymenu.vault.reveal"));
        revealItem.addActionListener(createActionListenerForVault(vault, this::revealVault));
        submenu.add(revealItem);
    }
    return submenu;
}
Also used : MenuItem(java.awt.MenuItem) Menu(java.awt.Menu) PopupMenu(java.awt.PopupMenu)

Example 53 with MenuItem

use of java.awt.MenuItem in project openblocks by mikaelhg.

the class ContextMenu method initRemoveCommentMenu.

/**
 * Initializes the context menu for deleting Comments.
 */
private static void initRemoveCommentMenu() {
    removeCommentItem = new MenuItem("Delete Comment");
    removeCommentItem.setActionCommand(REMOVE_COMMENT_BLOCK);
    removeCommentItem.addActionListener(rndBlockMenu);
    removeCommentMenu.add(removeCommentItem);
    // rndBlockMenu.add(runBlockItem);
    removeCommentMenuInit = true;
}
Also used : MenuItem(java.awt.MenuItem)

Aggregations

MenuItem (java.awt.MenuItem)53 PopupMenu (java.awt.PopupMenu)24 Menu (java.awt.Menu)15 JMenuItem (javax.swing.JMenuItem)15 JPopupMenu (javax.swing.JPopupMenu)13 TrayIcon (java.awt.TrayIcon)12 AWTException (java.awt.AWTException)9 MenuShortcut (java.awt.MenuShortcut)9 ActionEvent (java.awt.event.ActionEvent)9 ActionListener (java.awt.event.ActionListener)9 CheckboxMenuItem (java.awt.CheckboxMenuItem)8 Image (java.awt.Image)8 SystemTray (java.awt.SystemTray)8 IOException (java.io.IOException)6 Dimension (java.awt.Dimension)5 File (java.io.File)4 BorderLayout (java.awt.BorderLayout)3 FileDialog (java.awt.FileDialog)3 URL (java.net.URL)3 SQLException (java.sql.SQLException)3