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).

!7

sclass TaskBar extends DynSCP {
  transient Bool vertical;
  transient L<L> status;
  transient L<JButton> buttons;

  start {
    doEvery(0.0, 10.0, r revisualize2);
  }
  
  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();
    ret vertical
      ? jscroll_dynamicvstack(withRightMargin(6, dynamicVStack2((L<JComponent>) (L) buttons, )))
      : hgrid(buttons);
  }
  
  enhanceFrame {
    addTitlePopupMenuItems(f,
      "Place on bottom", rThread placeOnBottom,
      "Place on the right", rThread placeOnRight);
    onResize(f, r {
      if (vertical == shouldBeVertical()) ret;
      vertical = shouldBeVertical();
      revisualize2();
    });
  }
  
  void placeOnBottom {
    temp enter();
    if (!isFalse(vertical)) { vertical = false; revisualize2_impl(); } // for height calculation
    dm_placeOnBottom();
  }
  
  void placeOnRight { temp enter(); dm_placeOnRight(); }

  // returns true if change
  bool makeButtons() {
    L<wmctrl_Entry> list = [wmctrl_Entry e : linux_wmctrl_list() | e.desktopNumber >= 0];
    L status = ll(vertical, list); // TODO: less fields
    if (eq(status, this.status)) false;
    this.status = status;
    print("Linux Task Bar: Making new buttons");
    
    new L<JButton> out;
    L<Pair<S, VF1<wmctrl_Entry>>> menuItems = (L) ll(pair("Close window", voidfunc(wmctrl_Entry e) { wmctrl_closeWindow(e) }));
    
    for (final wmctrl_Entry e : list) {
      JButton btn = jbutton(e.windowTitle, r { wmctrl_activateWindow(e) });
      for (final Pair<S, VF1<wmctrl_Entry>> p : menuItems)
        componentPopupMenuItem(btn, p.a, rThread { callF(p.b, e) });
      out.add(btn);
    }

    buttons = out;
    true;
  }
}

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: 284 / 442
Version history: 9 change(s)
Referenced in: [show references]