!include once #1031274 // dorkbox SystemTray // trayName has to be unique for each tray you create per application (or globally?) // Difference to installTrayIcon: menuItems can not be a PopupMenu // first of menuItems can be a Runnable for left-click on icon static dorkbox.systemTray.SystemTray dorkBox_installTrayIcon(S trayName, S imageID, S tooltip, O... menuItems) { // convenience parameter swap if (!isSnippetID(imageID) && isSnippetID(tooltip)) { S s = tooltip; tooltip = imageID; imageID = s; } ret dorkBox_installTrayIcon(trayName, imageIcon(imageID).getImage(), tooltip, menuItems); } static dorkbox.systemTray.SystemTray dorkBox_installTrayIcon(S trayName, Image image, S tooltip, O... _menuItems) null on exception { ret swing(() -> { Runnable leftClick = null; O[] menuItems = params_unpackList(_menuItems); if (first(menuItems) instanceof Runnable) { leftClick = (Runnable) menuItems[0]; menuItems = dropFirst(menuItems); } dorkbox.systemTray.SystemTray systemTray = dorkbox.systemTray.SystemTray.get(trayName); systemTray.setImage(image); systemTray.setStatus(tooltip); // TODO if (leftClick != null) onLeftClick(trayIcon, _leftClick); var m = systemTray.getMenu(); var x = menuItems; for i over x: { O o = x[i]; if (eqOneOf(o, "***", "---", "===", "")) m.add(new dorkbox.systemTray.Separator()); else if (o instanceof S && _get(x, i+1) instanceof Runnable) m.add(new dorkbox.systemTray.MenuItem((S) o, actionListener(get(x, ++i)))); /*else if (o instanceof S || o instanceof Menu || o instanceof MenuItem) call(m, "add", o);*/ else print("Unknown menu item: " + o); } ret systemTray; }); }