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

41
LINES

< > BotCompany Repo | #1005359 - awtOnConceptChanges - run something in AWT thread when concepts change; also runs first time

JavaX fragment (include)

static int awtOnConceptChanges_defaultDelay = 500;

static new ThreadLocal<Concepts> awtOnConceptChanges_concepts;

static void awtOnConceptChanges(Component component, O runnable) {
  awtOnConceptChanges(componentToJComponent(component), runnable, true);
}

static void awtOnConceptChanges(JComponent component, final O runnable, bool runOnFirstTime) {
  awtOnConceptChanges(component, awtOnConceptChanges_defaultDelay, 0, runnable, runOnFirstTime);
}

static void awtOnConceptChanges(JComponent component, int delay, final O runnable) {
  awtOnConceptChanges(component, delay, delay, runnable);
}
  
static void awtOnConceptChanges(JComponent component, int delay, int firstDelay, O runnable) {
  awtOnConceptChanges(component, delay, firstDelay, runnable, true);
}

sbool awtOnConceptChanges_debug;

static void awtOnConceptChanges(JComponent component, int delay, int firstDelay, final O runnable, final bool runOnFirstTime) {
  final Concepts concepts = or(awtOnConceptChanges_concepts!, db_mainConcepts());
  installTimer(component, delay, firstDelay, new Runnable {
    long c = runOnFirstTime ? -1 : concepts.changes;
    bool skip;
    
    public void run() {
      long _c = concepts.changes;
      if (awtOnConceptChanges_debug)
        print("awtOnConceptChanges: " + _c + " / " + c);
      if (skip) skip = false;        
      else if (_c != c) {
        c = _c;
        call(runnable);
        skip = true;
      }
    }
  });
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005359
Snippet name: awtOnConceptChanges - run something in AWT thread when concepts change; also runs first time
Eternal ID of this version: #1005359/5
Text MD5: acfdc7005a563abd8331be4aab776650
Author: stefan
Category: javax / concepts / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-24 00:10:09
Source code size: 1484 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 394 / 406
Version history: 4 change(s)
Referenced in: [show references]