Search in sources :

Example 46 with MenuItem

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

the class ExternalTrayManager method getMainMenu.

public PopupMenu getMainMenu() {
    PopupMenu popup = new PopupMenu();
    MenuItem startItem = new MenuItem(_t("Start I2P"));
    startItem.addActionListener(new ActionListener() {

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

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

                @Override
                protected void done() {
                    trayIcon.displayMessage(_t("Starting"), _t("I2P is starting!"), TrayIcon.MessageType.INFO);
                    // Hide the tray icon.
                    // We cannot stop the desktopgui program entirely,
                    // since that risks killing the I2P process as well.
                    tray.remove(trayIcon);
                }
            }.execute();
        }
    });
    popup.add(startItem);
    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 47 with MenuItem

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

the class InternalTrayManager method updateMenu.

/**
 * Update the menu
 * @since 0.9.26
 */
protected synchronized void updateMenu() {
    boolean x = RouterManager.isShutdownInProgress(_context);
    boolean imminent = false;
    String status;
    if (x) {
        long time = RouterManager.getShutdownTimeRemaining(_context);
        if (time > 5000) {
            status = _t("Shutdown in {0}", DataHelper.formatDuration2(time).replace("&nbsp;", " "));
        } else {
            status = _t("Shutdown imminent");
            imminent = true;
        }
    } else {
        // status translations are in the console bundle
        status = _t("Network") + ": " + Translate.getString(RouterManager.getStatus(_context), _context, CONSOLE_BUNDLE_NAME);
    }
    PopupMenu awt = trayIcon.getPopupMenu();
    if (awt != null) {
        MenuItem item = awt.getItem(0);
        String oldStatus = item.getLabel();
        if (!status.equals(oldStatus))
            item.setLabel(status);
    }
    if (_browserItem != null)
        _browserItem.setEnabled(!imminent);
    if (_configItem != null)
        _configItem.setEnabled(!imminent);
    if (_restartItem != null)
        _restartItem.setEnabled(!x);
    if (_stopItem != null)
        _stopItem.setEnabled(!x);
    if (_restartHardItem != null)
        _restartHardItem.setEnabled(!imminent);
    if (_stopHardItem != null)
        _stopHardItem.setEnabled(!imminent);
    if (_cancelItem != null)
        _cancelItem.setEnabled(x && !imminent);
    if (_jstatusItem != null)
        _jstatusItem.setText(status);
    if (_jbrowserItem != null)
        _jbrowserItem.setVisible(!imminent);
    if (_jconfigItem != null)
        _jconfigItem.setVisible(!imminent);
    if (_jrestartItem != null)
        _jrestartItem.setVisible(!x);
    if (_jstopItem != null)
        _jstopItem.setVisible(!x);
    if (_jrestartHardItem != null)
        _jrestartHardItem.setVisible(!imminent);
    if (_jstopHardItem != null)
        _jstopHardItem.setVisible(!imminent);
    if (_jcancelItem != null)
        _jcancelItem.setVisible(x && !imminent);
}
Also used : MenuItem(java.awt.MenuItem) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) PopupMenu(java.awt.PopupMenu)

Example 48 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 49 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 50 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)50 PopupMenu (java.awt.PopupMenu)21 Menu (java.awt.Menu)15 JMenuItem (javax.swing.JMenuItem)15 JPopupMenu (javax.swing.JPopupMenu)13 TrayIcon (java.awt.TrayIcon)10 MenuShortcut (java.awt.MenuShortcut)9 ActionEvent (java.awt.event.ActionEvent)9 CheckboxMenuItem (java.awt.CheckboxMenuItem)8 ActionListener (java.awt.event.ActionListener)8 AWTException (java.awt.AWTException)7 Image (java.awt.Image)7 SystemTray (java.awt.SystemTray)6 IOException (java.io.IOException)6 Dimension (java.awt.Dimension)4 File (java.io.File)4 FileDialog (java.awt.FileDialog)3 URL (java.net.URL)3 SQLException (java.sql.SQLException)3 JMenu (javax.swing.JMenu)3