org.opensourcephysics.controls
Class AbstractAnimation

java.lang.Object
  extended byorg.opensourcephysics.controls.AbstractAnimation
All Implemented Interfaces:
Animation, java.lang.Runnable
Direct Known Subclasses:
AbstractSimulation

public abstract class AbstractAnimation
extends java.lang.Object
implements Animation, java.lang.Runnable

AbstractAnimation is a template for simple animations. Implement the doStep method to create an animation. This method is called from the run method and when the stepAnimation button is pressed.


Field Summary
protected  java.lang.Thread animationThread
           
protected  Control control
           
protected  java.text.DecimalFormat decimalFormat
          Field decimalFormat can be used to display time and other numeric values.
protected  int delayTime
           
 
Constructor Summary
AbstractAnimation()
           
 
Method Summary
protected abstract  void doStep()
          Does an animation step.
 Control getControl()
          Gets the Control.
 void initializeAnimation()
          Initializes the animation by reading parameters from the control.
 boolean isRunning()
          Determines if the animation is running.
 void resetAnimation()
          Resets the animation to a predefined state.
 void run()
          Implementation of Runnable interface.
 void setControl(Control control)
          Sets the Control for this model and initializes the control's values.
 void startAnimation()
          Starts the animation.
 void stepAnimation()
          Steps the animation.
 void stopAnimation()
          Stops the animation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

control

protected Control control

animationThread

protected volatile java.lang.Thread animationThread

delayTime

protected int delayTime

decimalFormat

protected java.text.DecimalFormat decimalFormat
Field decimalFormat can be used to display time and other numeric values.

Constructor Detail

AbstractAnimation

public AbstractAnimation()
Method Detail

setControl

public void setControl(Control control)
Sets the Control for this model and initializes the control's values.

Specified by:
setControl in interface Animation
Parameters:
control -

getControl

public Control getControl()
Gets the Control.

Returns:
the control

initializeAnimation

public void initializeAnimation()
Initializes the animation by reading parameters from the control.

Specified by:
initializeAnimation in interface Animation

doStep

protected abstract void doStep()
Does an animation step.


stopAnimation

public void stopAnimation()
Stops the animation. Sets the animationThread to null and waits for a join.

Specified by:
stopAnimation in interface Animation

isRunning

public final boolean isRunning()
Determines if the animation is running.

Returns:
boolean

stepAnimation

public void stepAnimation()
Steps the animation.

Specified by:
stepAnimation in interface Animation

startAnimation

public void startAnimation()
Starts the animation. Use this method to start a timer or a thread.

Specified by:
startAnimation in interface Animation

resetAnimation

public void resetAnimation()
Resets the animation to a predefined state.

Specified by:
resetAnimation in interface Animation

run

public void run()
Implementation of Runnable interface. DO NOT access this method directly.

Specified by:
run in interface java.lang.Runnable