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);
}
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");
}
}
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);
}
}
}
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);
}
// ...
}
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);
}
Aggregations