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: 709 / 3191
Referenced in: #750 - x25.java (JavaX)
#1000818 - Console
#1001110 - x26.java (JavaX)
#1001148 - x27.java (JavaX)
#1001187 - Console Bot (developing)
#1001370 - x28.java (JavaX)
#1001600 - x29.java (JavaX)
#1001729 - Show console for other process (developing)
#1004305 - x31.java (JavaX)
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)