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

79
LINES

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

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

Libraryless. Click here for Pure Java version (10720L/76K).

!7

sclass TaskBar extends DynSCP {
  transient SimpleLiveValue<S> lvInvisible = stringLiveValue();
  transient Bool vertical;
  transient ReliableSingleThread rst = new(r {
    revisualize2();
    sleepSeconds(1);
  });
  
  bool shouldBeVertical() {
    Rect r = dm_getBounds();
    ret r != null && r.h > r.w*0.3;
  }

  JComponent visualize2() {
    L<JButton> buttons = makeButtons();
    JLabel lblInvisible = onLeftClick(jLiveValueLabel(lvInvisible), r dm_showInvisibleModulesList);
    if (vertical == null) vertical = shouldBeVertical();
    ret vertical
      ? jscroll_dynamicvstack(dynamicVStack2(listPlusInBeginning(
        (L<JComponent>) (L) buttons, withMargin(6, lblInvisible))))
      : centerAndEast(hgrid(buttons), withLeftAndRightMargin(6, 3, lblInvisible));
  }
  
  enhanceFrame {
    addTitlePopupMenuItems(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) {
      print("Packing frame");
      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(); }
  
  // TODO: make less often
  L<JButton> makeButtons() {
    new L<JButton> out;
    new L invisible;
    L modules = dm_listModules();
    // TODO: get module names all at once
    for (fO m : modules)
      if (m != this)
        if (dm_isVisible(m)) {
          final WeakReference ref = new(m); // allow GC for modules
          out.add(jbutton(dm_moduleName(m), r { dm_showModule(ref!) }));
        } else invisible.add(m);
    lvInvisible.set(empty(invisible) ? "" : "+ " + l(invisible) + " invisible");

    ret out;
  }
}

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: 424 / 26609
Version history: 46 change(s)
Referenced in: [show references]