objectdraw
Class Text

java.lang.Object
  |
  +--objectdraw.Drawable
        |
        +--objectdraw.Drawable2D
              |
              +--objectdraw.Text
All Implemented Interfaces:
Drawable2DInterface, DrawableInterface, java.io.Serializable

public class Text
extends Drawable2D

Text is an implementation of a drawable text string object.

See Also:
Serialized Form

Field Summary
protected  double baseHeight
          The text's height above baseline.
protected  java.awt.Font font
          The text's font.
protected  double height
          The text's height.
protected  Location origin
          The location of the upper-left-most point of the text
protected  java.lang.String text
          The object's text contents.
protected  double width
          The text's width.
 
Fields inherited from class objectdraw.Drawable
canvas, canvasContent, color, DEBUGGING, shown
 
Constructor Summary
Text(boolean text, double x, double y, DrawingCanvas c)
          Creates a new Text object a boolean.
Text(boolean text, Location origin, DrawingCanvas c)
          Creates a new Text object that displays a boolean.
Text(char text, double x, double y, DrawingCanvas c)
          Creates a new Text object that displays a char.
Text(char text, Location origin, DrawingCanvas c)
          Creates a new Text object that displays a char.
Text(double text, double x, double y, DrawingCanvas c)
          Creates a new Text object that displays a double or float.
Text(double text, Location origin, DrawingCanvas c)
          Creates a new Text object that displays a double or float.
Text(long text, double x, double y, DrawingCanvas c)
          Creates a new Text object that displays a long, int, short, or byte.
Text(long text, Location origin, DrawingCanvas c)
          Creates a new Text object that displays a short, int, byte or long.
Text(java.lang.Object text, double x, double y, DrawingCanvas c)
          Creates a new Text object that displays an object.
Text(java.lang.Object text, Location origin, DrawingCanvas c)
          Creates a new Text object that displays an Object.
 
Method Summary
protected  void changeSize()
          Updates instance variables when something changes that may impact bounding box of the text.
 void draw(java.awt.Graphics g)
          Draws the object.
 Bounds getBounds()
          Retrieves the bounding rectangle of the object.
 java.awt.Font getFont()
          Retrieves the text object's font.
 double getHeight()
          Gets the width of the object's bounding rectangle
 java.lang.String getText()
          Gets the text of the object.
 double getWidth()
          Gets the width of the object's bounding rectangle
 void move(double dx, double dy)
          Moves the Text object within the canvas by the amount specified in the x and y direction.
 void moveTo(Location point)
          Moves the Text object within the canvas to the specified Location.
 void setBold()
          Deprecated. Deprecated since objectdraw 4, use setBold(boolean) instead.
 void setBold(boolean bool)
          Toggles whether the text object's style is bold or not.
 void setFont(java.awt.Font f)
          Sets the text object's font.
 void setFont(java.lang.String fname)
          Sets the text object's font.
 void setFontSize(int size)
          Sets the text object's font size.
 void setItalic()
          Deprecated. Deprecated since objectdraw 4, use setItalic(boolean) instead.
 void setItalic(boolean bool)
          Toggles whether the text object's style is italics or not.
 void setPlain()
          Sets the text object's font to have plain style.
 void setText(boolean text)
          Sets the text object's value to the boolean text.
 void setText(char text)
          Sets the text object's value to the char text
 void setText(double text)
          Sets the text object's value to the double text
 void setText(long text)
          Sets the text object's value to the short, int, byte, or long text.
 void setText(java.lang.Object text)
          Sets the text object's value to the Object text
 void setText(java.lang.String text)
          Sets the text object's value to the String text.
 java.lang.String toString()
          Generates a string representation of the object.
 
Methods inherited from class objectdraw.Drawable2D
contains, getLocation, getX, getY, overlaps
 
Methods inherited from class objectdraw.Drawable
addToCanvas, getColor, hide, isHidden, moveTo, removeFromCanvas, sendBackward, sendForward, sendToBack, sendToFront, setColor, setStateChanged, show
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface objectdraw.DrawableInterface
addToCanvas, getColor, hide, isHidden, moveTo, removeFromCanvas, sendBackward, sendForward, sendToBack, sendToFront, setColor, show
 

Field Detail

origin

protected Location origin
The location of the upper-left-most point of the text

width

protected double width
The text's width.

height

protected double height
The text's height.

baseHeight

protected double baseHeight
The text's height above baseline.

font

protected java.awt.Font font
The text's font.

text

protected java.lang.String text
The object's text contents.
Constructor Detail

Text

public Text(java.lang.Object text,
            Location origin,
            DrawingCanvas c)
Creates a new Text object that displays an Object.
Parameters:
text - the text to be drawn
origin - the upper left corner of the bounding region for the object
c - the canvas into which the text will be drawn

Text

public Text(boolean text,
            Location origin,
            DrawingCanvas c)
Creates a new Text object that displays a boolean.
Parameters:
text - the text to be drawn
origin - the upper left corner of the bounding region for the object
c - the canvas into which the text will be drawn

