javalib.worldimages
Class TextImage

java.lang.Object
  extended by javalib.worldimages.AImage
      extended by javalib.worldimages.ColoredImage
          extended by javalib.worldimages.TextImage
All Implemented Interfaces:
Drawable, WorldImage, tester.ISame<WorldImage>

 class TextImage
extends ColoredImage

An image of some text.

Version:
Dec. 5, 2012
Author:
Stephen Bloch, mostly cribbed from Viera's TextImage class

Copyright 2012 Viera K. Proulx

This program is distributed under the terms of the GNU Lesser General Public License (LGPL)


Field Summary
(package private) static float defaultSize
           
 
Fields inherited from class javalib.worldimages.ColoredImage
defaultColor
 
Fields inherited from interface javalib.worldimages.WorldImage
LOOKS_SAME
 
Method Summary
 void draw(Graphics2D g)
          Draw this image in the provided Graphics2D context.
 boolean equals(Object o)
          Is this TextImage same as the given object?
 int getBottom()
          Produce the height of this text image (based on its size)
 int getRight()
          Produce the width of this image.
 int hashCode()
          The hashCode to match the equals method
(package private) static TextImage make(String text)
           
(package private) static TextImage make(String text, Color color)
           
(package private) static TextImage make(String text, float size)
           
(package private) static TextImage make(String text, float size, Color color)
           
(package private) static TextImage make(String text, float size, IColor color)
           
(package private) static TextImage make(String text, float size, TextStyle style)
           
(package private) static TextImage make(String text, float size, TextStyle style, Color color)
           
(package private) static TextImage make(String text, float size, TextStyle style, IColor color)
           
(package private) static TextImage make(String text, IColor color)
           
(package private) static TextImage make(String text, TextStyle style)
           
(package private) static TextImage make(String text, TextStyle style, Color color)
           
(package private) static TextImage make(String text, TextStyle style, IColor color)
           
(package private)  ColoredImage replaceColor(Color color)
          Functional setter for the color field Define this in all concrete subclasses.
(package private)  ColoredImage replaceMode(Mode newMode)
          Functional setter for the mode field Define this in all concrete subclasses.
protected  void setWidthHeight()
          Compute and set the width and the height for this text in the given style and size.
 String toIndentedString(String indent)
          Produce a String that represents this image, indented by the given indent
 
Methods inherited from class javalib.worldimages.ColoredImage
getColor, getMode, replaceColor
 
Methods inherited from class javalib.worldimages.AImage
above, aboveCentered, beside, besideCentered, build, build, centerMoved, centerMoved, cornerString, cropped, frozen, getCenter, getHeight, getLeft, getPixelColor, getTop, getWidth, isApplet, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCenteredCircle, makeCircle, makeCircle, makeCircle, makeCircle, makeCircle, makeCircle, makeEllipse, makeEllipse, makeEllipse, makeEllipse, makeEllipse, makeEllipse, makeFromFile, makeFromURL, makeImage, makeLine, makeLine, makeLine, makePolygon, makePolygon, makePolygon, makePolygon, makePolygon, makePolygon, makeRectangle, makeRectangle, makeRectangle, makeRectangle, makeRectangle, makeRectangle, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeText, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, makeTriangle, map, map, moved, moved, normalized, overlay, overlayCentered, overlayImages, overlayXY, place, rotate, rotated, rotated, rotatedAround, rotatedAround, rotatedInPlace, rotatedInPlace, same, sameClass, save, scaled, scaled, show, toString, xReflected, yReflected
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultSize

static final float defaultSize
See Also:
Constant Field Values
Method Detail

draw

public void draw(Graphics2D g)
Draw this image in the provided Graphics2D context.

Parameters:
g - the provided Graphics2D context

equals

public boolean equals(Object o)
Is this TextImage same as the given object?

Specified by:
equals in interface WorldImage
Overrides:
equals in class ColoredImage
Parameters:
o - the object to compare with this
Returns:
true iff the images are isomorphic expression trees, with equal fields.

getBottom

public int getBottom()
Produce the height of this text image (based on its size)

Returns:
the height of this image

getRight

public int getRight()
Produce the width of this image.

Returns:
the (approximate) width of this image

hashCode

public int hashCode()
The hashCode to match the equals method

Specified by:
hashCode in interface WorldImage
Overrides:
hashCode in class ColoredImage

make

static TextImage make(String text)

make

static TextImage make(String text,
                      Color color)

make

static TextImage make(String text,
                      float size)

make

static TextImage make(String text,
                      float size,
                      Color color)

make

static TextImage make(String text,
                      float size,
                      IColor color)

make

static TextImage make(String text,
                      float size,
                      TextStyle style)

make

static TextImage make(String text,
                      float size,
                      TextStyle style,
                      Color color)

make

static TextImage make(String text,
                      float size,
                      TextStyle style,
                      IColor color)

make

static TextImage make(String text,
                      IColor color)

make

static TextImage make(String text,
                      TextStyle style)

make

static TextImage make(String text,
                      TextStyle style,
                      Color color)

make

static TextImage make(String text,
                      TextStyle style,
                      IColor color)

replaceColor

ColoredImage replaceColor(Color color)
Description copied from class: ColoredImage
Functional setter for the color field Define this in all concrete subclasses. (I HATE this! Every one of these definitions will consist of calling the constructor with exactly the same fields but newColor plugged in as the color. Why do I have to write that over and over in every concrete subclass?)

Specified by:
replaceColor in class ColoredImage
Returns:
a new image just like this one but with a different color

replaceMode

ColoredImage replaceMode(Mode newMode)
Description copied from class: ColoredImage
Functional setter for the mode field Define this in all concrete subclasses.

Specified by:
replaceMode in class ColoredImage
Returns:
a new image just like this one but with a different mode

setWidthHeight

protected void setWidthHeight()
Compute and set the width and the height for this text in the given style and size. Note that our translation tells where to put the top-left corner of the text, but Graphics2D.draw works from the baseline, so we need to adjust by the ascent.


toIndentedString

public String toIndentedString(String indent)
Produce a String that represents this image, indented by the given indent

Parameters:
indent - the given prefix representing the desired indentation
Returns:
the String representation of this image