summaryrefslogtreecommitdiffstats
path: root/examples/org.eclipse.swt.examples.paint/src
diff options
context:
space:
mode:
authorJeff Brown <jbrown>2001-06-28 23:05:36 +0000
committerJeff Brown <jbrown>2001-06-28 23:05:36 +0000
commita00c4e1f66e67aec4dc29233162965c7f8c70ce4 (patch)
tree9d24148209c53573182c6369230fb49547949dcf /examples/org.eclipse.swt.examples.paint/src
parent188fe2f5cffd36c8c2bfd5270ff9b50827c1adb1 (diff)
downloadeclipse.platform.swt-a00c4e1f66e67aec4dc29233162965c7f8c70ce4.tar.gz
eclipse.platform.swt-a00c4e1f66e67aec4dc29233162965c7f8c70ce4.tar.xz
eclipse.platform.swt-a00c4e1f66e67aec4dc29233162965c7f8c70ce4.zip
*** empty log message ***
Diffstat (limited to 'examples/org.eclipse.swt.examples.paint/src')
-rwxr-xr-xexamples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContinuousPaintSession.java39
1 files changed, 14 insertions, 25 deletions
diff --git a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContinuousPaintSession.java b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContinuousPaintSession.java
index abbe320b64..22aa5eb1d9 100755
--- a/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContinuousPaintSession.java
+++ b/examples/org.eclipse.swt.examples.paint/src/org/eclipse/swt/examples/paint/ContinuousPaintSession.java
@@ -28,9 +28,9 @@ public abstract class ContinuousPaintSession extends BasicPaintSession {
private int retriggerInterval = 0;
/**
- * A unique identifier used to track RetriggerHandlers
+ * The currently valid RetriggerHandler
*/
- protected int retriggerId = 0;
+ protected Runnable retriggerHandler = null;
/**
* Constructs a ContinuousPaintSession.
@@ -193,13 +193,21 @@ public abstract class ContinuousPaintSession extends BasicPaintSession {
* timerExec() provides a lightweight mechanism for running code at intervals from within
* the event loop when timing accuracy is not important.
*
- * Since it is not possible to cancel a timerExec(), we tag the Runnable's with an
- * identifier in order to distinguish the valid one from the stale ones. In practice,
+ * Since it is not possible to cancel a timerExec(), we remember the Runnable that is
+ * active in order to distinguish the valid one from the stale ones. In practice,
* if the interval is 1/100th of a second, then creating a few hundred new RetriggerHandlers
* each second will not cause a significant performance hit.
*/
Display display = getPaintSurface().getDisplay();
- display.timerExec(retriggerInterval, new RetriggerHandler(++retriggerId));
+ retriggerHandler = new Runnable() {
+ public void run() {
+ if (retriggerHandler == this) {
+ render(points[0]);
+ prepareRetrigger();
+ }
+ }
+ };
+ display.timerExec(retriggerInterval, retriggerHandler);
}
}
@@ -207,26 +215,7 @@ public abstract class ContinuousPaintSession extends BasicPaintSession {
* Aborts the retrigger timer
*/
private final void abortRetrigger() {
- ++retriggerId;
- }
-
- /**
- * Handles possible retrigger events generated by timerExec().
- */
- private class RetriggerHandler implements Runnable {
- int id;
- public RetriggerHandler(int id) {
- this.id = id;
- }
- public void run() {
- /*
- * If the id's don't match, then we have cancelled the timed operation.
- */
- if (retriggerId == id) {
- render(points[0]);
- prepareRetrigger();
- }
- }
+ retriggerHandler = null;
}
/**