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

81
LINES

< > BotCompany Repo | #1034942 // CollapsibleNorthPanel - collapsible panel at the north of component

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

Transpiled version (14673L) is out of date.

persistable sclass CollapsibleNorthPanel > MetaWithChangeListeners is Swingable {
  settableWithVar volatile bool expanded;
  settable double defaultSplitPoint = 0.5;
  
  settableWithVar volatile transient S sidePanelName;
  
  transient JComponent sideComponent, mainComponent;
  transient JSplitPane splitPane;
  transient SingleComponentPanel scp = singleComponentPanel();
  
  *(bool *expanded) {}
  *(bool *expanded, S *sidePanelName, JComponent *sideComponent, JComponent *mainComponent) {
  }
  
  void init(S sidePanelName, JComponent sideComponent, JComponent mainComponent) {
    this.sideComponent = sideComponent;
    this.mainComponent = mainComponent;
    sidePanelName(sidePanelName);
  }
  
  void expand { setExpanded(true); }
  void collapse { setExpanded(false); }
  void toggle { setExpanded(!expanded); }
  
  scaffolded void updateScp() swing {
    if (expanded) {
      splitPane().setTopComponent(wrappedSideComponent());
      splitPane().setBottomComponent(mainComponent);
      scp.set(splitPane());
    } else {
      var collapsedNorthPanel = sidePanelMargins(sidePanelHeading());
      scp.set(northAndCenterWithMargin(
        collapsedNorthPanel,
        mainComponent));
    }
  }
  
  JComponent expandButton() {
    print("Making expandButton");
    ret jClickableImage_instantToolTip(#1103076, "Expand " + sidePanelName, r expand);
  }
  
  JComponent collapseButton() {
    print("Making collapseButton");
    ret jClickableImage_instantToolTip(#1103104, "Collapse " + sidePanelName, r collapse);
  }
  
  // side component plus heading in expanded view
  JComponent wrappedSideComponent() {
    var c = northAndCenterWithMargin(
      sidePanelHeading(),
      sideComponent
    );
    ret sidePanelMargins(c);
  }
  
  JComponent expandOrCollapseButton() {
    ret expanded ? collapseButton() : expandButton();
  }

  JComponent sidePanelHeading() {  
    ret rightAlignedLineWithSpacing(5,
      onLeftClick(r toggle, liveValueLabel(varSidePanelName())),
      expandOrCollapseButton());
  }

  JSplitPane splitPane() {
    if (splitPane == null) {
      splitPane = jvsplit(defaultSplitPoint(), wrappedSideComponent(), null);
      varExpanded().onChangeAndNow(r updateScp);
    }
    ret splitPane;
  }
  
  swappable JComponent sidePanelMargins(JComponent c) { ret c; }
  
  visualize {
    splitPane();
    ret scp;
  }
}

Author comment

Began life as a copy of #1034544

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1034942
Snippet name: CollapsibleNorthPanel - collapsible panel at the north of component
Eternal ID of this version: #1034942/14
Text MD5: 8c3823936e58754fd6b017a6fa093154
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-14 02:38:41
Source code size: 2446 bytes / 81 lines
Pitched / IR pitched: No / No
Views / Downloads: 51 / 135
Version history: 13 change(s)
Referenced in: [show references]