vitro.grid
Class GridView

java.lang.Object
  extended by vitro.grid.GridView
All Implemented Interfaces:
View

public class GridView
extends Object
implements View

GridView is a generic View that can be applied to any GridModel. It supports the display of ActorAnnotations as well as GridAnnotations and can be easily extended to support new features or alter the appearance of various elements.


Field Summary
protected  int cellMargin
          The margin between the edges of a cell and an Actor.
protected  int cellSize
          The size (width and height) of a cell in pixels.
protected  ColorScheme colors
          This View's ColorScheme.
protected  Controller controller
          This View's Controller.
protected  int height
          The height of this View in pixels.
protected  int horizontalMargin
          The x-offset of the grid relative to the View.
protected  Grid model
          This View's Model.
protected  int verticalMargin
          The y-offset of the grid relative to the View.
protected  int width
          The width of this View in pixels.
 
Constructor Summary
GridView(Grid model, Controller controller, int width, int height, ColorScheme colors)
          Construct a new GridView.
 
Method Summary
 ColorScheme colorScheme()
          Obtain the ColorScheme used by this View.
 Controller controller()
          Obtain a reference to the Controller associated with this View.
 void draw(Graphics2D g)
          Render the entire View.
protected  void drawActor(Graphics2D g, Actor a)
          Render one Actor.
protected  void drawActorAnnotation(Graphics2D g, ActorAnnotation a)
          Render one ActorAnnotation.
protected  void drawBackground(Graphics2D g)
          Render the background of this View.
protected  void drawCell(Graphics2D g, int x, int y)
          Render one cell of the Grid, starting at a specified position.
protected  void drawGridAnnotation(Graphics2D g, GridAnnotation a)
          Render one GridAnnotation.
 void flush()
          Release any transient view state and update the View to reflect the current state of the Model.
 int height()
          Obtain the preferred height of this View, in pixels.
 void tick(double time)
          Advance the state of the simulation.
 int width()
          Obtain the preferred width of this View, in pixels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

width

protected final int width
The width of this View in pixels.


height

protected final int height
The height of this View in pixels.


cellSize

protected final int cellSize
The size (width and height) of a cell in pixels.


cellMargin

protected int cellMargin
The margin between the edges of a cell and an Actor.


horizontalMargin

protected int horizontalMargin
The x-offset of the grid relative to the View.


verticalMargin

protected int verticalMargin
The y-offset of the grid relative to the View.


model

protected final Grid model
This View's Model.


controller

protected final Controller controller
This View's Controller.


colors

protected final ColorScheme colors
This View's ColorScheme.

Constructor Detail

GridView

public GridView(Grid model,
                Controller controller,
                int width,
                int height,
                ColorScheme colors)
Construct a new GridView.

Parameters:
model - the Model this View will visualize.
controller - the Controller associated with the Model.
width - the width this View should take up, in pixels.
height - the height this View should take up, in pixels.
colors - the ColorScheme used for drawing this View.
Method Detail

controller

public Controller controller()
Obtain a reference to the Controller associated with this View.

Specified by:
controller in interface View
Returns:
this view's Controller.

colorScheme

public ColorScheme colorScheme()
Obtain the ColorScheme used by this View. Mainly used so that host applications can customize their UI overlays to suit this View.

Specified by:
colorScheme in interface View
Returns:
this view's ColorScheme.

width

public int width()
Obtain the preferred width of this View, in pixels.

Specified by:
width in interface View
Returns:
the width of this view in pixels.

height

public int height()
Obtain the preferred height of this View, in pixels.

Specified by:
height in interface View
Returns:
the height of this view in pixels.

draw

public void draw(Graphics2D g)
Render the entire View. First, the background will be drawn, then every cell of the Grid will be drawn, then Actors will be drawn and finally any Annotations will be drawn. This process can be customized by overriding the methods responsible for each step.

Specified by:
draw in interface View
Parameters:
g - the target Graphics2D surface.

drawBackground

protected void drawBackground(Graphics2D g)
Render the background of this View.

Parameters:
g - the target Graphics2D surface.

drawCell

protected void drawCell(Graphics2D g,
                        int x,
                        int y)
Render one cell of the Grid, starting at a specified position.

Parameters:
g - the target Graphics2D surface.
x - the x-coordinate of the top-left corner of this cell in pixels.
y - the y-coordinate of the top-left corner of this cell in pixels.

drawActor

protected void drawActor(Graphics2D g,
                         Actor a)
Render one Actor.

Parameters:
g - the target Graphics2D surface.
a - the Actor to render.

drawActorAnnotation

protected void drawActorAnnotation(Graphics2D g,
                                   ActorAnnotation a)
Render one ActorAnnotation.

Parameters:
g - the target Graphics2D surface.
a - the ActorAnnotation to render.

drawGridAnnotation

protected void drawGridAnnotation(Graphics2D g,
                                  GridAnnotation a)
Render one GridAnnotation.

Parameters:
g - the target Graphics2D surface.
a - the GridAnnotation to render.

tick

public void tick(double time)
Advance the state of the simulation. The time provided may be in fractional units. When a fixed amount of time has elapsed, the View should direct the associated controller to advance the simulation state.

Specified by:
tick in interface View
Parameters:
time - the amount of time that has passed since the last tick

flush

public void flush()
Release any transient view state and update the View to reflect the current state of the Model. This will be called whenever the Model's Controller is driven externally, allowing Views to interrupt any animations or other operations in progress.

Specified by:
flush in interface View