Libraryless. Click here for Pure Java version (10720L/76K).
1  | !7  | 
2  | |
3  | sclass TaskBar extends DynSCP {
 | 
4  | transient SimpleLiveValue<S> lvInvisible = stringLiveValue();  | 
5  | transient Bool vertical;  | 
6  |   transient ReliableSingleThread rst = new(r {
 | 
7  | revisualize2();  | 
8  | sleepSeconds(1);  | 
9  | });  | 
10  | |
11  |   bool shouldBeVertical() {
 | 
12  | Rect r = dm_getBounds();  | 
13  | ret r != null && r.h > r.w*0.3;  | 
14  | }  | 
15  | |
16  |   JComponent visualize2() {
 | 
17  | L<JButton> buttons = makeButtons();  | 
18  | JLabel lblInvisible = onLeftClick(jLiveValueLabel(lvInvisible), r dm_showInvisibleModulesList);  | 
19  | if (vertical == null) vertical = shouldBeVertical();  | 
20  | ret vertical  | 
21  | ? jscroll_dynamicvstack(dynamicVStack2(listPlusInBeginning(  | 
22  | (L<JComponent>) (L) buttons, withMargin(6, lblInvisible))))  | 
23  | : centerAndEast(hgrid(buttons), withLeftAndRightMargin(6, 3, lblInvisible));  | 
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()) {
 | 
32  | vertical = shouldBeVertical();  | 
33  |         print("Revisualizing task bar");
 | 
34  | revisualize2();  | 
35  | }  | 
36  | });  | 
37  | }  | 
38  | |
39  |   void placeOnBottom {
 | 
40  |     if (!isFalse(vertical)) { vertical = false; revisualize2_impl(); }
 | 
41  | Container frame = dm_frame();  | 
42  | Rectangle desktop = getBounds(dm_desktopPane());  | 
43  |     if (frame != null && desktop != null) {
 | 
44  |       print("Packing frame");
 | 
45  | packInternalFrameVertically_noFix((JInternalFrame) frame);  | 
46  | Rectangle me = getBounds(frame);  | 
47  | DynModule mod = dm_current();  | 
48  | dm_setBounds(mod, 0, desktop.height-me.height,  | 
49  | desktop.width, me.height);  | 
50  | }  | 
51  | }  | 
52  | |
53  |   void placeOnRight {
 | 
54  | Rectangle desktop = getBounds(dm_desktopPane());  | 
55  |     if (desktop != null) {
 | 
56  | int w = min(desktop.width/4, 300);  | 
57  | dm_setBounds(dm_current(), desktop.width-w, 0, w, desktop.height);  | 
58  | }  | 
59  | }  | 
60  | |
61  |   void update { rst.trigger(); }
 | 
62  | |
63  | // TODO: make less often  | 
64  |   L<JButton> makeButtons() {
 | 
65  | new L<JButton> out;  | 
66  | new L invisible;  | 
67  | L modules = dm_listModules();  | 
68  | // TODO: get module names all at once  | 
69  | for (fO m : modules)  | 
70  | if (m != this)  | 
71  |         if (dm_isVisible(m)) {
 | 
72  | final WeakReference ref = new(m); // allow GC for modules  | 
73  |           out.add(jbutton(dm_moduleName(m), r { dm_showModule(ref!) }));
 | 
74  | } else invisible.add(m);  | 
75  | lvInvisible.set(empty(invisible) ? "" : "+ " + l(invisible) + " invisible");  | 
76  | |
77  | ret out;  | 
78  | }  | 
79  | }  | 
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1016123 | 
| Snippet name: | Task Bar [Dyn Module] | 
| Eternal ID of this version: | #1016123/47 | 
| Text MD5: | 9862da9a0bc1fc39cc11f90260cbc7cd | 
| Transpilation MD5: | a2731ce50b8208a2d775cd8c221656df | 
| Author: | stefan | 
| Category: | javax | 
| Type: | JavaX source code (Dynamic Module) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2018-11-28 21:41:06 | 
| Source code size: | 2494 bytes / 79 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 863 / 27174 | 
| Version history: | 46 change(s) | 
| Referenced in: | [show references] |