public class TextDisplay extends ScaledDisplay
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.
Constructor and Description |
---|
TextDisplay() |
Modifier and Type | Method and Description |
---|---|
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.
|
addDecorator, adjust, draw, removeDecorator
public void draw(GridObject obj, java.awt.Component comp, java.awt.Graphics2D g2)
draw
in class ScaledDisplay
obj
- object we want to drawcomp
- component on which to drawg2
- drawing surfaceprotected java.lang.String getText(GridObject obj)
protected java.awt.Color getTextColor(GridObject obj)
protected java.lang.Object invokeAccessorMethod(GridObject obj, java.lang.String methodName)
protected void paintCenteredText(java.awt.Graphics2D g2, java.lang.String s, float centerX, float centerY)
g2
- drawing surfaces
- string to draw (centered)centerX
- x-coordinate of center pointcenterY
- y-coordinate of center point