sysModel.env
Class AGlobalEnv

java.lang.Object
  extended by sysModel.env.AGlobalEnv
Direct Known Subclasses:
ASquareEnv, NoGridEnv, NullEnv, Test_AFish.TestGlobalEnv

public abstract class AGlobalEnv
extends java.lang.Object

Abstract global environment class.

Note: All subclasses must provide a two-parameter constructor that takes in an ICmdFactory for dynamic access to parse() and makeEnvFactory(), and an ISecurityAdapter for the security adapter in use.

Author:
Mathias Ricken

Nested Class Summary
 class AGlobalEnv.ALocalEnv
          Abstract bsae class of the environment local to a fish.
protected  class AGlobalEnv.BreedLambda
          Lambda to execute a breed.
static interface AGlobalEnv.ILocalEnvVisitor
          Visitor to opererate on a local environment.
 
Field Summary
protected  LRStruct _breedLambdas
          List of breed commands issued.
protected  ICmdFactory _cmdFactory
          Command factory for lambdas given to the simulation driver.
protected  LRStruct _moveLambdas
          List of move commands issued.
protected  ISecurityAdapter _securityManager
          Security manager that controls the actions of the fish.
protected  java.awt.Color _waterColor
          Color of the water.
protected static java.awt.Color OCEAN_BLUE
          Color of the ocean.
 
Constructor Summary
AGlobalEnv(ICmdFactory cmdFactory, ISecurityAdapter sm)
          Construct a new abstract global environment.
 
Method Summary
protected  ILambda addFish(AGlobalEnv.ALocalEnv localEnv, AFish fish)
          Add the fish to the global environment.
protected abstract  void addFishToInternalData(AGlobalEnv.ALocalEnv localEnv, AFish fish)
          Add the fish to the environment's internal data structure.
protected  void deactivateBreedLambdas()
          Deactivate move commands and clear list.
protected  void deactivateMoveLambdas()
          Deactivate move commands and clear list.
protected  void drawBackground(java.awt.Graphics2D g2, java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2)
          Draw ocean background.
protected abstract  ILambda editFish(AGlobalEnv.ALocalEnv localEnv, IFishFactory fishFactory, int button)
          Edit the fish.
abstract  java.awt.Dimension getDisplaySize()
          Get size of the display.
abstract  java.awt.geom.Point2D.Double getPanDelta(java.awt.geom.Point2D.Double delta)
          Ask the model how much to pan, given where the user scrolled.
abstract  ILambda getToolTipText(java.awt.geom.Point2D.Double p)
          Get a tool tip description for a specific place in the environment.
abstract  java.awt.geom.Point2D.Double getViewPosition(java.awt.geom.Point2D.Double pos)
          Ask the model where to scroll, given where the user has scrolled.
 ILambda makeDrawCmd(java.awt.Graphics2D g2, java.awt.Component comp, java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2)
          Draw the environment in the region requested in model coordinates.
 ILambda makeEditCmd(java.awt.geom.Point2D.Double p, IFishFactory fishFactory, int button)
          Edit a location.
abstract  AEnvFactory makeEnvFactory()
          Create the environment settings class for an environment.
protected abstract  AGlobalEnv.ALocalEnv makeLocalEnv(java.awt.geom.Point2D.Double p)
          Create a local environment for the position.
 ILambda makeStepCmd()
          Make the step command for the simulation driver to execute.
 AGlobalEnv parse(Lexer l)
          Factory method for parsing a stream of tokens and creating a global environment from it.
protected abstract  AGlobalEnv parseEnvironment(Lexer l)
          Factory method for parsing the parameters for an environment and then creating it.
protected abstract  void parseFish(Lexer l)
          Parse fish and add them to the environment.
protected abstract  void printHeader(java.io.PrintWriter pw)
          Print file header.
protected  ILambda removeFish(AGlobalEnv.ALocalEnv localEnv)
          Remove the fish from the global environment.
protected abstract  void removeFishFromInternalData(AGlobalEnv.ALocalEnv localEnv)
          Remove the fish to the environment's internal data structure.
abstract  void returnHome(IScrollAdapter sa)
          The action to be executed if the display should return home.
 ILambda save(java.io.PrintWriter pw)
          Save an environment to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OCEAN_BLUE

protected static final java.awt.Color OCEAN_BLUE
Color of the ocean.


_moveLambdas

protected LRStruct _moveLambdas
List of move commands issued. The commands issued in a fish's step are recorded so that they can be deactivated once a fish completes its step. This prevents a fish class from saving commands and executing them at a later time.


_breedLambdas

protected LRStruct _breedLambdas
List of breed commands issued. The commands issued in a fish's step are recorded so that they can be deactivated once a fish completes its step. This prevents a fish class from saving commands and executing them at a later time.


_cmdFactory

