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

33
LINES

< > BotCompany Repo | #1033687 // ScreenSelectorRadioButtons

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

Libraryless. Click here for Pure Java version (8162L/47K).

srecord noeq ScreenSelectorRadioButtons(SimpleLiveValue<Int> lvScreenNr) is Swingable {
  transient ButtonGroup radioButtons;
  transient SingleComponentPanel scp;
  settable bool compactLayout;
  settable bool hideIfOnlyOne;
  settable S screenLabel = "Screen";
  
  visual swing(-> {
    if (scp == null) {
      scp = singleComponentPanel();
      awtEveryAndNow(scp, 5.0, r updateScreenCount);
    }
    
    var n = screenCount();
    radioButtons = jRadioButtons(
      countIteratorAsList(n,
        i -> (compactLayout ? "": screenLabel + " ") + (i+1)));
    setRadioButtonToolTips(radioButtons, i -> "Select screen " + (i+1));
    selectRadioButton(radioButtons, lvScreenNr!);
    onRadioButtonChange(radioButtons, i -> lvScreenNr.set(i));
    scp.setComponent(compactLayout
      ? hideIfOnlyOne && n == 1 ? null
        : hstack(flattenList2(nempty(screenLabel) ? jlabel(screenLabel) : null, buttonsInGroup(radioButtons)))
      : jline(flattenList2(buttonsInGroup(radioButtons))));
      
    ret scp;
  });
  
  void updateScreenCount() {
    if (radioButtons != null && radioButtons.getButtonCount() != screenCount())
      visualize();
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1033687
Snippet name: ScreenSelectorRadioButtons
Eternal ID of this version: #1033687/20
Text MD5: 8b52a1bc23627b8a2e608dac9d191fda
Transpilation MD5: eec17c068ca583e70d8e9a131fbea2cf
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-12-29 16:19:05
Source code size: 1188 bytes / 33 lines
Pitched / IR pitched: No / No
Views / Downloads: 188 / 352
Version history: 19 change(s)
Referenced in: [show references]