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

91
LINES

< > BotCompany Repo | #1018410 // Task Bar v2 [Dyn Module]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Libraryless. Click here for Pure Java version (6068L/42K).

1  
!7
2  
3  
sclass TaskBar extends DynSCP {
4  
  transient SimpleLiveValue<S> lvInvisible = stringLiveValue();
5  
  transient Bool vertical;
6  
  transient ReliableSingleThread rst = dm_rstWithPostDelay(this, 1.0, r revisualize2);
7  
  transient L<L> status;
8  
  transient L<JButton> buttons;
9  
  bool sortByName = true;
10  
  
11  
  start {
12  
    if (dm_getBounds() == null) placeOnRight();
13  
    //DynSCP.verbose = true;
14  
    ownResource(vmBus_onMessages(vmBus_modulesListChangeMessages(), rst));
15  
  }
16  
  
17  
  bool shouldBeVertical() {
18  
    Rect r = dm_getBounds();
19  
    ret r != null && r.h > r.w*0.3;
20  
  }
21  
22  
  JComponent visualize2() {
23  
    temp enter();
24  
    if (vertical == null) vertical = shouldBeVertical();
25  
    time "makeButtons" {
26  
      bool mb = makeButtons();
27  
    }
28  
    if (!mb && getComponent() != null) ret getComponent();
29  
    JLabel lblInvisible = onLeftClick(jLiveValueLabel(lvInvisible), r dm_showInvisibleModulesList);
30  
    ret vertical
31  
      ? jscroll_dynamicvstack(withRightMargin(6, dynamicVStack2(listPlusInBeginning(
32  
        (L<JComponent>) (L) buttons, withMargin(6, lblInvisible)))))
33  
      : centerAndEast(hgrid(buttons), withLeftAndRightMargin(6, 3, lblInvisible));
34  
  }
35  
  
36  
  void enhanceFrame(final Container f) {
37  
    super.enhanceFrame(f);
38  
    addTitlePopupMenuItems(f,
39  
      "Place on bottom", rThread placeOnBottom,
40  
      "Place on the right", rThread placeOnRight);
41  
    onResize(f, r {
42  
      //print("onResize " + jGetSize(f));
43  
      if (vertical == shouldBeVertical()) ret;
44  
      vertical = shouldBeVertical();
45  
      revisualize2();
46  
    });
47  
  }
48  
  
49  
  void placeOnBottom {
50  
    temp enter();
51  
    if (!isFalse(vertical)) { vertical = false; revisualize2_impl(); } // for height calculation
52  
    dm_placeOnBottom();
53  
  }
54  
  
55  
  void placeOnRight { temp enter(); dm_placeOnRight(); }
56  
  void update { /*printStackTrace();*/ rst.trigger(); }
57  
58  
  // returns true if change
59  
  bool makeButtons() {
60  
    Pair<L> p = dm_visibleAndInvisibleModules();
61  
    LS namesVis = map dm_moduleName(p.a);
62  
    final Map<O, S> namesMap = zipTwoListsToMap(p.a, namesVis);
63  
    L vis = p.a;
64  
    if (sortByName) {
65  
      vis = sortedByMapLookupCI(vis, namesMap);
66  
      //print("Sorted by map: " + namesMap);
67  
    }
68  
    LS namesInvis = map dm_moduleName(p.b);
69  
    L status = ll(vertical, map dm_moduleID(vis), map dm_moduleID(p.b), map(vis, func(O mod) -> S { namesMap.get(mod) }), l(namesInvis));
70  
    if (eq(status, this.status)) false;
71  
    this.status = status;
72  
    print("Task bar: Making new buttons");
73  
    
74  
    new L<JButton> out;
75  
    L modules = dm_listModules();
76  
    L<Pair<S, VF1<O>>> moduleItems = dm_moduleMenuItems();
77  
    for (int i = 0; i < l(vis); i++)
78  
      if (vis.get(i) != this) {
79  
        final WeakReference ref = new(vis.get(i)); // allow GC for modules
80  
        JButton btn = jbutton(namesMap.get(vis.get(i)), r { dm_showModule(ref!) });
81  
        for (final Pair<S, VF1<O>> p2 : moduleItems)
82  
          componentPopupMenuItem(btn,
83  
            p2.a, rThread { O mod = ref!; if (mod != null) callF(p2.b, ref!) });
84  
        out.add(btn);
85  
      }
86  
    lvInvisible.set(empty(p.b) ? "" : "+ " + l(p.b) + " invisible");
87  
88  
    buttons = out;
89  
    true;
90  
  }
91  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018410
Snippet name: Task Bar v2 [Dyn Module]
Eternal ID of this version: #1018410/34
Text MD5: 23d383ab0cda53250faaa8466a35b9f2
Transpilation MD5: 3635e78ca5d2452258ea7ef4e3bde648
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-28 13:57:03
Source code size: 3196 bytes / 91 lines
Pitched / IR pitched: No / No
Views / Downloads: 418 / 4358
Version history: 33 change(s)
Referenced in: [show references]