org.opensourcephysics.controls
Class AbstractSimulation

java.lang.Object
  extended by org.opensourcephysics.controls.AbstractAnimation
      extended by org.opensourcephysics.controls.AbstractSimulation
All Implemented Interfaces:
java.lang.Runnable, Animation, Simulation

public abstract class AbstractSimulation
extends AbstractAnimation
implements Simulation

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
protected  SimControl control
           
protected  boolean showStepsPerDisplay
           
protected  int stepCounter
           
protected  int stepsPerDisplay
           
 
Fields inherited from class org.opensourcephysics.controls.AbstractAnimation
animationThread, decimalFormat, delayTime, mainFrame
 
Constructor Summary
AbstractSimulation()
           
 
Method Summary
 void enableStepsPerDisplay(boolean enable)
          Enables the steps per display variable in the control;
 Control getControl()
          Gets this simulation's control.
static XML.ObjectLoader getLoader()
          Returns an XML.ObjectLoader to save and load data for this object.
 int getStepCounter()
          Gets number of animation steps that have been performed since the last initializeAnimation.
 int getStepsPerDisplay()
          Gets the number of animation steps before animated drawing panels are rendered.
 void initialize()
          Initializes the simulation.
 void initializeAnimation()
          Deprecated.  
 void reset()
          Resets the simulation to its default state.
 void resetAnimation()
          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 startAnimation()
          Deprecated.  
 void startRunning()
          Performs an action before executing one or more animation steps.
 void startSimulation()
          Starts the simulation thread.
 void stepAnimation()
          Steps the simulation.
 void stop()
          Stops the simulation.
 void stopAnimation()
          Deprecated.  
 void stopRunning()
          Performs an action after executing one or more animation steps.
 void stopSimulation()
          Stops the simulation thread.
 
Methods inherited from class org.opensourcephysics.controls.AbstractAnimation
addChildFrame, clearChildFrames, doStep, getChildFrames, getDelayTime, getMainFrame, 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 Detail

control

protected SimControl control

showStepsPerDisplay

protected boolean showStepsPerDisplay

stepsPerDisplay

protected int stepsPerDisplay

stepCounter

protected int stepCounter
Constructor Detail

AbstractSimulation

public AbstractSimulation()
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
Overrides:
setControl in class AbstractAnimation
Parameters:
control -

getControl

public Control getControl()
Gets this simulation's control.

Overrides:
getControl in class AbstractAnimation
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

public void 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 interface Animation
Overrides:
startAnimation in class AbstractAnimation

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 interface Simulation

start

public void start()
Starts the simulation. Override this method to perform custom actions before the animation thread begins running.


stopAnimation

public void 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 interface Animation
Overrides:
stopAnimation in class AbstractAnimation

stopSimulation

public final void stopSimulation()
Stops the simulation thread. This method cannot be overridden so it is not deprecated.

Specified by:
stopSimulation in interface Simulation

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 interface Animation
Overrides:
stepAnimation in class AbstractAnimation

initializeAnimation

public void initializeAnimation()
Deprecated. 

Initializes the animation. Simulations should invoke the initialize method.

Specified by:
initializeAnimation in interface Animation
Overrides:
initializeAnimation in class AbstractAnimation

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

public void resetAnimation()
Deprecated. 

Resets the animation to its default condition. Simulations should invoke the reset method.

Specified by:
resetAnimation in interface Animation
Overrides:
resetAnimation in class AbstractAnimation

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 slugish 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.


run

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

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class AbstractAnimation

getLoader

public static XML.ObjectLoader getLoader()
Returns an XML.ObjectLoader to save and load data for this object.

Returns:
the object loader