Search in sources :

Example 1 with MenuItem

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);
}
Also used : SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) MenuItem(dorkbox.systemTray.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Separator(dorkbox.systemTray.Separator)

Example 2 with MenuItem

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();
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MenuItem(dorkbox.systemTray.MenuItem) LaunchUtil.getResourceAsString(runwar.LaunchUtil.getResourceAsString) IOException(java.io.IOException) JSONObject(net.minidev.json.JSONObject) Checkbox(dorkbox.systemTray.Checkbox) JSONObject(net.minidev.json.JSONObject) Menu(dorkbox.systemTray.Menu) ZipFile(java.util.zip.ZipFile) File(java.io.File) LaunchUtil.readFile(runwar.LaunchUtil.readFile) Separator(dorkbox.systemTray.Separator)

Aggregations

MenuItem (dorkbox.systemTray.MenuItem)2 Separator (dorkbox.systemTray.Separator)2 Checkbox (dorkbox.systemTray.Checkbox)1 Menu (dorkbox.systemTray.Menu)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ZipFile (java.util.zip.ZipFile)1 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)1 JSONObject (net.minidev.json.JSONObject)1 LaunchUtil.getResourceAsString (runwar.LaunchUtil.getResourceAsString)1 LaunchUtil.readFile (runwar.LaunchUtil.readFile)1