sysModel
Class SimDriver

java.lang.Object
  extended by sysModel.SimDriver

public class SimDriver
extends java.lang.Object

Simulation control coordinating interaction between view, simulation engine and environment.

Author:
Mathias Ricken

Field Summary
private  ICmdFactory _cmdFactory
          Command factory for use in the environment.
private  IEditAdapter _editAdapter
          Edit adapter.
private  AGlobalEnv _env
          Environment.
private  ILambda _iterationCommand
          Command executed after the simulation finishes an iteration.
private  MBSSecurityManager _securityManager
          Security manager.
private  ILambda _seedCommand
          Command to set the seed when a new environment is loaded or created.
private  SimEngine _simEngine
          Simulation engine.
private  ISimulationExceptionAdapter _simulationExceptionAdapter
          Simulation exception adapter.
private  int _simulationSpeed
          Simulation speed.
private  ILambda _startCommand
          Command executed before the simulation starts running.
private  javax.swing.Timer _timer
          Processing timer.
 
Constructor Summary
SimDriver()
          Construct a new model.
 
Method Summary
 boolean createEnvironment(AEnvFactory factory)
          Create environment from factory.
 void draw(java.awt.Graphics2D g, java.awt.Component comp, java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2)
          Draw model in this region.
 void edit(java.awt.geom.Point2D.Double p, int button)
          Edit a field.
 ICmdFactory getCmdFactory()
          Get the simulation engine.
 java.awt.Dimension getDisplaySize()
          Get size of the display.
 java.awt.geom.Point2D.Double getPanDelta(java.awt.geom.Point2D.Double delta)
          Ask the model how much to pan, given where the user scrolled.
 ISecurityAdapter getSecurityAdapter()
          Return the security adapter.
 java.lang.String getToolTipText(java.awt.geom.Point2D.Double p)
          Get a tool tip description for a specific place in the environment.
 java.awt.geom.Point2D.Double getViewPosition(java.awt.geom.Point2D.Double pos)
          Ask the model where to scroll, given where the user has scrolled.
 boolean loadEnvironment(java.lang.String filename)
          Load environment from file.
 void returnHome(IScrollAdapter sa)
          The action to be executed if the display should return home.
 boolean saveEnvironment(java.lang.String filename)
          Save environment to file.
 void setAdapters(IEditAdapter ea, ISimulationExceptionAdapter sea)
          Set adapters.
 void setIterationLambda(ILambda itCmd)
          Set simulation iteration command.
 void setSeedLambda(ILambda seedCmd)
          Set the seed command.
 void setSpeed(int speed)
          Change the simulation speed.
 void setStartLambda(ILambda startCmd)
          Set simulation start command.
 void start()
          Start simulation.
 void step()
          Make a simulation step.
 void stop()
          Stop simulation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_env

private AGlobalEnv _env
Environment.


_simEngine

private SimEngine _simEngine
Simulation engine.


_seedCommand

private ILambda _seedCommand
Command to set the seed when a new environment is loaded or created.


_startCommand

private ILambda _startCommand
Command executed before the simulation starts running.


_iterationCommand

private ILambda _iterationCommand
Command executed after the simulation finishes an iteration.


_simulationSpeed

private int _simulationSpeed
Simulation speed.


_timer

private javax.swing.Timer _timer
Processing timer.


_editAdapter

private IEditAdapter _editAdapter
Edit adapter.


_simulationExceptionAdapter

private ISimulationExceptionAdapter _simulationExceptionAdapter
Simulation exception adapter.


_securityManager

private MBSSecurityManager _securityManager
Security manager.


_cmdFactory

private ICmdFactory _cmdFactory
Command factory for use in the environment.

Constructor Detail

SimDriver

public SimDriver()
Construct a new model.

Method Detail

getCmdFactory

public ICmdFactory getCmdFactory()
Get the simulation engine.

Returns:
simulation engine

setAdapters

public void setAdapters(IEditAdapter ea,
                        ISimulationExceptionAdapter sea)
Set adapters.

Parameters:
ea - makeEditCmd adapter to use
sea - simulation exception adapter to use

loadEnvironment

public boolean loadEnvironment(java.lang.String filename)
Load environment from file.

Parameters:
filename - filename
Returns:
true if successful

saveEnvironment

public boolean saveEnvironment(java.lang.String filename)
Save environment to file.

Parameters:
filename - filename
Returns:
true if successful

createEnvironment

public boolean createEnvironment(AEnvFactory factory)
Create environment from factory.

Parameters:
factory - factory
Returns:
true if successful

setSeedLambda

public void setSeedLambda(ILambda seedCmd)
Set the seed command. This command gets executed before a new environment is created or loaded.

Parameters:
seedCmd - command to set

step

public void step()
Make a simulation step.


start

public void start()
Start simulation.


stop

public void stop()
Stop simulation.


setSpeed

public void setSpeed(int speed)
Change the simulation speed.

Parameters:
speed - simulation speed

setStartLambda

public void setStartLambda(ILambda startCmd)
Set simulation start command. This command gets called before the simulation starts.

Parameters:
startCmd - start command

setIterationLambda

public void setIterationLambda(ILambda itCmd)
Set simulation iteration command. This command gets called after the simulation finishes a step.

Parameters:
itCmd - start command

draw

public void draw(java.awt.Graphics2D g,
                 java.awt.Component comp,
                 java.awt.geom.Point2D.Double p1,
                 java.awt.geom.Point2D.Double p2)
Draw model in this region. The graphics object has been set up so that (0,0) represents the top left and (100,100) the bottom right corner.

Parameters:
g - graphics object
comp - component to drawFish on
p1 - top left corner of the region
p2 - bottom right corner of the region

edit

public void edit(java.awt.geom.Point2D.Double p,
                 int button)
Edit a field.

Parameters:
p - coordinates in model coordinate units
button - mouse button pressed

returnHome

public void returnHome(IScrollAdapter sa)
The action to be executed if the display should return home.

Parameters:
sa - scroll adapter

getDisplaySize

public java.awt.Dimension getDisplaySize()
Get size of the display.

Returns:
size of the display in model coordinate units.

getViewPosition

public java.awt.geom.Point2D.Double getViewPosition(java.awt.geom.Point2D.Double pos)
Ask the model where to scroll, given where the user has scrolled. If the environment just acts like a normal panal, it should return pos without modification. If the environment recenters, it should return a position in the middle of the pan area. All coordinates are in model coordinate units.

Parameters:
pos - position where the user scrolled to
Returns:
position where the environment wants the view to be
See Also:
IDisplayAdapter.getPanDelta(java.awt.geom.Point2D.Double)

getPanDelta

public java.awt.geom.Point2D.Double getPanDelta(java.awt.geom.Point2D.Double delta)
Ask the model how much to pan, given where the user scrolled. If the environment just acts like a normal panal, it should return (0,0). If the environment recenters, it should return delta without modification. All coordinates are in model coordinate units.

Parameters:
delta - how far the user scrolled
Returns:
how far the panel should scroll
See Also:
IDisplayAdapter.getViewPosition(java.awt.geom.Point2D.Double)

getToolTipText

public java.lang.String getToolTipText(java.awt.geom.Point2D.Double p)
Get a tool tip description for a specific place in the environment.

Parameters:
p - mouse coordinates
Returns:
tool tip text

getSecurityAdapter

public ISecurityAdapter getSecurityAdapter()
Return the security adapter.

Returns:
security adapter