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

36
LINES

< > BotCompany Repo | #1034215 // AWTOnConceptChangesByClass

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

Libraryless. Click here for Pure Java version (21570L/131K).

sclass AWTOnConceptChangesByClass is AutoCloseable {
  settable JComponent component;
  settable Runnable action;
  settable Concepts concepts;
  settable Class conceptClass;
  settable int firstDelay;
  settable int delay = 500;
  
  volatile long changes = -1, changeCounter;
  javax.swing.Timer timer;
  AutoCloseable closer;
  
  *(Concepts *concepts, Class *conceptClass, JComponent *component, Runnable *action) {}
  
  void install {
    assertNotNull(concepts);
    assertNotNull(conceptClass);
    assertNotNull(component);
    
    bindToComponent(component, ->
      closer = onConceptChangeByClass_notOnAllChanged(concepts, conceptClass, -> ++changeCounter),
      -> { dispose closer; });
      
    timer = installTimer(component, delay, firstDelay, r _trigger);
  }
  
  void _trigger {
    long c = changeCounter;
    if (changes != c) {
      changes = c;
      action?.run();
    }
  }
  
  close { dispose timer; dispose closer; }
}

Author comment

Began life as a copy of #1033869

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1034215
Snippet name: AWTOnConceptChangesByClass
Eternal ID of this version: #1034215/8
Text MD5: b0e8ee0b4089a3efa12a01fbeb13585b
Transpilation MD5: 87b86fab3e4ad07aeac97c1d90872f30
Author: stefan
Category: javax / concepts / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-12 22:28:57
Source code size: 986 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 153 / 277
Version history: 7 change(s)
Referenced in: [show references]