sclass BackgroundProcessesUI {
Set processes = syncLinkedHashSet();
SimpleLiveValue lvCount = new SimpleLiveValue(Int, 0);
JLabel shortLabel() {
var lbl = bindToolTipToTransformedLiveValue(
n -> makeToolTip(), lvCount,
simpleTransformedLiveValueLabel(n -> n2(n), lvCount));
addPopupTrigger(lbl, e -> {
var l = cloneList(processes);
new JPopupMenu menu;
int n = componentCount(menu);
for (A a : l)
addMenuItem(menu, processToMenuItem(a));
if (componentCount(menu) != n)
showPopupMenu(menu, e);
});
ret lbl;
}
void add(A process) {
if (processes.add(process))
lvCount.set(l(processes));
}
void remove(A process) {
if (processes.remove(process))
lvCount.set(l(processes));
}
void addOrRemove(bool add, A process) {
if (add) add(process); else remove(process);
}
S makeToolTip() {
var l = cloneList(processes);
ret empty(l) ? "No background processes"
: n2(l, "background process", "background processes")
+ ": " + joinWithComma(processes);
}
swappable JMenuItem processToMenuItem(A process) {
ret null;
}
}