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

59
LINES

< > BotCompany Repo | #1034544 // CollapsibleLeftPanel - collapsible side panel

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (14626L/86K).

sclass CollapsibleLeftPanel > MetaWithChangeListeners is Swingable {
  settableWithVar volatile S sidePanelName;
  JComponent sideComponent, mainComponent;
  JSplitPane splitPane;
  settableWithVar volatile bool expanded;
  SingleComponentPanel scp = singleComponentPanel();
  
  *(bool *expanded, S *sidePanelName, JComponent *sideComponent, JComponent *mainComponent) {
  }
  
  void expand {
    if (scaffolding()) print("CollapsibleLeftPanel.expand");
    setExpanded(true);
  }
  
  void collapse { setExpanded(false); }
  
  scaffolded void updateScp() swing {
    if (expanded) {
      splitPane().setRightComponent(jMinWidth0(mainComponent));
      scp.set(splitPane());
    } else {
      splitPane().setRightComponent(jMinWidth0(jpanel()));
      scp.set(westAndCenterWithMargin(
        sidePanelMargins(vstack(expandButton())), mainComponent));
    }
  }
  
  JComponent expandButton() {
    ret jClickableImage_instantToolTip(#1103075, "Expand " + sidePanelName, r expand);
  }
  
  JComponent collapseButton() {
    ret jClickableImage_instantToolTip(#1103076, "Collapse " + sidePanelName, r collapse);
  }
  
  JComponent wrappedSideComponent() {
    ret sidePanelMargins(northAndCenterWithMargin(
      westAndCenterWithMargin(collapseButton(), liveValueLabel(varSidePanelName())),
      sideComponent
    ));
  }

  JSplitPane splitPane() {
    if (scaffolding()) print("splitPane " + splitPane);
    if (splitPane == null) {
      splitPane = jhsplit_minZero(0.25, wrappedSideComponent(), null);
      varExpanded().onChangeAndNow(r updateScp);
    }
    ret splitPane;
  }
  
  swappable JComponent sidePanelMargins(JComponent c) { ret c; }
  
  visualize {
    splitPane();
    ret scp;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034544
Snippet name: CollapsibleLeftPanel - collapsible side panel
Eternal ID of this version: #1034544/29
Text MD5: 8bc55321b692c6bd240f0f6d00a38011
Transpilation MD5: 5c3ab07febc1df6d8d7f109bd05eacfa
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-06-27 05:39:13
Source code size: 1770 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 226 / 416
Version history: 28 change(s)
Referenced in: [show references]