Text

public Text(char text,
            Location origin,
            DrawingCanvas c)
Creates a new Text object that displays a char.
Parameters:
text - the text to be drawn
origin - the upper left corner of the bounding region for the object
c - the canvas into which the text will be drawn

Text

public Text(long text,
            Location origin,
            DrawingCanvas c)
Creates a new Text object that displays a short, int, byte or long.
Parameters:
text - the text to be drawn
origin - the upper left corner of the bounding region for the object
c - the canvas into which the text will be drawn

Text

public Text(double text,
            Location origin,
            DrawingCanvas c)
Creates a new Text object that displays a double or float.
Parameters:
text - the text to be drawn
origin - the upper left corner of the bounding region for the object
c - the canvas into which the text will be drawn

Text

public Text(java.lang.Object text,
            double x,
            double y,
            DrawingCanvas c)
Creates a new Text object that displays an object.
Parameters:
text - the text to be drawn
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
c - the canvas into which the text will be drawn

Text

public Text(boolean text,
            double x,
            double y,
            DrawingCanvas c)
Creates a new Text object a boolean.
Parameters:
text - the text to be drawn
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
c - the canvas into which the text will be drawn

Text

public Text(long text,
            double x,
            double y,
            DrawingCanvas c)
Creates a new Text object that displays a long, int, short, or byte.
Parameters:
text - the text to be drawn
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
c - the canvas into which the text will be drawn

Text

public Text(double text,
            double x,
            double y,
            DrawingCanvas c)
Creates a new Text object that displays a double or float.
Parameters:
text - the text to be drawn
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
c - the canvas into which the text will be drawn

Text

public Text(char text,
            double x,
            double y,
            DrawingCanvas c)
Creates a new Text object that displays a char.
Parameters:
text - the text to be drawn
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
c - the canvas into which the text will be drawn
Method Detail

draw

public void draw(java.awt.Graphics g)
Draws the object.
Overrides:
draw in class Drawable2D
Parameters:
g - the graphics context into which the object is drawn

changeSize

protected void changeSize()
Updates instance variables when something changes that may impact bounding box of the text.

getWidth

public double getWidth()
Gets the width of the object's bounding rectangle

getHeight

public double getHeight()
Gets the width of the object's bounding rectangle
Overrides:
getHeight in class Drawable2D
Following copied from class: objectdraw.Drawable2D
Returns:
the height of the object's bounding rectangle

getBounds

public Bounds getBounds()
Retrieves the bounding rectangle of the object.
Following copied from interface: objectdraw.Drawable2DInterface
Returns:
the bounding rectangle

moveTo

public void moveTo(Location point)
Moves the Text object within the canvas to the specified Location.
Overrides:
moveTo in class Drawable
Parameters:
point - the coordinates of the upper left corner of the object's new bounding box

move

public void move(double dx,
                 double dy)
Moves the Text object within the canvas by the amount specified in the x and y direction.
Overrides:
move in class Drawable
Parameters:
dx - the amount to move in the x-direction
dy - the amount to move in the y-direction

getFont

public java.awt.Font getFont()
Retrieves the text object's font.
Returns:
the font

setText

public void setText(java.lang.String text)
Sets the text object's value to the String text.
Parameters:
text - the text

setText

public void setText(long text)
Sets the text object's value to the short, int, byte, or long text.
Parameters:
text - the text

setText

public void setText(boolean text)
Sets the text object's value to the boolean text.
Parameters:
text - the text

setText

public void setText(char text)
Sets the text object's value to the char text
Parameters:
text - the text

setText

public void setText(double text)
Sets the text object's value to the double text
Parameters:
text - the text

setText

public void setText(java.lang.Object text)
Sets the text object's value to the Object text
Parameters:
text - the text

setFont

public void setFont(java.awt.Font f)
Sets the text object's font.
Parameters:
f - the font

getText

public java.lang.String getText()
Gets the text of the object.
Returns:
the text's objects text

setFont

public void setFont(java.lang.String fname)
Sets the text object's font.
Parameters:
f - the font

setFontSize

public void setFontSize(int size)
Sets the text object's font size.
Parameters:
size - the font size in points

setItalic

public void setItalic()
Deprecated. Deprecated since objectdraw 4, use setItalic(boolean) instead.

Sets the text object's font to have italic style.

setItalic

public void setItalic(boolean bool)
Toggles whether the text object's style is italics or not.
Parameters:
bool - defines whether the text object is italics or not

setBold

public void setBold()
Deprecated. Deprecated since objectdraw 4, use setBold(boolean) instead.

Sets the text object's font to have bold style.

setBold

public void setBold(boolean bool)
Toggles whether the text object's style is bold or not.
Parameters:
bool - defines whether the text object is bold or not

setPlain

public void setPlain()
Sets the text object's font to have plain style.

toString

public java.lang.String toString()
Generates a string representation of the object.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object