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

64
LINES

< > BotCompany Repo | #1036474 // JContentAndControls

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

Transpiled version (18082L) is out of date.

sclass JContentAndControls is Swingable, Updateable {
  settable IF0/*<JComponent or Swingable>*/ makeContent;
  SingleComponentPanel scpContent = singleComponentPanel();
  ReliableSingleThread rstReloadContent = rst(l0 reloadImpl);
  settable JButton btnReload;
  gettable DynamicHStack controls = dynamicHStack();
  gettable JPanel rightCornerControls = jline();
  SingleComponentPanel scpControls = singleComponentPanel(jfullcenter(controls));
  
  settable bool loadingScreenWhenReloading;
  settable bool showControls = true;
  settable bool showReloadButton = true;
  
  public void reload aka update() { rstReloadContent.trigger(); }
  
  cachedVisualize {
    onComponentShown(scpContent, -> { if (scpContent.isEmpty()) reload(); });
    
    if (!showControls) ret scpContent;
    
    if (showReloadButton) {
      btnReload = jReloadButton(l0 reload);
      add(rightCornerControls, btnReload);
    }
    
    ret northAndCenter(withMargin(
      centerAndEastWithMargin(scpControls, rightCornerControls)), scpContent);
  }
  
  swappable JComponent makeLoadingScreen() {
    ret jCenteredLabel("Loading...");
  }
    
  void reloadImpl {
    temp tempDisableButton(btnReload);
    
    if (loadingScreenWhenReloading() || !scpContent.hasComponent())
      scpContent.set(makeLoadingScreen());
      
    try {
      scpContent.set(wrap(makeContent?!));
    } catch print e {
      scpContent.set(jErrorView(e));
    }
  }
  
  selfType addControl(S label, JComponent etc control) {
    ret addControl(withLabel(label, control));
  }
  
  selfType addControl(JComponent etc control) {
    controls.addComponent(control);
    this;
  }
  
  selfType content(IF0 makeContent) {
    ret makeContent(makeContent);
  }
  
  selfType addControlLine(JComponent newControls) {
    scpControls.set(centerAndSouthWithMargin(scpControls!, newControls);
    this;
  }
}

Author comment

Began life as a copy of #1036191

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1036474
Snippet name: JContentAndControls
Eternal ID of this version: #1036474/29
Text MD5: 5e3f74676772621b75a4a30b827024da
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-08-08 23:46:39
Source code size: 1931 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 209 / 389
Version history: 28 change(s)
Referenced in: [show references]