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

66
LINES

< > BotCompany Repo | #1019051 // Linux Task Bar [Dyn Module]

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

Libraryless. Click here for Pure Java version (7314L/53K).

1  
!7
2  
3  
sclass TaskBar extends DynSCP {
4  
  transient Bool vertical;
5  
  transient L<L> status;
6  
  transient L<JButton> buttons;
7  
8  
  start {
9  
    doEvery(0.0, 10.0, r revisualize2);
10  
  }
11  
  
12  
  bool shouldBeVertical() {
13  
    Rect r = dm_getBounds();
14  
    ret r != null && r.h > r.w*0.3;
15  
  }
16  
17  
  JComponent visualize2() {
18  
    temp enter();
19  
    if (vertical == null) vertical = shouldBeVertical();
20  
    if (!makeButtons() && getComponent() != null) ret getComponent();
21  
    ret vertical
22  
      ? jscroll_dynamicvstack(withRightMargin(6, dynamicVStack2((L<JComponent>) (L) buttons, )))
23  
      : hgrid(buttons);
24  
  }
25  
  
26  
  enhanceFrame {
27  
    addTitlePopupMenuItems(f,
28  
      "Place on bottom", rThread placeOnBottom,
29  
      "Place on the right", rThread placeOnRight);
30  
    onResize(f, r {
31  
      if (vertical == shouldBeVertical()) ret;
32  
      vertical = shouldBeVertical();
33  
      revisualize2();
34  
    });
35  
  }
36  
  
37  
  void placeOnBottom {
38  
    temp enter();
39  
    if (!isFalse(vertical)) { vertical = false; revisualize2_impl(); } // for height calculation
40  
    dm_placeOnBottom();
41  
  }
42  
  
43  
  void placeOnRight { temp enter(); dm_placeOnRight(); }
44  
45  
  // returns true if change
46  
  bool makeButtons() {
47  
    L<wmctrl_Entry> list = [wmctrl_Entry e : linux_wmctrl_list() | e.desktopNumber >= 0];
48  
    L status = ll(vertical, list); // TODO: less fields
49  
    if (eq(status, this.status)) false;
50  
    this.status = status;
51  
    print("Linux Task Bar: Making new buttons");
52  
    
53  
    new L<JButton> out;
54  
    L<Pair<S, VF1<wmctrl_Entry>>> menuItems = (L) ll(pair("Close window", voidfunc(wmctrl_Entry e) { wmctrl_closeWindow(e) }));
55  
    
56  
    for (final wmctrl_Entry e : list) {
57  
      JButton btn = jbutton(e.windowTitle, r { wmctrl_activateWindow(e) });
58  
      for (final Pair<S, VF1<wmctrl_Entry>> p : menuItems)
59  
        componentPopupMenuItem(btn, p.a, rThread { callF(p.b, e) });
60  
      out.add(btn);
61  
    }
62  
63  
    buttons = out;
64  
    true;
65  
  }
66  
}

Author comment

Began life as a copy of #1018410

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1019051
Snippet name: Linux Task Bar [Dyn Module]
Eternal ID of this version: #1019051/10
Text MD5: 3ee9384709d39dc8da1fb9eba1061e83
Transpilation MD5: 05ba35ceb04301a3d5f8218f44dc9ac6
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-28 21:41:28
Source code size: 1952 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 289 / 447
Version history: 9 change(s)
Referenced in: [show references]