!7 sclass TaskBar extends DynSCP { transient SimpleLiveValue lvInvisible = stringLiveValue(); transient Bool vertical; transient ReliableSingleThread rst = new(r { revisualize2(); sleepSeconds(1); }); transient L status; transient L buttons; bool sortByName = true; bool shouldBeVertical() { Rect r = dm_getBounds(); ret r != null && r.h > r.w*0.3; } JComponent visualize2() { temp enter(); if (vertical == null) vertical = shouldBeVertical(); if (!makeButtons() && getComponent() != null) ret getComponent(); JLabel lblInvisible = onLeftClick(jLiveValueLabel(lvInvisible), r dm_showInvisibleModulesList); ret vertical ? jscroll_dynamicvstack(withRightMargin(6, dynamicVStack2(listPlusInBeginning( (L) (L) buttons, withMargin(6, lblInvisible))))) : centerAndEast(hgrid(buttons), withLeftAndRightMargin(6, 3, lblInvisible)); } void enhanceFrame(Container f) { super.enhanceFrame(f); addTitlePopupMenuItems((RootPaneContainer) f, "Place on bottom", rThread placeOnBottom, "Place on the right", rThread placeOnRight); onResize(f, r { if (vertical != shouldBeVertical()) { vertical = shouldBeVertical(); print("Revisualizing task bar"); revisualize2(); } }); } void placeOnBottom { if (!isFalse(vertical)) { vertical = false; revisualize2_impl(); } Container frame = dm_frame(); Rectangle desktop = getBounds(dm_desktopPane()); if (frame != null && desktop != null) { packInternalFrameVertically_noFix((JInternalFrame) frame); Rectangle me = getBounds(frame); DynModule mod = dm_current(); dm_setBounds(mod, 0, desktop.height-me.height, desktop.width, me.height); } } void placeOnRight { Rectangle desktop = getBounds(dm_desktopPane()); if (desktop != null) { int w = min(desktop.width/4, 300); dm_setBounds(dm_current(), desktop.width-w, 0, w, desktop.height); } } void update { rst.trigger(); } // returns true if change bool makeButtons() { Pair p = dm_visibleAndInvisibleModules(); LS namesVis = map dm_moduleName(p.a); Map namesMap = zipTwoListsToMap(p.a, namesVis); L vis = p.a; if (sortByName) { vis = sortedByMapLookup(vis, namesMap); //print("Sorted by map: " + namesMap); } LS namesInvis = map dm_moduleName(p.b); L status = ll(vertical, map dm_moduleID(vis), map dm_moduleID(p.b), map(vis, func(O mod) -> S { namesMap.get(mod) }), l(namesInvis)); if (eq(status, this.status)) false; this.status = status; print("Task bar: Making new buttons"); new L out; L modules = dm_listModules(); for (int i = 0; i < l(vis); i++) if (vis.get(i) != this) { final WeakReference ref = new(vis.get(i)); // allow GC for modules out.add(jbutton(namesMap.get(vis.get(i)), r { dm_showModule(ref!) })); } lvInvisible.set(empty(p.b) ? "" : "+ " + l(p.b) + " invisible"); buttons = out; true; } }