info.gridworld.gui
Class AbstractDisplay

java.lang.Object
  extended by info.gridworld.gui.AbstractDisplay
All Implemented Interfaces:
Display
Direct Known Subclasses:
ImageDisplay

public abstract class AbstractDisplay
extends java.lang.Object
implements Display

This class provides common implementation code for drawing objects. It will translate, scale, and rotate the graphics system as needed and then invoke its abstract draw method. Subclasses of this abstract class define draw to display an object in a fixed size and orientation.
This code is not tested on the AP CS A and AB exams. It contains GUI implementation details that are not intended to be understood by AP CS students.


Constructor Summary
AbstractDisplay()
           
 
Method Summary
abstract  void draw(java.lang.Object obj, java.awt.Component comp, java.awt.Graphics2D g2)
          Draw the given object.
 void draw(java.lang.Object obj, java.awt.Component comp, java.awt.Graphics2D g2, java.awt.Rectangle rect)
          Draw the given object.
static java.lang.Object getProperty(java.lang.Object obj, java.lang.String propertyName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDisplay

public AbstractDisplay()
Method Detail

draw

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

Parameters:
obj - the occupant we want to draw
comp - the component on which to draw
g2 - the graphics context

draw

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

Specified by:
draw in interface Display
Parameters:
obj - the occupant we want to draw
comp - the component on which to draw
g2 - the graphics context
rect - rectangle in which to draw

getProperty

public static java.lang.Object getProperty(java.lang.Object obj,
                                           java.lang.String propertyName)