From 76145eca17724f86e6a16e20b4b6e7ca5d39da34 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 15 Oct 2011 07:24:02 +0200 Subject: NEWT/EDTUtil: Allow get/set poll period, defaults to defaultEDTPollPeriod --- src/newt/classes/com/jogamp/newt/util/EDTUtil.java | 12 +++++++++++- src/newt/classes/jogamp/newt/DefaultEDTUtil.java | 11 ++++++++++- src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java | 14 +++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) (limited to 'src/newt/classes') diff --git a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java index d1a11a788..4493e2781 100644 --- a/src/newt/classes/com/jogamp/newt/util/EDTUtil.java +++ b/src/newt/classes/com/jogamp/newt/util/EDTUtil.java @@ -49,8 +49,18 @@ package com.jogamp.newt.util; */ public interface EDTUtil { - public static final long defaultEDTPollGranularity = 10; // 10ms, 1/100s + public static final long defaultEDTPollPeriod = 10; // 10ms, 1/100s + /** + * @return poll period in milliseconds + */ + public long getPollPeriod(); + + /** + * @param ms poll period in milliseconds + */ + public void setPollPeriod(long ms); + /** * Create a new EDT. One should invoke reset()
* after invokeStop(..) in case another start() or invoke(..) diff --git a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java index 0bcd3323c..fd757fba6 100644 --- a/src/newt/classes/jogamp/newt/DefaultEDTUtil.java +++ b/src/newt/classes/jogamp/newt/DefaultEDTUtil.java @@ -55,6 +55,7 @@ public class DefaultEDTUtil implements EDTUtil { private String name; int start_iter=0; private Runnable dispatchMessages; + private static long pollPeriod = EDTUtil.defaultEDTPollPeriod; public DefaultEDTUtil(ThreadGroup tg, String name, Runnable dispatchMessages) { this.threadGroup = tg; @@ -64,6 +65,14 @@ public class DefaultEDTUtil implements EDTUtil { this.edt.setDaemon(true); // don't stop JVM from shutdown .. } + final public long getPollPeriod() { + return pollPeriod; + } + + final public void setPollPeriod(long ms) { + pollPeriod = ms; + } + public final void reset() { synchronized(edtLock) { waitUntilStopped(); @@ -271,7 +280,7 @@ public class DefaultEDTUtil implements EDTUtil { // wait for tasks if(!shouldStop && tasks.size()==0) { try { - tasks.wait(defaultEDTPollGranularity); + tasks.wait(pollPeriod); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java index cca1e321c..6d0b102c7 100644 --- a/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java +++ b/src/newt/classes/jogamp/newt/driver/awt/AWTEDTUtil.java @@ -29,7 +29,6 @@ package jogamp.newt.driver.awt; import java.awt.EventQueue; -import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -49,7 +48,8 @@ public class AWTEDTUtil implements EDTUtil { private static TimerTask pumpMessagesTimerTask=null; private static final Map pumpMessageDisplayMap = new HashMap(); private static AWTEDTUtil singletonMainThread = new AWTEDTUtil(); // one singleton MainThread - + private static long pollPeriod = EDTUtil.defaultEDTPollPeriod; + public static AWTEDTUtil getSingleton() { return singletonMainThread; } @@ -58,6 +58,14 @@ public class AWTEDTUtil implements EDTUtil { // package private access .. } + final public long getPollPeriod() { + return pollPeriod; + } + + final public void setPollPeriod(long ms) { + pollPeriod = ms; + } + final public void reset() { // nop AWT is always running } @@ -132,7 +140,7 @@ public class AWTEDTUtil implements EDTUtil { } } }; - pumpMessagesTimer.scheduleAtFixedRate(pumpMessagesTimerTask, 0, defaultEDTPollGranularity); + pumpMessagesTimer.scheduleAtFixedRate(pumpMessagesTimerTask, 0, pollPeriod); } pumpMessageDisplayMap.put(dpy, pumpMessage); } -- cgit v1.2.3