sysModel.env
Class BoundedEnv

java.lang.Object
  extended by sysModel.env.AGlobalEnv
      extended by sysModel.env.ASquareEnv
          extended by sysModel.env.BoundedEnv
Direct Known Subclasses:
WrappingEnv

public class BoundedEnv
extends ASquareEnv

Implementation of a square bounded environment.

Author:
Mathias G. Ricken

Nested Class Summary
static class BoundedEnv.EmptyField
          Empty field singleton.
static interface BoundedEnv.IField
          Field interface.
static interface BoundedEnv.IFieldVisitor
          Field visitor interface.
protected  class BoundedEnv.LocalEnvironment
          Concrete local environment for the square bounded environment.
static class BoundedEnv.NonEmptyField
          Non-empty field class.
static class BoundedEnv.Test_BoundedEnv
          Test cases for BoundedEnv.
static class BoundedEnv.Test_BoundedEnv_LocalEnv
          Test cases for BoundedEnv.LocalEnv.
 
Nested classes/interfaces inherited from class sysModel.env.ASquareEnv
ASquareEnv.ASquareLocalEnvironment, ASquareEnv.Direction, ASquareEnv.Location
 
Nested classes/interfaces inherited from class sysModel.env.AGlobalEnv
AGlobalEnv.ALocalEnv, AGlobalEnv.BreedLambda, AGlobalEnv.ILocalEnvVisitor
 
Field Summary
protected  BoundedEnv.IField[][] _fieldMap
          List of local environments in this global environment.
protected  int _height
          Height.
protected  BoundedEnv.LocalEnvironment _outOfBounds
          "Singleton" instance for all out-of-bounds locations.
protected  int _width
          Width.
protected  java.awt.geom.Point2D.Double PAN_CENTER
          Center of the pan area.
protected  int PAN_SIZE
          Size of the pan area.
 
Fields inherited from class sysModel.env.AGlobalEnv
_breedLambdas, _cmdFactory, _moveLambdas, _securityAdapter, _waterColor, OCEAN_BLUE
 
Constructor Summary
BoundedEnv(ICmdFactory cmdFactory, ISecurityAdapter sm)
          Construct a new square bounded environment.
BoundedEnv(ICmdFactory cmdFactory, ISecurityAdapter sm, int width, int height)
          Construct a new square bounded environment.
 
Method Summary
protected  void addFishToInternalData(AGlobalEnv.ALocalEnv localEnv, AFish fish)
          Add the fish to the global environment.
protected  ASquareEnv.ASquareLocalEnvironment createLocalEnvironment(ASquareEnv.Location loc, ASquareEnv.Direction dir)
          Create a local environment with the given data.
 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.
 java.awt.geom.Point2D.Double getViewPosition(java.awt.geom.Point2D.Double pos)
          Ask the model where to scroll, given where the user has scrolled.
 AEnvFactory makeEnvFactory()
          Get the environment settings class.
protected  ASquareEnv.ASquareLocalEnvironment makeLocalEnv(ASquareEnv.Location loc, ASquareEnv.Direction dir)
          Create a local environment for the position.
protected  AGlobalEnv parseEnvironment(Lexer l)
          Factory method for parsing a stream of tokens and creating a global environment from it.
protected  void printHeader(java.io.PrintWriter pw)
          Print file header.
protected  void removeFishFromInternalData(AGlobalEnv.ALocalEnv localEnv)
          Remove the fish from the global environment.
 void returnHome(IScrollAdapter sa)
          The action to be executed if the display should return home.
 
Methods inherited from class sysModel.env.ASquareEnv
editFish, getToolTipText, makeDirection, makeDirection, makeDirection, makeLocalEnv, makeLocation, parseFish
 
Methods inherited from class sysModel.env.AGlobalEnv
addFish, deactivateBreedLambdas, deactivateMoveLambdas, drawBackground, makeDrawCmd, makeEditCmd, makeStepCmd, parse, removeFish, save
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAN_SIZE

protected final int PAN_SIZE
Size of the pan area.

See Also:
Constant Field Values

PAN_CENTER

protected final java.awt.geom.Point2D.Double PAN_CENTER
Center of the pan area.


_fieldMap

protected BoundedEnv.IField[][] _fieldMap
List of local environments in this global environment.


_outOfBounds

protected final BoundedEnv.LocalEnvironment _outOfBounds
"Singleton" instance for all out-of-bounds locations.


_width

protected int _width
Width.


_height

protected int _height
Height.

Constructor Detail

BoundedEnv

public BoundedEnv(ICmdFactory cmdFactory,
                  ISecurityAdapter sm)
Construct a new square bounded environment. Does not set this object up for actual use. Note: This constructor needs to exist and be public for the "environment selection" dialog to work.

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

BoundedEnv

public BoundedEnv(ICmdFactory cmdFactory,
                  ISecurityAdapter sm,
                  int width,
                  int height)
Construct a new square bounded environment.

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

addFishToInternalData

protected void addFishToInternalData(AGlobalEnv.ALocalEnv localEnv,
                                     AFish fish)
Add the fish to the global environment.

Specified by:
addFishToInternalData in class AGlobalEnv
Parameters:
localEnv - local environment
fish - fish to add

removeFishFromInternalData

protected void removeFishFromInternalData(AGlobalEnv.ALocalEnv localEnv)
Remove the fish from the global environment.

Specified by:
removeFishFromInternalData in class AGlobalEnv
Parameters:
localEnv - local environment

makeLocalEnv

protected ASquareEnv.ASquareLocalEnvironment makeLocalEnv(ASquareEnv.Location loc,
                                                          ASquareEnv.Direction dir)
Create a local environment for the position.

Specified by:
makeLocalEnv in class ASquareEnv
Parameters:
loc - location
dir - direction
Returns:
local environment

createLocalEnvironment

protected ASquareEnv.ASquareLocalEnvironment createLocalEnvironment(ASquareEnv.Location loc,
                                                                    ASquareEnv.Direction dir)
Create a local environment with the given data.

Parameters:
loc - location
dir - direction
Returns:
new local environment

parseEnvironment

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

Specified by:
parseEnvironment in class AGlobalEnv
Parameters:
l - lexer
Returns:
new global environment

makeEnvFactory

public AEnvFactory makeEnvFactory()
Get the environment settings class.

Specified by:
makeEnvFactory in class AGlobalEnv
Returns:
environment settings class

printHeader

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

Specified by:
printHeader in class AGlobalEnv
Parameters:
pw - PrintWriter to use

getDisplaySize

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

Specified by:
getDisplaySize in class AGlobalEnv
Returns:
size of the display in model coordinate units.

returnHome

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

Specified by:
returnHome in class AGlobalEnv
Parameters:
sa - scroll adapter

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.

Specified by:
getViewPosition in class AGlobalEnv
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.

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