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 Details

    • control

      protected SimControl control
    • showStepsPerDisplay

      protected boolean showStepsPerDisplay
    • stepsPerDisplay

      protected int stepsPerDisplay
    • stepCounter

      protected int stepCounter
  • Constructor Details

    • AbstractSimulation

      public AbstractSimulation()
  • Method Details

    • 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

      @Deprecated 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

      @Deprecated 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

      @Deprecated 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

      @Deprecated 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 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 interface javajs.async.SwingJSUtils.StateMachine
      Overrides:
      stateLoop in class AbstractAnimation
    • run

      public void run()
      Implementation of Runnable interface. DO NOT access this method directly.
      Specified by:
      run in interface 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