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)

static class DelayedUpdate {
  Runnable renderer;
  volatile long version;
  long lastUpdate; // AWT time
  int delay = 1000;
  
  *(Runnable *renderer) {}

  void trigger() {
    awt {
      awt_quickUpdate();
    }

    final long n = ++version;
    
    javax.swing.Timer timer = new javax.swing.Timer(delay, actionListener {
      awt_show(n);
    });
    timer.setRepeats(false);
    timer.start(); 
  }

  void awt_quickUpdate() {
    if (lastUpdate < now()-delay) {
      render();
      lastUpdate = now(); // This can be rough, no problem
    }
  }

  void awt_show(long n) {
    if (n == version) {
      render();
      lastUpdate = now();
    }
  }
  
  void render() {
    try {
      renderer.run();
    } catch (Throwable e) {
      e.printStackTrace();
    }
  }
}

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: 708 / 3189
Referenced in: [show references]