Search in sources :

Example 26 with MenuItem

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

the class TrayMenuController method rebuildMenu.

private void rebuildMenu() {
    menu.removeAll();
    MenuItem showMainWindowItem = new MenuItem(resourceBundle.getString("traymenu.showMainWindow"));
    showMainWindowItem.addActionListener(this::showMainWindow);
    menu.add(showMainWindowItem);
    MenuItem showPreferencesItem = new MenuItem(resourceBundle.getString("traymenu.showPreferencesWindow"));
    showPreferencesItem.addActionListener(this::showPreferencesWindow);
    menu.add(showPreferencesItem);
    menu.addSeparator();
    for (Vault v : vaults) {
        MenuItem submenu = buildSubmenu(v);
        menu.add(submenu);
    }
    menu.addSeparator();
    MenuItem lockAllItem = new MenuItem(resourceBundle.getString("traymenu.lockAllVaults"));
    lockAllItem.addActionListener(this::lockAllVaults);
    lockAllItem.setEnabled(!vaults.filtered(Vault::isUnlocked).isEmpty());
    menu.add(lockAllItem);
    MenuItem quitApplicationItem = new MenuItem(resourceBundle.getString("traymenu.quitApplication"));
    quitApplicationItem.addActionListener(this::quitApplication);
    menu.add(quitApplicationItem);
}
Also used : MenuItem(java.awt.MenuItem) Vault(org.cryptomator.common.vaults.Vault)

Example 27 with MenuItem

use of java.awt.MenuItem in project vft-capture by videofirst.

the class VfCaptureFrame method setupSystemTray.

// Private methods
private void setupSystemTray() {
    if (SystemTray.isSupported()) {
        tray = SystemTray.getSystemTray();
        Image image = Toolkit.getDefaultToolkit().getImage(CAPTURE_ICON_16);
        ActionListener exitListener = e -> System.exit(0);
        PopupMenu popup = new PopupMenu();
        MenuItem defaultItem = new MenuItem("Exit");
        defaultItem.addActionListener(exitListener);
        popup.add(defaultItem);
        defaultItem = new MenuItem("Open");
        defaultItem.addActionListener(e -> {
            showCaptureFrame();
        });
        popup.add(defaultItem);
        trayIcon = new TrayIcon(image, "Video First Capture", popup);
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {

            public void mouseClicked(MouseEvent e) {
                if (SwingUtilities.isLeftMouseButton(e)) {
                    showCaptureFrame();
                }
            }
        });
        addWindowStateListener(e -> {
            if (e.getNewState() == ICONIFIED || e.getNewState() == 7) {
                trayHide(true);
            }
            if (e.getNewState() == MAXIMIZED_BOTH || e.getNewState() == NORMAL) {
                trayHide(false);
            }
        });
    } else {
        System.out.println("system tray not supported");
    }
}
Also used : ActionListener(java.awt.event.ActionListener) Image(java.awt.Image) GraphicsDevice(java.awt.GraphicsDevice) Window(java.awt.Window) Point(java.awt.Point) CAPTURE_ICON_16(io.videofirst.capture.ui.constants.UiConstants.CAPTURE_ICON_16) GraphicsEnvironment(java.awt.GraphicsEnvironment) MouseEvent(java.awt.event.MouseEvent) PopupMenu(java.awt.PopupMenu) RecordPanel(io.videofirst.capture.ui.panels.RecordPanel) Dimension(java.awt.Dimension) SwingUtilities(javax.swing.SwingUtilities) MenuItem(java.awt.MenuItem) TrayIcon(java.awt.TrayIcon) AWTException(java.awt.AWTException) DisplayMode(java.awt.DisplayMode) MouseAdapter(java.awt.event.MouseAdapter) CaptureService(io.videofirst.capture.service.CaptureService) BorderLayout(java.awt.BorderLayout) SystemTray(java.awt.SystemTray) JFrame(javax.swing.JFrame) Toolkit(java.awt.Toolkit) MouseEvent(java.awt.event.MouseEvent) ActionListener(java.awt.event.ActionListener) TrayIcon(java.awt.TrayIcon) MouseAdapter(java.awt.event.MouseAdapter) MenuItem(java.awt.MenuItem) Image(java.awt.Image) PopupMenu(java.awt.PopupMenu)

Example 28 with MenuItem

use of java.awt.MenuItem in project litiengine by gurkenlabs.

the class Tray method init.

public static void init() {
    // add system tray icon with popup menu
    if (SystemTray.isSupported()) {
        SystemTray tray = SystemTray.getSystemTray();
        PopupMenu menu = new PopupMenu();
        MenuItem exitItem = new MenuItem(Resources.strings().get("menu_exit"));
        exitItem.addActionListener(a -> Game.exit());
        menu.add(exitItem);
        trayIcon = new TrayIcon(Resources.images().get("liti-logo-x16.png"), Game.info().toString(), menu);
        trayIcon.setImageAutoSize(true);
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
    }
}
Also used : TrayIcon(java.awt.TrayIcon) SystemTray(java.awt.SystemTray) MenuItem(java.awt.MenuItem) PopupMenu(java.awt.PopupMenu) AWTException(java.awt.AWTException)

