Search this API

y.anim
Class AnimationPlayer

java.lang.Object
  extended by y.anim.AnimationPlayer

public class AnimationPlayer
extends java.lang.Object

An animation player that interprets a given animation object.

The animation player first calls AnimationObject.initAnimation(). Then it repeatedly calls AnimationObject.calcFrame(double) with an appropriate time argument in the range 0.0 to 1.0. The animation player tries to achieve the configured target frames-per-second rate (FPS) with which it calls the calcFrame method. The actual frequency of calls, however, largely depends on the preferred duration of an animation object and the actual progress of its animation. When the animation gets stuck, frames are skipped, i.e. the FPS effectively drops. Finally, AnimationObject.disposeAnimation() gets called.

The player notifies interested parties when it begins processing animations, when a new animation frame should be displayed, and when it stops processing animations. Typically, a Graph2DView or a Graph2DViewRepaintManager is registered as an AnimationListener and triggers appropriate repaints when notified.

The player supports two modes of operation: blocking and non-blocking. In blocking mode, the player's animate method blocks until the passed in animation is completely processed. In non-blocking mode, the animate method immediately returns and subsequent calls will schedule the passed in animations for concurrent processing. While in non-blocking mode, the isPlaying method can be used to determine if the player is processing animations.

See Also:
animate(AnimationObject), isBlocking(), setBlocking(boolean), isPlaying()
 

Constructor Summary
AnimationPlayer()
          Creates a new instance of AnimationPlayer.
AnimationPlayer(boolean blocking)
          Creates a new instance of AnimationPlayer using the given blocking mode policy.
AnimationPlayer(double speedFactor)
          Creates a new instance of AnimationPlayer with the given speed factor.
AnimationPlayer(double speedFactor, boolean blocking)
          Creates a new instance of AnimationPlayer with the given speed factor and blocking mode policy.
 
Method Summary
 void addAnimationListener(AnimationListener listener)
          Adds an AnimationListener to the AnimationObject.
 void animate(AnimationObject anim)
          Processes the given AnimationObject and informs the AnimationListener whenever changes in the animation scene should be displayed.
 void decreaseSpeed()
          Decreases the speed factor of the animation by 33 percent.
 int getFps()
          Returns the target frames-per-second rate (FPS), which the player tries to achieve.
 double getSpeed()
          Returns the speed factor of the animation player.
 void increaseSpeed()
          Increases the speed factor of the animation by 50 percent.
 boolean isBlocking()
          Returns whether the player is currently in blocking mode.
 boolean isInEventDispatchThread()
          Returns true if the player is running in the AWT event dispatch thread.
 boolean isPlaying()
          Returns whether the player is currently processing animations.
 boolean isSynchronized()
          Returns whether or not the player is in synchronized mode.
 void removeAnimationListener(AnimationListener listener)
          Removes an AnimationListener from the AnimationObject.
 void setBlocking(boolean blocking)
          Specifies whether the player's animate method should block or return immediately.
 void setFps(int fps)
          Specifies the target frames-per-second rate (FPS), which the player tries to achieve.
 void setSpeed(double speedFactor)
          Sets the speed factor for the player.
 void setSynchronized(boolean sync)
          Specifies whether the player should synchronize itself with the AWT event thread.
 void stop()
          Stops the timer and disposes all animations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnimationPlayer

public AnimationPlayer()
Creates a new instance of AnimationPlayer. The newly created player will be in blocking mode and will use a speed factor of 1.0.

By default, this AnimationPlayer will synchronize with the AWT event thread and will use a target rate of 120 frames-per-second (FPS).


AnimationPlayer

public AnimationPlayer(double speedFactor,
                       boolean blocking)
Creates a new instance of AnimationPlayer with the given speed factor and blocking mode policy.

By default, this AnimationPlayer will synchronize with the AWT event thread and will use a target rate of 120 frames-per-second (FPS).


AnimationPlayer

public AnimationPlayer(double speedFactor)
Creates a new instance of AnimationPlayer with the given speed factor. The newly created player will be in blocking mode.

By default, this AnimationPlayer will synchronize with the AWT event thread and will use a target rate of 120 frames-per-second rate (FPS).


AnimationPlayer

public AnimationPlayer(boolean blocking)
Creates a new instance of AnimationPlayer using the given blocking mode policy. The newly created player will use a speed factor of 1.0.

By default, this AnimationPlayer will synchronize with the AWT event thread and will use a target rate of 120 frames-per-second (FPS).

Method Detail

addAnimationListener

public void addAnimationListener(AnimationListener listener)
Adds an AnimationListener to the AnimationObject.

Parameters:
listener - the AnimationListener to be added

removeAnimationListener

public void removeAnimationListener(AnimationListener listener)
Removes an AnimationListener from the AnimationObject.

Parameters:
listener - the AnimationListener to be removed

getFps

public int getFps()
Returns the target frames-per-second rate (FPS), which the player tries to achieve.

Returns:
The target FPS, which the player tries to achieve.

setFps

public void setFps(int fps)
Specifies the target frames-per-second rate (FPS), which the player tries to achieve.

Parameters:
fps - Target FPS, which the player tries to achieve.

isSynchronized

public boolean isSynchronized()
Returns whether or not the player is in synchronized mode.

Returns:
whether or not the player is in synchronized mode.

setSynchronized

public void setSynchronized(boolean sync)
Specifies whether the player should synchronize itself with the AWT event thread. The animation player should be used in synchronized mode whenever the player is run in a separate thread so that synchronization with the AWT event thread is necessary.


isInEventDispatchThread

public boolean isInEventDispatchThread()
Returns true if the player is running in the AWT event dispatch thread.

Returns:
true if the player is running in the AWT event dispatch thread.

isBlocking

public boolean isBlocking()
Returns whether the player is currently in blocking mode. If this method returns true, the player's animate method blocks until the passed in animation is completely processed. If this method returns false, the player's animate method immediately returns after being called and subsequent calls will result in the newly passed in animations to be processed concurrently with already scheduled ones.

Returns:
whether the player is currently in blocking mode.

setBlocking

public void setBlocking(boolean blocking)
Specifies whether the player's animate method should block or return immediately. If the player is set up to have its animate method return immediately, subsequent calls will result in the newly passed in animations to be processed concurrently with already scheduled ones.

Parameters:
blocking - if true, the player's animate method blocks; if false, the animate method will return immediately.

animate

public void animate(AnimationObject anim)
Processes the given AnimationObject and informs the AnimationListener whenever changes in the animation scene should be displayed. Depending on the blocking property, this method either blocks until the specified AnimationObject is completely processed or returns immediately and allows for additional AnimationObjects to be scheduled for concurrent processing.

Parameters:
anim - the AnimationObject to be processed
See Also:
setBlocking(boolean), isBlocking()

isPlaying

public boolean isPlaying()
Returns whether the player is currently processing animations.

Returns:
whether the player is currently processing animations.

getSpeed

public double getSpeed()
Returns the speed factor of the animation player.


setSpeed

public void setSpeed(double speedFactor)
Sets the speed factor for the player. The preferred duration is divided by the speed factor to determine the actual time the animation is running.

By default the speed factor is 1.0


increaseSpeed

public void increaseSpeed()
Increases the speed factor of the animation by 50 percent.


decreaseSpeed

public void decreaseSpeed()
Decreases the speed factor of the animation by 33 percent.


stop

public void stop()
Stops the timer and disposes all animations.


© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.