Class BugWorldView

java.lang.Object
  extended byBugWorldView
All Implemented Interfaces:
MatrixView

public class BugWorldView
extends java.lang.Object
implements MatrixView

This class creates and manages a display view of a MatrixModel.


Constructor Summary
BugWorldView(int viewRows, int viewCols, int cellWidth, int cellHeight)
          Create a new display of the given MatrixModel.
 
Method Summary
 void addCritter(Critter bug, int[] loc)
          Add the given Critter to the collection of Critters we are displaying.
 uwcse.graphics.GWindow getGWindow()
          Get the GWindow associated with this view for use by a MatrixController.
 void moveCritter(Critter bug, int[] newLoc)
          Update the display to reflect a new position for the given Critter.
 void removeCritter(Critter bug)
          Remove the given Critter from the collection of Critters we are displaying.
 void resumeRepaints()
          Resume repainting this view's window.
 void suspendRepaints()
          Suspend repainting this view's window because we are going to do a bunch of updates.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BugWorldView

public BugWorldView(int viewRows,
                    int viewCols,
                    int cellWidth,
                    int cellHeight)
Create a new display of the given MatrixModel.

Parameters:
viewRows - the height of the view into the cell array. Specify as the number of model cells in the vertical direction to display.
viewCols - the width of the view into the cell array. Specify as the number of model cells in the horizontal direction to display.
cellWidth - the width of each individual Critter cell on the screen in pixels
cellHeight - the height of each individual Critter cell on the screen in pixels
Method Detail

getGWindow

public uwcse.graphics.GWindow getGWindow()
Description copied from interface: MatrixView
Get the GWindow associated with this view for use by a MatrixController.

Specified by:
getGWindow in interface MatrixView
Returns:
the GWindow associated with this view, or null if no window.
See Also:
MatrixView.getGWindow()

addCritter

public void addCritter(Critter bug,
                       int[] loc)
Description copied from interface: MatrixView
Add the given Critter to the collection of Critters we are displaying. If the Critter is already in the collection, the request is ignored. Note that a cell location is not the same as a pixel location. One of the tasks that a MatrixView does is translate between the cell location and the screen location.

Specified by:
addCritter in interface MatrixView
Parameters:
bug - the Critter to add
loc - a 2-element int array containing the current cell location of this Critter. The row address is in element [0] and the column address is in element [1].
See Also:
MatrixView.addCritter(Critter, int[])

removeCritter

public void removeCritter(Critter bug)
Description copied from interface: MatrixView
Remove the given Critter from the collection of Critters we are displaying.

Specified by:
removeCritter in interface MatrixView
Parameters:
bug - the Critter to remove
See Also:
MatrixView.removeCritter(Critter)

moveCritter

public void moveCritter(Critter bug,
                        int[] newLoc)
Description copied from interface: MatrixView
Update the display to reflect a new position for the given Critter. Note that a cell location is not the same as a pixel location. One of the tasks that a MatrixView does is translate between the cell location and the screen location.

Specified by:
moveCritter in interface MatrixView
Parameters:
bug - the Critter to move
newLoc - a 2-element int array containing the new cell location of this Critter. The row address is in element [0] and the column address is in element [1].
See Also:
MatrixView.moveCritter(Critter, int[])

resumeRepaints

public void resumeRepaints()
Description copied from interface: MatrixView
Resume repainting this view's window.

Specified by:
resumeRepaints in interface MatrixView
See Also:
MatrixView.resumeRepaints()

suspendRepaints

public void suspendRepaints()
Description copied from interface: MatrixView
Suspend repainting this view's window because we are going to do a bunch of updates.

Specified by:
suspendRepaints in interface MatrixView
See Also:
MatrixView.suspendRepaints()