edu.umd.cs.jazz.animation
Class ZAnimationScheduler

java.lang.Object
  |
  +--edu.umd.cs.jazz.animation.ZAnimationScheduler
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class ZAnimationScheduler
extends java.lang.Object
implements java.awt.event.ActionListener

ZAnimationScheduler schedules the frames of ZAnimations. It uses a timer firing from the event dispatch thread, each time the timer fires it animates one frame from all animations that have been scheduled and are ready to animate at that time.

Normally you will not need to use this class directly, unless you are creating your own custom subclass of ZAnimation. This class is a singleton, only one instance should ever exist at the same time. This instance is accessed through the instance method.

Author:
Jesse Grosjean

Constructor Summary
protected ZAnimationScheduler()
          Construct a new ZAnimationScheduler.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          This method is called when the timer fires.
protected  java.util.Iterator getAnimationsToProcessForCurrentFrame()
          Return an iterator for all animations that should be animated for the current frame.
 long getCurrentFrame()
          Return the current frame this the animation scheduler is or will soon be drawing.
 long getCurrentTime()
          Return the current time for the animation scheduler.
 int getFrameDelay()
          Return the delay between each frame that gets animated.
protected  javax.swing.Timer getTimer()
          Return the animation schedulers timer.
static ZAnimationScheduler instance()
          Return a reference to the singleton animation scheduler.
 boolean isAnimationSchedulerRunning()
          Return true if the animation scheduler's timer is running.
 void processAnimations(long aTime)
          This method first sets the current time (returned by getCurrentTime) to the aTime parameter.
 void scheduleAnimation(ZAnimation aAnimation, ZNextFrameCondition aCondition)
          Schedule an animation together with its frame condition.
 void setFrameDelay(int aDelay)
          Set the delay between each frame that gets animated.
 void setFrameEndedRunnable(java.lang.Runnable aRunnable)
          Set a runnable that will be run when all the animations for one frame have finished.
protected  void startAnimationScheduler()
          Start the timer that drives this animation scheduler.
protected  void stopAnimationScheduler()
          Start the timer that drives this animation scheduler.
 void stopPendingAnimations()
          Forces all animations that are in the queue's to be stopped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZAnimationScheduler

protected ZAnimationScheduler()
Construct a new ZAnimationScheduler. This is protected because instance should be used instead.

Method Detail

instance

public static ZAnimationScheduler instance()
Return a reference to the singleton animation scheduler.


getCurrentTime

public long getCurrentTime()
Return the current time for the animation scheduler. All animations should use this instead of System.currentTimeMillis(). This will make sure that all animations in the system are synchronized.


getCurrentFrame

public long getCurrentFrame()
Return the current frame this the animation scheduler is or will soon be drawing.


getFrameDelay

public int getFrameDelay()
Return the delay between each frame that gets animated. If the animations take a long time to animate the actual frame delay may be greater then this value.


setFrameDelay

public void setFrameDelay(int aDelay)
Set the delay between each frame that gets animated. If the animations take a long time to animate the actual frame delay may be greater then this value.


scheduleAnimation

public void scheduleAnimation(ZAnimation aAnimation,
                              ZNextFrameCondition aCondition)
Schedule an animation together with its frame condition. Normally this will be done automatically by ZAnimation.play. NOTE the current implementation requires that the aCondition parameter inherits from either ZNextFrameOnElapsedTime or ZNextFrameOnElapsedFrames.


processAnimations

public void processAnimations(long aTime)
This method first sets the current time (returned by getCurrentTime) to the aTime parameter. Next it gets all animations that are ready to animate at that time or for the current frame and animates one frame for each one. Last of all it increments the current frame.


getAnimationsToProcessForCurrentFrame

protected java.util.Iterator getAnimationsToProcessForCurrentFrame()
Return an iterator for all animations that should be animated for the current frame. The values of getCurrentFrame and getCurrentTime are used to determine if an animation is ready to be animated for the current frame. Since all animations use these common values animates that are scheduled to start at the same time will always start animating in the same frame.


isAnimationSchedulerRunning

public boolean isAnimationSchedulerRunning()
Return true if the animation scheduler's timer is running.


stopPendingAnimations

public void stopPendingAnimations()
Forces all animations that are in the queue's to be stopped.


startAnimationScheduler

protected void startAnimationScheduler()
Start the timer that drives this animation scheduler.


stopAnimationScheduler

protected void stopAnimationScheduler()
Start the timer that drives this animation scheduler.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
This method is called when the timer fires. This method in turn calls processAnimations with the current time.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

getTimer

protected javax.swing.Timer getTimer()
Return the animation schedulers timer.


setFrameEndedRunnable

public void setFrameEndedRunnable(java.lang.Runnable aRunnable)
Set a runnable that will be run when all the animations for one frame have finished.



Copyright � 2003 by University of Maryland, College Park, MD 20742, USA All rights reserved.