Uses 8310K of libraries. Click here for Pure Java version (5531L/35K).
1 | !include once #1031274 // dorkbox SystemTray |
2 | |
3 | // trayName has to be unique for each tray you create per application (or globally?) |
4 | // Difference to installTrayIcon: menuItems can not be a PopupMenu |
5 | // first of menuItems can be a Runnable for left-click on icon |
6 | static dorkbox.systemTray.SystemTray dorkBox_installTrayIcon(S trayName, S imageID, S tooltip, O... menuItems) { |
7 | // convenience parameter swap |
8 | if (!isSnippetID(imageID) && isSnippetID(tooltip)) { |
9 | S s = tooltip; |
10 | tooltip = imageID; |
11 | imageID = s; |
12 | } |
13 | |
14 | ret dorkBox_installTrayIcon(trayName, imageIcon(imageID).getImage(), tooltip, menuItems); |
15 | } |
16 | |
17 | static dorkbox.systemTray.SystemTray dorkBox_installTrayIcon(S trayName, Image image, S tooltip, O... _menuItems) null on exception { |
18 | ret swing(() -> { |
19 | Runnable leftClick = null; |
20 | O[] menuItems = params_unpackList(_menuItems); |
21 | if (first(menuItems) instanceof Runnable) { |
22 | leftClick = (Runnable) menuItems[0]; |
23 | menuItems = dropFirst(menuItems); |
24 | } |
25 | |
26 | dorkbox.systemTray.SystemTray systemTray = dorkbox.systemTray.SystemTray.get(trayName); |
27 | systemTray.setImage(image); |
28 | |
29 | systemTray.setStatus(tooltip); |
30 | |
31 | // TODO if (leftClick != null) onLeftClick(trayIcon, _leftClick); |
32 | |
33 | var m = systemTray.getMenu(); |
34 | var x = menuItems; |
35 | |
36 | for i over x: { |
37 | O o = x[i]; |
38 | if (eqOneOf(o, "***", "---", "===", "")) |
39 | m.add(new dorkbox.systemTray.Separator()); |
40 | else if (o instanceof S && _get(x, i+1) instanceof Runnable) |
41 | m.add(new dorkbox.systemTray.MenuItem((S) o, actionListener(get(x, ++i)))); |
42 | /*else if (o instanceof S || o instanceof Menu || o instanceof MenuItem) |
43 | call(m, "add", o);*/ |
44 | else |
45 | print("Unknown menu item: " + o); |
46 | } |
47 | |
48 | ret systemTray; |
49 | }); |
50 | } |
Began life as a copy of #1003656
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1031275 |
Snippet name: | dorkbox_installTrayIcon - takes tray name, image ID and menu item params [dev.] |
Eternal ID of this version: | #1031275/9 |
Text MD5: | 76cfe3200f156f8b6365b3a8cfe30e9c |
Transpilation MD5: | 3247493a2556da2e62712409bee93406 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-05-31 13:03:47 |
Source code size: | 1832 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 166 / 243 |
Version history: | 8 change(s) |
Referenced in: | [show references] |