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)

1  
static int awtOnConceptChanges_defaultDelay = 500;
2  
3  
static new ThreadLocal<Concepts> awtOnConceptChanges_concepts;
4  
5  
static void awtOnConceptChanges(Component component, O runnable) {
6  
  awtOnConceptChanges(componentToJComponent(component), runnable, true);
7  
}
8  
9  
static void awtOnConceptChanges(JComponent component, final O runnable, bool runOnFirstTime) {
10  
  awtOnConceptChanges(component, awtOnConceptChanges_defaultDelay, 0, runnable, runOnFirstTime);
11  
}
12  
13  
static void awtOnConceptChanges(JComponent component, int delay, final O runnable) {
14  
  awtOnConceptChanges(component, delay, delay, runnable);
15  
}
16  
  
17  
static void awtOnConceptChanges(JComponent component, int delay, int firstDelay, O runnable) {
18  
  awtOnConceptChanges(component, delay, firstDelay, runnable, true);
19  
}
20  
21  
sbool awtOnConceptChanges_debug;
22  
23  
static void awtOnConceptChanges(JComponent component, int delay, int firstDelay, final O runnable, final bool runOnFirstTime) {
24  
  final Concepts concepts = or(awtOnConceptChanges_concepts!, db_mainConcepts());
25  
  installTimer(component, delay, firstDelay, new Runnable {
26  
    long c = runOnFirstTime ? -1 : concepts.changes;
27  
    bool skip;
28  
    
29  
    public void run() {
30  
      long _c = concepts.changes;
31  
      if (awtOnConceptChanges_debug)
32  
        print("awtOnConceptChanges: " + _c + " / " + c);
33  
      if (skip) skip = false;        
34  
      else if (_c != c) {
35  
        c = _c;
36  
        call(runnable);
37  
        skip = true;
38  
      }
39  
    }
40  
  });
41  
}

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: 552 / 582
Version history: 4 change(s)
Referenced in: [show references]