Example 29 with MenuItem

use of java.awt.MenuItem in project epadd by ePADD.

the class JettyShutdownThread method setupSystemTrayIcon.

/**
 * we need a system tray icon for management.
 * http://docs.oracle.com/javase/6/docs/api/java/awt/SystemTray.html
 */
public static void setupSystemTrayIcon() {
    // Set the app name in the menu bar for mac.
    // c.f. http://stackoverflow.com/questions/8918826/java-os-x-lion-set-application-name-doesnt-work
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "ePADD");
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    TrayIcon trayIcon = null;
    if (SystemTray.isSupported()) {
        System.out.println("Adding ePADD to the system tray");
        SystemTray tray = SystemTray.getSystemTray();
        // note: this better be 16x16, Windows doesn't resize! Mac os does.
        URL u = Main.class.getClassLoader().getResource("muse-icon.png");
        System.out.println("ePADD icon resource is " + u);
        Image image = Toolkit.getDefaultToolkit().getImage(u);
        System.out.println("Image = " + image);
        // create menu items and their listeners
        ActionListener openMuseControlsListener = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
                    // no + "info" for epadd like in muse
                    launchBrowser(BASE_URL);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        };
        ActionListener QuitMuseListener = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                out.println("*** Received quit from system tray. Stopping the Jetty embedded web server.");
                try {
                    server.stop();
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
                // we need to explicitly system.exit because we now use Swing (due to system tray, etc).
                System.exit(0);
            }
        };
        // create a popup menu
        PopupMenu popup = new PopupMenu();
        MenuItem defaultItem = new MenuItem("Open ePADD window");
        defaultItem.addActionListener(openMuseControlsListener);
        popup.add(defaultItem);
        MenuItem quitItem = new MenuItem("Quit ePADD");
        quitItem.addActionListener(QuitMuseListener);
        popup.add(quitItem);
        // / ... add other items
        // construct a TrayIcon
        String message = "ePADD menu";
        // on windows - the tray menu is a little non-intuitive, needs a right click (plain click seems unused)
        if (System.getProperty("os.name").toLowerCase().indexOf("windows") >= 0)
            message = "Right click for ePADD menu";
        trayIcon = new TrayIcon(image, message, popup);
        System.out.println("tray Icon = " + trayIcon);
        // trayIcon.addActionListener(openMuseControlsListener);
        try {
            tray.add(trayIcon);
        } catch (AWTException e) {
            System.err.println(e);
        }
    // ...
    } else {
    // disable tray option in your application or
    // perform other actions
    // ...
    }
    System.out.println("Done!");
    // the application state has changed - update the image
    if (trayIcon != null) {
    // trayIcon.setImage(updatedImage);
    }
// ...
}
Also used : SystemTray(java.awt.SystemTray) ActionEvent(java.awt.event.ActionEvent) MenuItem(java.awt.MenuItem) Image(java.awt.Image) URISyntaxException(java.net.URISyntaxException) AWTException(java.awt.AWTException) BindException(java.net.BindException) ConnectException(java.net.ConnectException) MalformedURLException(java.net.MalformedURLException) UnsupportedOperatingSystemException(edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException) IOException(java.io.IOException) BrowserLaunchingInitializingException(edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException) URL(java.net.URL) ActionListener(java.awt.event.ActionListener) TrayIcon(java.awt.TrayIcon) PopupMenu(java.awt.PopupMenu) AWTException(java.awt.AWTException)

Example 30 with MenuItem

use of java.awt.MenuItem in project proxyee-down by monkeyWie.

the class DownApplication method loadPopupMenu.

public void loadPopupMenu() {
    // 添加右键菜单
    PopupMenu popupMenu = new PopupMenu();
    MenuItem showItem = new MenuItem(I18nUtil.getMessage("gui.tray.show"));
    showItem.addActionListener(event -> Platform.runLater(() -> loadUri("", true)));
    MenuItem setItem = new MenuItem(I18nUtil.getMessage("gui.tray.set"));
    setItem.addActionListener(event -> loadUri("/#/setting", true));
    MenuItem aboutItem = new MenuItem(I18nUtil.getMessage("gui.tray.about"));
    aboutItem.addActionListener(event -> loadUri("/#/about", true));
    MenuItem supportItem = new MenuItem(I18nUtil.getMessage("gui.tray.support"));
    supportItem.addActionListener(event -> loadUri("/#/support", true));
    MenuItem closeItem = new MenuItem(I18nUtil.getMessage("gui.tray.exit"));
    closeItem.addActionListener(event -> {
        Platform.exit();
        System.exit(0);
    });
    popupMenu.add(showItem);
    popupMenu.addSeparator();
    popupMenu.add(setItem);
    popupMenu.add(aboutItem);
    popupMenu.add(supportItem);
    popupMenu.addSeparator();
    popupMenu.add(closeItem);
    trayIcon.setPopupMenu(popupMenu);
}
Also used : MenuItem(java.awt.MenuItem) PopupMenu(java.awt.PopupMenu)

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