edu.kzoo.grid.display
Class TextDisplay

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

public class TextDisplay
extends ScaledDisplay

Grid Display Package:
A TextDisplay draws a centered text string in a grid cell. If the object it is asked to display has a text method, it displays the text returned by that string, otherwise it displays the text returned by the object's toString method. If the object it is asked to display has a color method, it displays the text in that color, otherwise it displays it in black. The TextDisplay class works best for very short text strings, especially one-character strings; longer strings will not fit in the bounds of the object's grid cell location and if there are objects in the neighboring cells they will obscure the text that does not fit in its own cell.

The TextDisplay class is based on the College Board's DefaultDisplay class, as allowed by the GNU General Public License.

Version:
15 September 2004
Author:
Alyce Brady, Jeff Raab, Northeastern University, Alyce Brady (most recent modifications)

Constructor Summary
TextDisplay()
           
 
Method Summary
 void draw(GridObject obj, java.awt.Component comp, java.awt.Graphics2D g2)
          Draws the given object.
protected  java.lang.String getText(GridObject obj)
          Gets the text string to draw.
protected  java.awt.Color getTextColor(GridObject obj)
          Gets the text color.
protected  java.lang.Object invokeAccessorMethod(GridObject obj, java.lang.String methodName)
          Invokes the named method on the specified object.
protected  void paintCenteredText(java.awt.Graphics2D g2, java.lang.String s, float centerX, float centerY)
          Paints a horizontally and vertically-centered text string.
 
Methods inherited from class edu.kzoo.grid.display.ScaledDisplay
addDecorator, adjust, draw, removeDecorator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextDisplay

public TextDisplay()
Method Detail

draw

public void draw(GridObject obj,
                 java.awt.Component comp,
                 java.awt.Graphics2D g2)
Draws the given object. This implementation draws a text string using the Java 2D Graphics API.

Specified by:
draw in class ScaledDisplay
Parameters:
obj - object we want to draw
comp - component on which to draw
g2 - drawing surface

getText

protected java.lang.String getText(GridObject obj)
Gets the text string to draw.


getTextColor

protected java.awt.Color getTextColor(GridObject obj)
Gets the text color.


invokeAccessorMethod

protected java.lang.Object invokeAccessorMethod(GridObject obj,
                                                java.lang.String methodName)
Invokes the named method on the specified object.


paintCenteredText

protected void paintCenteredText(java.awt.Graphics2D g2,
                                 java.lang.String s,
                                 float centerX,
                                 float centerY)
Paints a horizontally and vertically-centered text string. This method is adapted from p. 134 of J. Knudsen's book, Java 2D Graphics, published by O'Reilly & Associates (1999).

Parameters:
g2 - drawing surface
s - string to draw (centered)
centerX - x-coordinate of center point
centerY - y-coordinate of center point