use of dorkbox.systemTray.Checkbox 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