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

47
LINES

< > BotCompany Repo | #1036191 // JOnDemandWithReloadButton - generate component only when shown

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

Libraryless. Click here for Pure Java version (16271L/97K).

1  
srecord noeq JOnDemandWithReloadButton(IF0<JComponent> makeComponent) is Swingable {
2  
  SingleComponentPanel scp = singleComponentPanel();
3  
  ReliableSingleThread rstReload = rst(l0 reloadImpl);
4  
  JButton btnReload;
5  
  settable JPanel controls = rightAlignedLine();
6  
  SingleComponentPanel scpControlsMain = scp();
7  
  
8  
  settable bool loadingScreenWhenReloading;
9  
  settable bool showControls = true;
10  
  
11  
  void reload { rstReload.trigger(); }
12  
  
13  
  cachedVisualize {
14  
    bindToComponent(scp, -> {
15  
      if (scp.isEmpty()) reload();
16  
    }, null);
17  
    
18  
    if (!showControls) ret scp;
19  
    
20  
    makeControls();
21  
    ret northAndCenter(withMargin(centerAndEastWithMargin(scpControlsMain, controls)), scp);
22  
  }
23  
  
24  
  void makeControls {
25  
    if (!showControls) ret;
26  
    btnReload = jReloadButton(l0 reload);
27  
    controls.add(btnReload);
28  
  }
29  
    
30  
  void reloadImpl {
31  
    temp tempDisableButton(btnReload);
32  
    
33  
    if (loadingScreenWhenReloading() || !scp.hasComponent())
34  
      scp.setComponent(jCenteredLabel("Loading..."));
35  
      
36  
    try {
37  
      scp.setComponent(makeComponent?!);
38  
    } catch print e {
39  
      scp.setComponent(jscroll(jFastLogView_noWrap(renderStackTrace(e)));
40  
    }
41  
  }
42  
  
43  
  selfType function(IF0 f) {
44  
    makeComponent = -> wrap(f?!);
45  
    this;
46  
  }
47  
}

Author comment

Began life as a copy of #1034024

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036191
Snippet name: JOnDemandWithReloadButton - generate component only when shown
Eternal ID of this version: #1036191/13
Text MD5: cc21a4bf9b81a56ba7e4d51bad7ecf17
Transpilation MD5: 50a45df00ef46cdf84c809971f33d0c2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-12-11 18:46:57
Source code size: 1301 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 187 / 295
Version history: 12 change(s)
Referenced in: [show references]