1 | sclass BackgroundProcessesUI<A> { |
2 | Set<A> processes = syncLinkedHashSet(); |
3 | SimpleLiveValue<Int> lvCount = new SimpleLiveValue<Int>(Int, 0); |
4 | |
5 | JLabel shortLabel() { |
6 | var lbl = bindToolTipToTransformedLiveValue( |
7 | n -> makeToolTip(), lvCount, |
8 | simpleTransformedLiveValueLabel(n -> n2(n), lvCount)); |
9 | |
10 | addPopupTrigger(lbl, e -> { |
11 | var l = cloneList(processes); |
12 | new JPopupMenu menu; |
13 | int n = componentCount(menu); |
14 | for (A a : l) |
15 | addMenuItem(menu, processToMenuItem(a)); |
16 | if (componentCount(menu) != n) |
17 | showPopupMenu(menu, e); |
18 | }); |
19 | |
20 | ret lbl; |
21 | } |
22 | |
23 | void add(A process) { |
24 | if (processes.add(process)) |
25 | lvCount.set(l(processes)); |
26 | } |
27 | |
28 | void remove(A process) { |
29 | if (processes.remove(process)) |
30 | lvCount.set(l(processes)); |
31 | } |
32 | |
33 | void addOrRemove(bool add, A process) { |
34 | if (add) add(process); else remove(process); |
35 | } |
36 | |
37 | S makeToolTip() { |
38 | var l = cloneList(processes); |
39 | ret empty(l) ? "No background processes" |
40 | : n2(l, "background process", "background processes") |
41 | + ": " + joinWithComma(processes); |
42 | } |
43 | |
44 | swappable JMenuItem processToMenuItem(A process) { |
45 | ret null; |
46 | } |
47 | } |
Began life as a copy of #1034127
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034163 |
Snippet name: | BackgroundProcessesUI [backup] |
Eternal ID of this version: | #1034163/1 |
Text MD5: | f2492257048635fbe6ea2c703f4c13d7 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-24 22:59:14 |
Source code size: | 1245 bytes / 47 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 119 / 149 |
Referenced in: | [show references] |