protected ICmdFactory _cmdFactory
Command factory for lambdas given to the simulation driver.


_securityManager

protected ISecurityAdapter _securityManager
Security manager that controls the actions of the fish.


_waterColor

protected java.awt.Color _waterColor
Color of the water.

Constructor Detail

AGlobalEnv

public AGlobalEnv(ICmdFactory cmdFactory,
                  ISecurityAdapter sm)
Construct a new abstract global environment.

Parameters:
cmdFactory - command factory to use
sm - security manager to control fish actions
Method Detail

deactivateMoveLambdas

protected void deactivateMoveLambdas()
Deactivate move commands and clear list. If this is called after a fish has moved or after a step is complete, it makes it impossible to use the commands at a later time.


deactivateBreedLambdas

protected void deactivateBreedLambdas()
Deactivate move commands and clear list. If this is called after a fish has moved or after a step is complete, it makes it impossible to use the commands at a later time.


makeEditCmd

public ILambda makeEditCmd(java.awt.geom.Point2D.Double p,
                           IFishFactory fishFactory,
                           int button)
Edit a location.

Parameters:
p - position
fishFactory - factory to make a new fish
button -
Returns:
the lambda that the simulation control should execute for this action

addFish

protected ILambda addFish(AGlobalEnv.ALocalEnv localEnv,
                          AFish fish)
Add the fish to the global environment.

Parameters:
localEnv - local environment
fish - fish to add
Returns:
add lambda

removeFish

protected ILambda removeFish(AGlobalEnv.ALocalEnv localEnv)
Remove the fish from the global environment.

Parameters:
localEnv - local environment
Returns:
delete lambda

makeDrawCmd

public ILambda makeDrawCmd(java.awt.Graphics2D g2,
                           java.awt.Component comp,
                           java.awt.geom.Point2D.Double p1,
                           java.awt.geom.Point2D.Double p2)
Draw the environment in the region requested in model coordinates.

Parameters:
g2 - the Graphics2D object to use to render
comp - the component to makeDrawCmd on
p1 - top left corner
p2 - bottom right corner
Returns:
lambda for the simulation control to execute

drawBackground

protected void drawBackground(java.awt.Graphics2D g2,
                              java.awt.geom.Point2D.Double p1,
                              java.awt.geom.Point2D.Double p2)
Draw ocean background.

Parameters:
g2 - graphics object
p1 - top left corner
p2 - bottom right corner

makeStepCmd

public ILambda makeStepCmd()
Make the step command for the simulation driver to execute.

Returns:
step command

save

public ILambda save(java.io.PrintWriter pw)
Save an environment to a file.

Parameters:
pw - PrintWriter to use for output
Returns:
lambda for the simulation control to execute

parse

public AGlobalEnv parse(Lexer l)
Factory method for parsing a stream of tokens and creating a global environment from it.

Parameters:
l - lexer to use
Returns:
new global environment

editFish

protected abstract ILambda editFish(AGlobalEnv.ALocalEnv localEnv,
                                    IFishFactory fishFactory,
                                    int button)
Edit the fish.

Parameters:
localEnv - local environment
fishFactory -
button -
Returns:
lambda for the simulation control to execute

addFishToInternalData

protected abstract void addFishToInternalData(AGlobalEnv.ALocalEnv localEnv,
                                              AFish fish)
Add the fish to the environment's internal data structure.

Parameters:
localEnv - local environment
fish - fish to add

removeFishFromInternalData

protected abstract void removeFishFromInternalData(AGlobalEnv.ALocalEnv localEnv)
Remove the fish to the environment's internal data structure.

Parameters:
localEnv - local environment

parseEnvironment

protected abstract AGlobalEnv parseEnvironment(Lexer l)
Factory method for parsing the parameters for an environment and then creating it.

Parameters:
l - lexer
Returns:
new global environment

parseFish

protected abstract void parseFish(Lexer l)
Parse fish and add them to the environment.

Parameters:
l - parser to read from

makeLocalEnv

protected abstract AGlobalEnv.ALocalEnv makeLocalEnv(java.awt.geom.Point2D.Double p)
Create a local environment for the position.

Parameters:
p - position
Returns:
local environment

makeEnvFactory

public abstract AEnvFactory makeEnvFactory()
Create the environment settings class for an environment. Factory method.

Returns:
environment settings class

printHeader

protected abstract void printHeader(java.io.PrintWriter pw)
Print file header.

Parameters:
pw - PrintWriter to use

getDisplaySize

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

Returns:
size of the display in model coordinate units.

returnHome

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

Parameters:
sa - scroll adapter

getViewPosition

public abstract 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 abstract 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 abstract ILambda getToolTipText(java.awt.geom.Point2D.Double p)
Get a tool tip description for a specific place in the environment.

Parameters:
p - mouse coordinates
Returns:
lambda for the simulation controller to execute. Must return the tooltip string.