edu.kzoo.grid.display
Class ScaledDisplay

java.lang.Object
  |
  +--edu.kzoo.grid.display.ScaledDisplay
All Implemented Interfaces:
GridObjectDisplay
Direct Known Subclasses:
ColorBlockDisplay, ScaledImageDisplay, TextDisplay

public abstract class ScaledDisplay
extends java.lang.Object
implements GridObjectDisplay

Grid Display Package:
This abstract class provides common implementation code for drawing a GridObject object. The class will translate and scale the graphics system as needed and then invoke its abstract draw method. Subclasses of this abstract class define draw to just display an object with a fixed size.

Version:
28 July 2004
Author:
Alyce Brady (based on AbstractFishDisplay by Julie Zelenski), Joel Booth (Added the mechanism to allow for decorators)

Constructor Summary
ScaledDisplay()
           
 
Method Summary
 void addDecorator(DisplayDecorator d)
          Add a Decorator to the display in order to add some functionality.
 void adjust(GridObject obj, java.awt.Component comp, java.awt.Graphics2D g2)
          Adjusts the graphics system for drawing an object, as appropriate.
abstract  void draw(GridObject obj, java.awt.Component comp, java.awt.Graphics2D g2)
          Draw the given GridObject object.
 void draw(GridObject obj, java.awt.Component comp, java.awt.Graphics2D g2, java.awt.Rectangle rect)
          Draw the given object.
 void removeDecorator(DisplayDecorator d)
          Remove a Decorator from the display
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScaledDisplay

public ScaledDisplay()
Method Detail

draw

public abstract void draw(GridObject obj,
                          java.awt.Component comp,
                          java.awt.Graphics2D g2)
Draw the given GridObject object. Subclasses should implement this method to draw the object in a cell of size (1,1) centered around (0,0) on the drawing surface. (All scaling has been done beforehand).

Parameters:
obj - object we want to draw
comp - component on which to draw
g2 - drawing surface

draw

public void draw(GridObject obj,
                 java.awt.Component comp,
                 java.awt.Graphics2D g2,
                 java.awt.Rectangle rect)
Draw the given object. Scales the coordinate appropriately then invokes the simple draw method above that is only responsible for drawing a unit-length object.

Specified by:
draw in interface GridObjectDisplay
Parameters:
obj - object we want to draw
comp - component on which to draw
g2 - drawing surface
rect - rectangle in which to draw

addDecorator

public void addDecorator(DisplayDecorator d)
Add a Decorator to the display in order to add some functionality.

Parameters:
d - The decorator to add

removeDecorator

public void removeDecorator(DisplayDecorator d)
Remove a Decorator from the display

Parameters:
d - The decorator to remove

adjust

public void adjust(GridObject obj,
                   java.awt.Component comp,
                   java.awt.Graphics2D g2)
Adjusts the graphics system for drawing an object, as appropriate. This method actually makes no further adjustments, but subclasses could override this method to rotate the object, for example.