com.threerings.media.animation
Class AnimationSequencer

java.lang.Object
  extended by com.threerings.media.AbstractMedia
      extended by com.threerings.media.animation.Animation
          extended by com.threerings.media.animation.AnimationSequencer
All Implemented Interfaces:
Shape

public class AnimationSequencer
extends Animation

An animation that provides facilities for adding a sequence of animations that are fired after a fixed time interval has elapsed or after previous animations in the sequence have completed. Facilities are also provided for running code upon the completion of animations in the sequence.


Nested Class Summary
protected  class AnimationSequencer.AnimRecord
           
 
Nested classes/interfaces inherited from class com.threerings.media.animation.Animation
Animation.AnimCompletedOp, Animation.AnimStartedOp
 
Field Summary
protected  AnimationManager _animmgr
          The animation manager in which we run animations.
protected  long _lastStamp
          The timestamp at which we fired the last animation.
protected  ArrayList<AnimationSequencer.AnimRecord> _queued
          Animations that have not been fired.
protected  ArrayList<AnimationSequencer.AnimRecord> _running
          Animations that are currently running.
protected  int _vdx
          Used to track view scrolling while animations are in limbo.
protected  int _vdy
          Used to track view scrolling while animations are in limbo.
 
Fields inherited from class com.threerings.media.animation.Animation
_finished
 
Fields inherited from class com.threerings.media.AbstractMedia
_bounds, _firstTick, _mgr, _observers, _renderOrder, HUD_LAYER
 
Constructor Summary
AnimationSequencer(AnimationManager animmgr)
          Constructs an animation sequencer with the expectation that animations will be added via subsequent calls to addAnimation(com.threerings.media.animation.Animation, long, java.lang.Runnable).
 
Method Summary
 void addAnimation(Animation anim)
          Convenience wrapper to add an animation to run at the same time as the previous one.
 void addAnimation(Animation anim, long delta, Runnable completionAction)
          Adds the supplied animation to the sequence with the given parameters.
 void appendAnimation(Animation anim)
          Convenience wrapper to add an animation to run after the previous one.
 void clear()
          Clears out the animations being managed by this sequencer.
 void fastForward(long timeDelta)
          Called when the appropriate media manager has been paused for some length of time and is then unpaused.
 void paint(Graphics2D gfx)
          Called by the appropriate manager to request that the media render itself with the given graphics context.
protected  void startAnimation(Animation anim, long tickStamp)
          Called when the time comes to start an animation.
 void tick(long tickStamp)
          Called periodically by this media's manager to give it a chance to do its thing.
 void viewLocationDidChange(int dx, int dy)
          Called by the AbstractMediaManager when we are in a VirtualMediaPanel that just scrolled.
 
Methods inherited from class com.threerings.media.animation.Animation
addAnimationObserver, didFinish, isFinished, removeAnimationObserver, reset, setLocation, willFinish, willStart
 
Methods inherited from class com.threerings.media.AbstractMedia
addObserver, contains, contains, contains, contains, getBounds, getBounds2D, getPathIterator, getPathIterator, getRenderOrder, init, init, intersects, intersects, invalidate, invalidateAfterChange, naturalCompareTo, queueNotification, removeObserver, renderCompareTo, setRenderOrder, shutdown, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_animmgr

protected AnimationManager _animmgr
The animation manager in which we run animations.


_queued

protected ArrayList<AnimationSequencer.AnimRecord> _queued
Animations that have not been fired.


_running

protected ArrayList<AnimationSequencer.AnimRecord> _running
Animations that are currently running.


_lastStamp

protected long _lastStamp
The timestamp at which we fired the last animation.


_vdx

protected int _vdx
Used to track view scrolling while animations are in limbo.


_vdy

protected int _vdy
Used to track view scrolling while animations are in limbo.

Constructor Detail

AnimationSequencer

public AnimationSequencer(AnimationManager animmgr)
Constructs an animation sequencer with the expectation that animations will be added via subsequent calls to addAnimation(com.threerings.media.animation.Animation, long, java.lang.Runnable).

Parameters:
animmgr - the animation manager to which to add our animations when they are ready to start.
Method Detail

addAnimation

public void addAnimation(Animation anim,
                         long delta,
                         Runnable completionAction)
Adds the supplied animation to the sequence with the given parameters. Note that care should be taken if this is called after the animation sequence has begun firing animations. Do not add new animations after the final animation in the sequence has been started or you run the risk of attempting to add an animation to the sequence after it thinks that it has finished (in which case this method will fail).

Parameters:
anim - the animation to be sequenced, or null if the completion action should be run immediately when this "animation" is ready to fired.
delta - the number of milliseconds following the start of the previous animation in the queue that this animation should be started; 0 if it should be started simultaneously with its predecessor in the queue; -1 if it should be started when its predecessor has completed.
completionAction - a runnable to be executed when this animation completes.

addAnimation

public void addAnimation(Animation anim)
Convenience wrapper to add an animation to run at the same time as the previous one.


appendAnimation

public void appendAnimation(Animation anim)
Convenience wrapper to add an animation to run after the previous one.


clear

public void clear()
Clears out the animations being managed by this sequencer.


tick

public void tick(long tickStamp)
Description copied from class: AbstractMedia
Called periodically by this media's manager to give it a chance to do its thing.

Specified by:
tick in class AbstractMedia
Parameters:
tickStamp - a time stamp associated with this tick. Note: this is not obtained from a call to System.currentTimeMillis() and cannot be compared to timestamps obtained there from.

paint

public void paint(Graphics2D gfx)
Description copied from class: AbstractMedia
Called by the appropriate manager to request that the media render itself with the given graphics context. The media may wish to inspect the clipping region that has been set on the graphics context to render itself more efficiently. This method will only be called after it has been established that this media's bounds intersect the clipping region.

Specified by:
paint in class AbstractMedia

fastForward

public void fastForward(long timeDelta)
Description copied from class: AbstractMedia
Called when the appropriate media manager has been paused for some length of time and is then unpaused. Media should adjust any time stamps that are maintained internally forward by the delta so that time maintains the illusion of flowing smoothly forward.

Overrides:
fastForward in class AbstractMedia

viewLocationDidChange

public void viewLocationDidChange(int dx,
                                  int dy)
Description copied from class: AbstractMedia
Called by the AbstractMediaManager when we are in a VirtualMediaPanel that just scrolled.

Overrides:
viewLocationDidChange in class AbstractMedia

startAnimation

protected void startAnimation(Animation anim,
                              long tickStamp)
Called when the time comes to start an animation. Derived classes may override this method and pass the animation on to their animation manager and do whatever else they need to do with operating animations. The default implementation simply adds them to the media panel supplied when we were constructed.

Parameters:
anim - the animation to be displayed.
tickStamp - the timestamp at which this animation was fired.