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

39
LINES

< > BotCompany Repo | #1034552 // JImageSwitch - like a checkbox but showing one of two images

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

Transpiled version (8342L) is out of date.

sclass JImageSwitch > JLabel {
  S onImageID, offImageID;
  S offToolTip, onToolTip;
  IVarWithNotify<Bool> var;
  bool on;
  InstantNeverHideToolTip toolTip;
  
  *(S *onImageID, S *offImageID, IVarWithNotify<Bool> *var) {
    toolTip = new InstantNeverHideToolTip(this);
    bindListenerToComponent(this, var, r { set(var!) });
    on = var!;
    updateIcon();
    onLeftClick(this, l0 flip);
  }
  
  selfType setToolTips(S onToolTip, S offToolTip) {
    this.onToolTip = onToolTip;
    this.offToolTip = offToolTip;
    updateIcon();
    this;
  }
  
  void updateIcon {  
    toolTip.setText(on ? onToolTip : offToolTip);
    setIcon(imageIcon(loadImage2_cached(on ? onImageID : offImageID)));
  }
  
  void flip { set(!on); }
  
  void set(bool value) swing {
    if (on != value) {
      on = value;
      updateIcon();
      var.set(on);
    }
  }
  
  bool isOn() { ret on; }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1034552
Snippet name: JImageSwitch - like a checkbox but showing one of two images
Eternal ID of this version: #1034552/20
Text MD5: c70699cab3c5e9f0e16aebb407d439e3
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-12 21:52:53
Source code size: 924 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 176 / 352
Version history: 19 change(s)
Referenced in: [show references]