Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

47
LINES

< > BotCompany Repo | #1034163 // BackgroundProcessesUI [backup]

JavaX fragment (include)

sclass BackgroundProcessesUI<A> {
  Set<A> processes = syncLinkedHashSet();
  SimpleLiveValue<Int> lvCount = new SimpleLiveValue<Int>(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;
  }
}

Author comment

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: 120 / 150
Referenced in: