use of dorkbox.systemTray.MenuItem in project DeskChan by DeskChan.
the class PluginMenu method updateImpl.
private static synchronized void updateImpl() {
dorkbox.systemTray.Menu menu = trayRef.getMenu();
menu.clear();
trayRef.setStatus(App.NAME);
menu.add(new MenuItem(Main.getString("options"), optionsMenuItemAction));
menu.add(new MenuItem(Main.getString("send-top"), frontMenuItemAction));
menu.add(new Separator());
try {
for (PluginMenuItem it : menuItems) {
menu.add(it.getDorkBoxItem());
}
} catch (ConcurrentModificationException e) {
Main.log("Concurrent modification by tray. Write us if it cause you lags.");
return;
}
menu.add(new Separator());
menu.add(new MenuItem(Main.getString("quit"), quitMenuItemAction));
ObservableList<javafx.scene.control.MenuItem> contextMenuItems = contextMenu.getItems();
contextMenuItems.clear();
javafx.scene.control.MenuItem item = new javafx.scene.control.MenuItem(Main.getString("options"));
item.setOnAction(optionsMenuItemAction);
contextMenuItems.add(item);
item = new javafx.scene.control.MenuItem(Main.getString("send-top"));
item.setOnAction(frontMenuItemAction);
contextMenuItems.add(item);
contextMenuItems.add(new SeparatorMenuItem());
for (PluginMenuItem it : menuItems) {
contextMenuItems.add(it.getJavaFXItem());
}
contextMenuItems.add(new SeparatorMenuItem());
item = new javafx.scene.control.MenuItem(Main.getString("quit"));
item.setOnAction(quitMenuItemAction);
contextMenuItems.add(item);
}
use of dorkbox.systemTray.MenuItem in project runwar by cfmlprojects.
the class Tray method addMenuItems.
public static void addMenuItems(JSONArray items, Menu menu, Server server) {
for (Object ob : items) {
JSONObject itemInfo = (JSONObject) ob;
InputStream is = null;
String label = getString(itemInfo, "label", "");
String hotkey = getString(itemInfo, "hotkey", "");
boolean isDisabled = Boolean.parseBoolean(getString(itemInfo, "disabled", "false"));
if (itemInfo.get("image") != null) {
is = getImageInputStream(itemInfo.get("image").toString());
}
MenuItem menuItem = null;
if (itemInfo.get("items") != null) {
Menu submenu = new Menu(label, is);
submenu.setShortcut(label.charAt(0));
menu.add(submenu);
addMenuItems((JSONArray) itemInfo.get("items"), submenu, server);
} else if (itemInfo.get("separator") != null) {
menu.add(new Separator());
} else if (itemInfo.get("checkbox") != null) {
Checkbox checkbox = new Checkbox(label, null);
checkbox.setShortcut(label.charAt(0));
checkbox.setEnabled(!isDisabled);
menu.add(checkbox);
} else if (itemInfo.get("action") != null) {
String action = getString(itemInfo, "action", "");
if (action.toLowerCase().equals("stopserver")) {
menuItem = new MenuItem(label, is, new ExitAction(server));
menuItem.setShortcut('s');
} else if (action.toLowerCase().equals("restartserver")) {
menuItem = new MenuItem(label, is, new RestartAction(server));
menuItem.setShortcut('r');
} else if (action.toLowerCase().equals("getversion")) {
menuItem = new MenuItem("Version: " + Server.getVersion(), is, new GetVersionAction());
menuItem.setShortcut('v');
} else if (action.toLowerCase().equals("openbrowser")) {
String url = itemInfo.get("url").toString();
menuItem = new MenuItem(label, is, new OpenBrowserAction(url));
menuItem.setShortcut('o');
} else if (action.toLowerCase().equals("openfilesystem")) {
File path = new File(getString(itemInfo, "path", Server.getServerOptions().getWarPath()));
menuItem = new MenuItem(label, is, new BrowseFilesystemAction(path.getAbsolutePath()));
menuItem.setShortcut('b');
} else {
RunwarLogger.LOG.error("Unknown menu item action \"" + action + "\" for \"" + label + "\"");
}
} else {
menuItem = new MenuItem(label, is);
}
if (menuItem != null) {
if (hotkey.length() > 0) {
menuItem.setShortcut(hotkey.charAt(0));
}
menuItem.setEnabled(!isDisabled);
menu.add(menuItem);
}
try {
if (is != null)
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations