From 4c3e9e258fae1161949dd14828c09f387bfd53d9 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 22 Nov 2010 12:46:19 +0100 Subject: GLAnimatorControl pause()/resume() don't fail fast, return a boolean instead to simplify usage. --- src/jogl/classes/com/jogamp/opengl/util/Animator.java | 10 ++++++---- src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/jogl/classes/com') diff --git a/src/jogl/classes/com/jogamp/opengl/util/Animator.java b/src/jogl/classes/com/jogamp/opengl/util/Animator.java index 2d4727bba..31abe099d 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/Animator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/Animator.java @@ -294,9 +294,9 @@ public class Animator extends AnimatorBase { } Condition waitForStoppedCondition = new WaitForStoppedCondition(); - public synchronized void pause() { + public synchronized boolean pause() { if ( !isStartedImpl() || pauseIssued ) { - throw new GLException("Pause: Invalid state (started "+isStartedImpl()+" (true), paused "+pauseIssued+" (false) )"); + return false; } stateSync.lock(); try { @@ -306,6 +306,7 @@ public class Animator extends AnimatorBase { } notifyAll(); finishLifecycleAction(waitForPausedCondition); + return true; } private class WaitForPausedCondition implements Condition { public boolean result() { @@ -315,9 +316,9 @@ public class Animator extends AnimatorBase { } Condition waitForPausedCondition = new WaitForPausedCondition(); - public synchronized void resume() { + public synchronized boolean resume() { if ( !isStartedImpl() || !pauseIssued ) { - throw new GLException("Resume: Invalid state (started "+isStartedImpl()+" (true), paused "+pauseIssued+" (true) )"); + return false; } stateSync.lock(); try { @@ -327,6 +328,7 @@ public class Animator extends AnimatorBase { } notifyAll(); finishLifecycleAction(waitForResumeCondition); + return true; } private class WaitForResumeCondition implements Condition { public boolean result() { diff --git a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java index 447c72709..6bac1646b 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java +++ b/src/jogl/classes/com/jogamp/opengl/util/FPSAnimator.java @@ -170,9 +170,9 @@ public class FPSAnimator extends AnimatorBase { } } - public synchronized void pause() { + public synchronized boolean pause() { if (timer == null) { - throw new GLException("Not running"); + return false; } stateSync.lock(); try { @@ -183,17 +183,19 @@ public class FPSAnimator extends AnimatorBase { } finally { stateSync.unlock(); } + return true; } - public synchronized void resume() { + public synchronized boolean resume() { if (timer == null) { - throw new GLException("Not running"); + return false; } stateSync.lock(); try { startTask(); } finally { stateSync.unlock(); - } + } + return true; } } -- cgit v1.2.3