-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure UI components are accessed on EDT.
- Loading branch information
1 parent
2f3cb01
commit 219633e
Showing
4 changed files
with
172 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/com/esotericsoftware/clippy/util/EventQueueRepeat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
package com.esotericsoftware.clippy.util; | ||
|
||
import java.awt.EventQueue; | ||
import java.util.TimerTask; | ||
|
||
public abstract class EventQueueRepeat { | ||
final Runnable repeatRunnable = new Runnable() { | ||
public void run () { | ||
if (repeat()) { | ||
repeatTask.cancel(); | ||
end(); | ||
} | ||
} | ||
}; | ||
|
||
final TimerTask repeatTask = new TimerTask() { | ||
public void run () { | ||
try { | ||
EventQueue.invokeLater(repeatRunnable); | ||
} catch (Exception ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
}; | ||
|
||
public void run (final int delay) { | ||
EventQueue.invokeLater(new Runnable() { | ||
public void run () { | ||
start(); | ||
Util.timer.schedule(repeatTask, delay, delay); | ||
} | ||
}); | ||
} | ||
|
||
abstract protected void start (); | ||
|
||
/** Returns true when finished. */ | ||
abstract protected boolean repeat (); | ||
|
||
abstract protected void end (); | ||
} |