Package org.opensourcephysics.controls
Class AbstractAnimation
java.lang.Object
org.opensourcephysics.controls.AbstractAnimation
- Direct Known Subclasses:
AbstractSimulation
public abstract class AbstractAnimation
extends Object
implements Animation, Runnable, javajs.async.SwingJSUtils.StateMachine
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.
- Version:
- 1.0
- Author:
- Wolfgang Christian
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Threadprotected Controlprotected DecimalFormatField decimalFormat can be used to display time and other numeric values.protected intprotected OSPFrameprotected DecimalFormatField decimalFormat can be used to display time and other numeric values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChildFrame(JFrame frame) Adds a child frame that depends on the main frame.voidClears the child frames from the main frame.protected abstract voiddoStep()Does an animation step.Gets a copy of the ChildFrames collection.Gets the Control.intGets the preferred delay time in ms between animation steps.static XML.ObjectLoaderReturns an XML.ObjectLoader to save and load data for this object.Gets the main OSPFrame.int[]Gets the Main Frame size.Gets the main OSPFrame.voidInitializes the animation by reading parameters from the control.final booleanDetermines if the animation is running.voidResets the animation to a predefined state.voidrun()Implementation of Runnable interface.voidsetControl(Control control) Sets the Control for this model and initializes the control's values.voidsetDelayTime(int delay) Sets the preferred delay time in ms between animation steps.voidStarts the animation.booleanvoidSteps the animation.voidStops the animation.
-
Field Details
-
mainFrame
-
control
-
animationThread
-
delayTime
protected int delayTime -
sciFormat
Field decimalFormat can be used to display time and other numeric values. -
decimalFormat
Field decimalFormat can be used to display time and other numeric values.
-
-
Constructor Details
-
AbstractAnimation
public AbstractAnimation()
-
-
Method Details
-
setControl
Sets the Control for this model and initializes the control's values.- Specified by:
setControlin interfaceAnimation- Parameters:
control-
-
setDelayTime
public void setDelayTime(int delay) Sets the preferred delay time in ms between animation steps.- Parameters:
delay-
-
getDelayTime
public int getDelayTime()Gets the preferred delay time in ms between animation steps.- Returns:
-
getMainFrame
Gets the main OSPFrame. The main frame will usually exit program when it is closed.- Returns:
- OSPFrame
-
getMainFrameSize
public int[] getMainFrameSize()Gets the Main Frame size. -
getOSPApp
Gets the main OSPFrame. The main frame will usually exit program when it is closed.- Returns:
- OSPFrame
-
addChildFrame
Adds a child frame that depends on the main frame. Child frames are closed when this frame is closed.- Parameters:
frame- JFrame
-
clearChildFrames
public void clearChildFrames()Clears the child frames from the main frame. -
getChildFrames
Gets a copy of the ChildFrames collection.- Returns:
- Collection
-
getControl
Gets the Control.- Returns:
- the control
-
initializeAnimation
public void initializeAnimation()Initializes the animation by reading parameters from the control.- Specified by:
initializeAnimationin interfaceAnimation
-
doStep
protected abstract void doStep()Does an animation step. -
stopAnimation
public void stopAnimation()Stops the animation. Sets animationThread to null and waits for a join with the animation thread.- Specified by:
stopAnimationin interfaceAnimation
-
isRunning
public final boolean isRunning()Determines if the animation is running.- Returns:
- boolean
-
stepAnimation
public void stepAnimation()Steps the animation.- Specified by:
stepAnimationin interfaceAnimation
-
startAnimation
public void startAnimation()Starts the animation. Use this method to start a timer or a thread.- Specified by:
startAnimationin interfaceAnimation
-
resetAnimation
public void resetAnimation()Resets the animation to a predefined state.- Specified by:
resetAnimationin interfaceAnimation
-
stateLoop
public boolean stateLoop()- Specified by:
stateLoopin interfacejavajs.async.SwingJSUtils.StateMachine
-
run
public void run()Implementation of Runnable interface. DO NOT access this method directly. -
getLoader
Returns an XML.ObjectLoader to save and load data for this object.- Returns:
- the object loader
-