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 SimControlprotected booleanprotected intprotected intFields inherited from class org.opensourcephysics.controls.AbstractAnimation
animationThread, decimalFormat, delayTime, mainFrame, sciFormat -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidenableStepsPerDisplay(boolean enable) Enables the steps per display variable in the control;Gets this simulation's control.static XML.ObjectLoaderReturns an XML.ObjectLoader to save and load data for this object.intGets number of animation steps that have been performed since the last initializeAnimation.intGets the number of animation steps before animated drawing panels are rendered.voidInitializes the simulation.voidDeprecated.voidreset()Resets the simulation to its default state.voidDeprecated.voidrun()Implementation of Runnable interface.voidsetControl(Control control) Sets the Control for this model and initializes the control's values.voidsetStepsPerDisplay(int num) Sets the number of animation steps before animated drawing panels are rendered.voidstart()Starts the simulation.voidDeprecated.voidPerforms an action before executing one or more animation steps.final voidStarts the simulation thread.booleanfinal voidSteps the simulation.voidstop()Stops the simulation.voidDeprecated.voidPerforms an action after executing one or more animation steps.final voidStops the simulation thread.Methods inherited from class org.opensourcephysics.controls.AbstractAnimation
addChildFrame, clearChildFrames, doStep, getChildFrames, getDelayTime, getMainFrame, getMainFrameSize, getOSPApp, isRunning, setDelayTimeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
setControlin interfaceAnimation- Overrides:
setControlin classAbstractAnimation- Parameters:
control-
-
getControl
Gets this simulation's control.- Overrides:
getControlin 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:
startAnimationin interfaceAnimation- Overrides:
startAnimationin classAbstractAnimation
-
startSimulation
public final void startSimulation()Starts the simulation thread. Unlike the startAnimation method cannot be overridden so it is not deprecated.- Specified by:
startSimulationin 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:
stopAnimationin interfaceAnimation- Overrides:
stopAnimationin classAbstractAnimation
-
stopSimulation
public final void stopSimulation()Stops the simulation thread. This method cannot be overridden so it is not deprecated.- Specified by:
stopSimulationin 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:
stepAnimationin interfaceAnimation- Overrides:
stepAnimationin classAbstractAnimation
-
initializeAnimation
Deprecated.Initializes the animation. Simulations should invoke the initialize method.- Specified by:
initializeAnimationin interfaceAnimation- Overrides:
initializeAnimationin 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:
resetAnimationin interfaceAnimation- Overrides:
resetAnimationin 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:
stateLoopin interfacejavajs.async.SwingJSUtils.StateMachine- Overrides:
stateLoopin classAbstractAnimation
-
run
public void run()Implementation of Runnable interface. DO NOT access this method directly.- Specified by:
runin interfaceRunnable- Overrides:
runin classAbstractAnimation
-
getLoader
Returns an XML.ObjectLoader to save and load data for this object.- Returns:
- the object loader
-