info.gridworld.gui
Class DefaultDisplay

java.lang.Object
  extended by info.gridworld.gui.DefaultDisplay
All Implemented Interfaces:
Display

public class DefaultDisplay
extends java.lang.Object
implements Display

The DefaultDisplay draws the object's text property with a background color given by the object's color property.
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
DefaultDisplay()
           
 
Method Summary
 void draw(java.lang.Object obj, java.awt.Component comp, java.awt.Graphics2D g2, java.awt.Rectangle rect)
          Draw the given object.
protected  void paintCenteredText(java.awt.Graphics2D g2, java.lang.String s, java.awt.Rectangle rect, double fontHeight, java.awt.Color color)
          Paint a horizontally and vertically-centered text string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultDisplay

public DefaultDisplay()
Method Detail

draw

public void draw(java.lang.Object obj,
                 java.awt.Component comp,
                 java.awt.Graphics2D g2,
                 java.awt.Rectangle rect)
Draw the given object. This implementation draws a string with a background color. The background color is the value of the color property, or, if there is no such property and the object is an instance of Color, the object itself. The string is the text property, or if there is no such property, the result of calling toString. The string is clipped to 8 characters.

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

paintCenteredText

protected void paintCenteredText(java.awt.Graphics2D g2,
                                 java.lang.String s,
                                 java.awt.Rectangle rect,
                                 double fontHeight,
                                 java.awt.Color color)
Paint a horizontally and vertically-centered text string.

Parameters:
g2 - drawing surface
s - string to draw (centered)
rect - the bounding rectangle
fontHeight - the desired height of the font. (The font will be shrunk in increments of sqrt(2)/2 if the text is too large.)
color - the color in which to draw the text