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

85
LINES

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

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

Transpiled version (15733L) is out of date.

1  
persistable sclass CollapsibleNorthPanel > MetaWithChangeListeners is Swingable {
2  
  settableWithVar volatile bool expanded;
3  
  settable double defaultSplitPoint = 0.5;
4  
  
5  
  settableWithVar volatile transient S sidePanelName;
6  
  
7  
  transient gettable JComponent sideComponent;
8  
  transient gettable JComponent mainComponent;
9  
  transient JSplitPane splitPane;
10  
  transient SingleComponentPanel scp = singleComponentPanel();
11  
  
12  
  *(bool *expanded) {}
13  
  *(bool *expanded, S *sidePanelName, JComponent *sideComponent, JComponent *mainComponent) {
14  
  }
15  
  
16  
  void init(S sidePanelName, JComponent sideComponent, JComponent mainComponent) {
17  
    this.sideComponent = sideComponent;
18  
    this.mainComponent = mainComponent;
19  
    sidePanelName(sidePanelName);
20  
  }
21  
  
22  
  void expand { setExpanded(true); }
23  
  void collapse { setExpanded(false); }
24  
  void toggle { setExpanded(!expanded); }
25  
  
26  
  scaffolded void updateScp() swing {
27  
    if (expanded) {
28  
      splitPane().setTopComponent(wrappedSideComponent());
29  
      splitPane().setBottomComponent(mainComponent);
30  
      scp.set(splitPane());
31  
    } else {
32  
      scp.set(northAndCenterWithMargin(
33  
        collapsedSidePanel(),
34  
        mainComponent));
35  
    }
36  
  }
37  
  
38  
  JComponent expandButton() {
39  
    print("Making expandButton");
40  
    ret jClickableImage_instantToolTip(#1103076, "Expand " + sidePanelName, r expand);
41  
  }
42  
  
43  
  JComponent collapseButton() {
44  
    print("Making collapseButton");
45  
    ret jClickableImage_instantToolTip(#1103104, "Collapse " + sidePanelName, r collapse);
46  
  }
47  
  
48  
  // side component plus heading in expanded view
49  
  swappable JComponent wrappedSideComponent() {
50  
    var c = northAndCenterWithMargin(
51  
      sidePanelHeading(),
52  
      sideComponent
53  
    );
54  
    ret sidePanelMargins(c);
55  
  }
56  
  
57  
  swappable JComponent collapsedSidePanel() {
58  
    ret sidePanelMargins(sidePanelHeading());
59  
  }
60  
  
61  
  JComponent expandOrCollapseButton() {
62  
    ret expanded ? collapseButton() : expandButton();
63  
  }
64  
65  
  JComponent sidePanelHeading() {  
66  
    ret rightAlignedLineWithSpacing(5,
67  
      onLeftClick(r toggle, liveValueLabel(varSidePanelName())),
68  
      expandOrCollapseButton());
69  
  }
70  
71  
  JSplitPane splitPane() {
72  
    if (splitPane == null) {
73  
      splitPane = jvsplit_minZero(defaultSplitPoint(), wrappedSideComponent(), null);
74  
      varExpanded().onChangeAndNow(r updateScp);
75  
    }
76  
    ret splitPane;
77  
  }
78  
  
79  
  swappable JComponent sidePanelMargins(JComponent c) { ret c; }
80  
  
81  
  visualize {
82  
    splitPane();
83  
    ret scp;
84  
  }
85  
}

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/18
Text MD5: d36521ca68f8c2fac10dd1d7954c4db9
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-12-11 14:35:50
Source code size: 2539 bytes / 85 lines
Pitched / IR pitched: No / No
Views / Downloads: 202 / 368
Version history: 17 change(s)
Referenced in: [show references]