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

44
LINES

< > BotCompany Repo | #1000943 // class DelayedUpdate - sophisticated update triggering on AWT thread (quick fast update + full update)

JavaX fragment (include)

1  
static class DelayedUpdate {
2  
  Runnable renderer;
3  
  volatile long version;
4  
  long lastUpdate; // AWT time
5  
  int delay = 1000;
6  
  
7  
  *(Runnable *renderer) {}
8  
9  
  void trigger() {
10  
    awt {
11  
      awt_quickUpdate();
12  
    }
13  
14  
    final long n = ++version;
15  
    
16  
    javax.swing.Timer timer = new javax.swing.Timer(delay, actionListener {
17  
      awt_show(n);
18  
    });
19  
    timer.setRepeats(false);
20  
    timer.start(); 
21  
  }
22  
23  
  void awt_quickUpdate() {
24  
    if (lastUpdate < now()-delay) {
25  
      render();
26  
      lastUpdate = now(); // This can be rough, no problem
27  
    }
28  
  }
29  
30  
  void awt_show(long n) {
31  
    if (n == version) {
32  
      render();
33  
      lastUpdate = now();
34  
    }
35  
  }
36  
  
37  
  void render() {
38  
    try {
39  
      renderer.run();
40  
    } catch (Throwable e) {
41  
      e.printStackTrace();
42  
    }
43  
  }
44  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000943
Snippet name: class DelayedUpdate - sophisticated update triggering on AWT thread (quick fast update + full update)
Eternal ID of this version: #1000943/1
Text MD5: e7cb8248051a31330bd6f3e2244d9315
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-11-08 00:24:17
Source code size: 823 bytes / 44 lines
Pitched / IR pitched: No / No
Views / Downloads: 613 / 3100
Referenced in: [show references]