Package org.opensourcephysics.controls
Class AbstractSimulation
java.lang.Object
org.opensourcephysics.controls.AbstractAnimation
org.opensourcephysics.controls.AbstractSimulation
- All Implemented Interfaces:
Runnable
,javajs.async.SwingJSUtils.StateMachine
,Animation
,Simulation
public abstract class AbstractSimulation
extends AbstractAnimation
implements Simulation, javajs.async.SwingJSUtils.StateMachine
AbstractSimulation is a template for SIP simulations.
AbstractSimulation creates and manages an animation thread that
invokes the abstract "doStep()" method every 1/10 second. The doStep method is also called when
the stepAnimation button is pressed.
Implement the doStep method to create a concrete simulation.
- Version:
- 1.0
- Author:
- Wolfgang Christian
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SimControl
protected boolean
protected int
protected int
Fields inherited from class org.opensourcephysics.controls.AbstractAnimation
animationThread, decimalFormat, delayTime, mainFrame, sciFormat
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
enableStepsPerDisplay
(boolean enable) Enables the steps per display variable in the control;Gets this simulation's control.static XML.ObjectLoader
Returns an XML.ObjectLoader to save and load data for this object.int
Gets number of animation steps that have been performed since the last initializeAnimation.int
Gets the number of animation steps before animated drawing panels are rendered.void
Initializes the simulation.void
Deprecated.void
reset()
Resets the simulation to its default state.void
Deprecated.void
run()
Implementation of Runnable interface.void
setControl
(Control control) Sets the Control for this model and initializes the control's values.void
setStepsPerDisplay
(int num) Sets the number of animation steps before animated drawing panels are rendered.void
start()
Starts the simulation.void
Deprecated.void
Performs an action before executing one or more animation steps.final void
Starts the simulation thread.boolean
final void
Steps the simulation.void
stop()
Stops the simulation.void
Deprecated.void
Performs an action after executing one or more animation steps.final void
Stops the simulation thread.Methods inherited from class org.opensourcephysics.controls.AbstractAnimation
addChildFrame, clearChildFrames, doStep, getChildFrames, getDelayTime, getMainFrame, getMainFrameSize, getOSPApp, isRunning, setDelayTime
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opensourcephysics.controls.Simulation
isRunning
-
Field Details
-
control
-
showStepsPerDisplay
protected boolean showStepsPerDisplay -
stepsPerDisplay
protected int stepsPerDisplay -
stepCounter
protected int stepCounter
-
-
Constructor Details
-
AbstractSimulation
public AbstractSimulation()
-
-
Method Details
-
setControl
Sets the Control for this model and initializes the control's values.- Specified by:
setControl
in interfaceAnimation
- Overrides:
setControl
in classAbstractAnimation
- Parameters:
control
-
-
getControl
Gets this simulation's control.- Overrides:
getControl
in classAbstractAnimation
- Returns:
- Control
-
startRunning
public void startRunning()Performs an action before executing one or more animation steps. -
stopRunning
public void stopRunning()Performs an action after executing one or more animation steps. -
startAnimation
Deprecated.Invokes the simulation's start method and then starts the animation thread. Simulations should not override this method. Override the start method to perform custom actions just before a thread starts.- Specified by:
startAnimation
in interfaceAnimation
- Overrides:
startAnimation
in classAbstractAnimation
-
startSimulation
public final void startSimulation()Starts the simulation thread. Unlike the startAnimation method cannot be overridden so it is not deprecated.- Specified by:
startSimulation
in interfaceSimulation
-
start
public void start()Starts the simulation. Override this method to perform custom actions before the animation thread begins running. -
stopAnimation
Deprecated.Stops the animation thread and then invokes the simulations stop method.\ Simulations should not override this method. They should override the stop method.- Specified by:
stopAnimation
in interfaceAnimation
- Overrides:
stopAnimation
in classAbstractAnimation
-
stopSimulation
public final void stopSimulation()Stops the simulation thread. This method cannot be overridden so it is not deprecated.- Specified by:
stopSimulation
in interfaceSimulation
-
stop
public void stop()Stops the simulation. Override this method to perform custom actions after the animation thread stops running. -
stepAnimation
public final void stepAnimation()Steps the simulation. This method is final in order to insure that all AbsractSimulations invoke startRunning(), doStep(), stepCounter++ and stopRunning() in the correct order.- Specified by:
stepAnimation
in interfaceAnimation
- Overrides:
stepAnimation
in classAbstractAnimation
-
initializeAnimation
Deprecated.Initializes the animation. Simulations should invoke the initialize method.- Specified by:
initializeAnimation
in interfaceAnimation
- Overrides:
initializeAnimation
in classAbstractAnimation
-
getStepCounter
public int getStepCounter()Gets number of animation steps that have been performed since the last initializeAnimation.- Returns:
- stepCounter
-
initialize
public void initialize()Initializes the simulation. Override this method to initialize a concrete simulation. -
resetAnimation
Deprecated.Resets the animation to its default condition. Simulations should invoke the reset method.- Specified by:
resetAnimation
in interfaceAnimation
- Overrides:
resetAnimation
in classAbstractAnimation
-
enableStepsPerDisplay
public void enableStepsPerDisplay(boolean enable) Enables the steps per display variable in the control;- Parameters:
enable
- boolean
-
setStepsPerDisplay
public void setStepsPerDisplay(int num) Sets the number of animation steps before animated drawing panels are rendered. The default steps per animation is 1. Increase this number if frequent rendering causes sluggish behavior.- Parameters:
num
- int
-
getStepsPerDisplay
public int getStepsPerDisplay()Gets the number of animation steps before animated drawing panels are rendered.- Parameters:
num
- int
-
reset
public void reset()Resets the simulation to its default state. Override this method to set the simulation's parameters. -
stateLoop
public boolean stateLoop()- Specified by:
stateLoop
in interfacejavajs.async.SwingJSUtils.StateMachine
- Overrides:
stateLoop
in classAbstractAnimation
-
run
public void run()Implementation of Runnable interface. DO NOT access this method directly.- Specified by:
run
in interfaceRunnable
- Overrides:
run
in classAbstractAnimation
-
getLoader
Returns an XML.ObjectLoader to save and load data for this object.- Returns:
- the object loader
-