objectdraw
Class Text

java.lang.Object
  extended by objectdraw.Drawable
      extended by objectdraw.Drawable2D
          extended by objectdraw.Text
All Implemented Interfaces:
Serializable, Drawable2DInterface, DrawableInterface

public class Text
extends Drawable2D
implements Drawable2DInterface

Text is an implementation of text strings that can be drawn on a Drawingcanvas.

Version:
1.1.1 released February 2005
See Also:
Serialized Form

Field Summary
protected  double baseHeight
          The text's height above baseline.
protected  DrawingCanvas canvas
          The convas on which the text is displayed
protected  FontMetrics fm
          The Font metrics object associated with the canvas holding this text
protected  Font font
          The text's font.
protected  Graphics g
          The Graphics object associated with the canvas holding this text
protected  double height
          The text's height.
protected  Location origin
          The location of the upper-left-most point of the text
protected  String text
          The object's text contents.
protected  double width
          The text's width.
 
Fields inherited from class objectdraw.Drawable
canvasContent, color, shown
 
Constructor Summary
Text(boolean text, double x, double y, DrawingCanvas canvas)
          Creates a new Text object that displays a boolean.
Text(boolean text, Location origin, DrawingCanvas canvas)
          Creates a new Text object that displays a boolean.
Text(char text, double x, double y, DrawingCanvas canvas)
          Creates a new Text object that displays a char.
Text(char text, Location origin, DrawingCanvas canvas)
          Creates a new Text object that displays a char.
Text(double text, double x, double y, DrawingCanvas canvas)
          Creates a new Text object that displays a double or float.
Text(double text, Location origin, DrawingCanvas canvas)
          Creates a new Text object that displays a double or float.
Text(long text, double x, double y, DrawingCanvas canvas)
          Creates a new Text object that displays a short, int, byte or long.
Text(long text, Location origin, DrawingCanvas canvas)
          Creates a new Text object that displays a short, int, byte or long.
Text(Object text, double x, double y, DrawingCanvas canvas)
          Creates a new Text object that displays an arbitrary Object.
Text(Object text, Location origin, DrawingCanvas canvas)
          Creates a new Text object that displays an arbitrary Object.
 
Method Summary
 void addToCanvas(DrawingCanvas canvas)
          Places an existing object on a specified DrawingCanvas.
(package private)  void draw(Graphics g)
          Draws the object.
(package private)  Bounds getBounds()
          Retrieves the bounding rectangle of the object.
 Font getFont()
          Retrieves the text object's font.
 double getHeight()
          Get the height of a graphical object
 String getText()
          Gets the text of the object.
 double getWidth()
          Get the width of a graphical object
 void move(double dx, double dy)
          Moves the object within the canvas in the x and y direction by the amounts specified as parameters.
 void moveTo(Location point)
          Moves the object within the canvas to the specified Location
 void setBold(boolean bool)
          Toggles whether the text object's style is bold or not.
 void setFont(Font f)
          Sets the text object's font.
 void setFont(String fname)
          Sets the text object's font.
 void setFontSize(int size)
          Sets the text object's font size.
 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 display a boolean value.
 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 text representation of a double
 void setText(long text)
          Sets the text object's value to the representation of a short, int, byte, or long value.
 void setText(Object text)
          Sets the text object's value to a representation of the Object text
 void setText(String text)
          Sets the text object's value to the String text.
 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
clearCanvasContent, getCanvas, getColor, hide, isHidden, moveTo, removeFromCanvas, sendBackward, sendForward, sendToBack, sendToFront, setCanvasContent, 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.Drawable2DInterface
getLocation, getX, getY, overlaps
 
Methods inherited from interface objectdraw.DrawableInterface
contains, getCanvas, getColor, hide, isHidden, moveTo, removeFromCanvas, sendBackward, sendForward, sendToBack, sendToFront, setColor, show
 

Field Detail

baseHeight

protected double baseHeight
The text's height above baseline.


canvas

protected DrawingCanvas canvas
The convas on which the text is displayed


fm

protected FontMetrics fm
The Font metrics object associated with the canvas holding this text


font

protected Font font
The text's font.


g

protected Graphics g
The Graphics object associated with the canvas holding this text


height

protected double height
The text's height.


origin

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


text

protected String text
The object's text contents.


width

protected double width
The text's width.

Constructor Detail

Text

public Text(boolean text,
            double x,
            double y,
            DrawingCanvas canvas)
Creates a new Text object that displays a boolean.

Parameters:
text - the boolean to be displayed
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
canvas - the canvas into which the text will be drawn

Text

public Text(boolean text,
            Location origin,
            DrawingCanvas canvas)
Creates a new Text object that displays a boolean.

Parameters:
text - the boolean to be displayed
origin - the upper left corner of the bounding region for the text displayed
canvas - the canvas into which the text will be drawn

Text

public Text(char text,
            double x,
            double y,
            DrawingCanvas canvas)
Creates a new Text object that displays a char.

Parameters:
text - the char to be displayed
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
canvas - the canvas into which the text will be drawn

Text

public Text(char text,
            Location origin,
            DrawingCanvas canvas)
Creates a new Text object that displays a char.

Parameters:
text - the char to be displayed
origin - the upper left corner of the bounding region for the text displayed
canvas - the canvas into which the text will be drawn

Text

public Text(double text,
            double x,
            double y,
            DrawingCanvas canvas)
Creates a new Text object that displays a double or float.

Parameters:
text - the numeric value to be displayed
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
canvas - the canvas into which the text will be drawn

Text

public Text(double text,
            Location origin,
            DrawingCanvas canvas)
Creates a new Text object that displays a double or float.

Parameters:
text - the numeric value to be displayed
origin - the upper left corner of the bounding region for the display
canvas - the canvas into which the text will be drawn

Text

public Text(long text,
            double x,
            double y,
            DrawingCanvas canvas)
Creates a new Text object that displays a short, int, byte or long.

Parameters:
text - the numeric value to be displayed
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
canvas - the canvas into which the text will be drawn

Text

public Text(long text,
            Location origin,
            DrawingCanvas canvas)
Creates a new Text object that displays a short, int, byte or long.

Parameters:
text - the numeric value to be displayed
origin - the upper left corner of the bounding region for the information displayed
canvas - the canvas into which the text will be drawn

Text

public Text(Object text,
            double x,
            double y,
            DrawingCanvas canvas)
Creates a new Text object that displays an arbitrary Object.

Parameters:
text - the object to be displayed
x - coordinate of the upper left corner of the bounding rectangle
y - coordinate of the upper left corner of the bounding rectangle
canvas - the canvas into which the text will be drawn

Text

public Text(Object text,
            Location origin,
            DrawingCanvas canvas)
Creates a new Text object that displays an arbitrary Object.

Parameters:
text - the object to be displayed
origin - the upper left corner of the bounding region for the text that appears
canvas - the canvas into which the text will be drawn
Method Detail

addToCanvas

public void addToCanvas(DrawingCanvas canvas)
Description copied from interface: DrawableInterface
Places an existing object on a specified DrawingCanvas. This method will fail if the object is already on a canvas. Therefore, to move an object from one canvas to another one must use removeFromCanvas() followed by addToCanvas. This method can also be invoked to place a Drawable object on a DrawingCanvas after the object is loaded from a file or other stream.

Specified by:
addToCanvas in interface DrawableInterface
Overrides:
addToCanvas in class Drawable
Parameters:
canvas - the canvas on which the object should be drawn

draw

void draw(Graphics g)
Draws the object.

Overrides:
draw in class Drawable2D
Parameters:
g - the graphics context into which the object is drawn

getBounds

Bounds getBounds()
Retrieves the bounding rectangle of the object.

Specified by:
getBounds in class Drawable2D
Returns:
the bounding rectangle

getFont

public Font getFont()
Retrieves the text object's font.

Returns:
the font

getHeight

public double getHeight()
Description copied from interface: Drawable2DInterface
Get the height of a graphical object

Specified by:
getHeight in interface Drawable2DInterface
Specified by:
getHeight in class Drawable2D
Returns:
the height of the object's bounding rectangle

getText

public String getText()
Gets the text of the object.

Returns:
the String displayed by the text object

getWidth

public double getWidth()
Description copied from interface: Drawable2DInterface
Get the width of a graphical object

Specified by:
getWidth in interface Drawable2DInterface
Specified by:
getWidth in class Drawable2D
Returns:
the width of the object's bounding rectangle

move

public void move(double dx,
                 double dy)
Description copied from interface: DrawableInterface
Moves the object within the canvas in the x and y direction by the amounts specified as parameters.

Specified by:
move in interface DrawableInterface
Specified by:
move in class Drawable
Parameters:
dx - the amount to move in the x-direction.
dy - the amount to move in the y-direction.

moveTo

public void moveTo(Location point)
Description copied from interface: DrawableInterface
Moves the object within the canvas to the specified Location

Specified by:
moveTo in interface DrawableInterface
Overrides:
moveTo in class Drawable
Parameters:
point - the destination for moving the object.

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

setFont

public void setFont(Font f)
Sets the text object's font.

Parameters:
f - the font

setFont

public void setFont(String fname)
Sets the text object's font.

Parameters:
fname - - 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(boolean bool)
Toggles whether the text object's style is italics or not.

Parameters:
bool - defines whether the text object is italics or not

setPlain

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


setText

public void setText(boolean text)
Sets the text object's value to display a boolean value.

Parameters:
text - the boolean to be displayed

setText

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

Parameters:
text - the char to be displayed

setText

public void setText(double text)
Sets the text object's value to the text representation of a double

Parameters:
text - the number to be displayed

setText

public void setText(long text)
Sets the text object's value to the representation of a short, int, byte, or long value.

Parameters:
text - the numeric value to be displayed

setText

public void setText(Object text)
Sets the text object's value to a representation of the Object text

Parameters:
text - the object to be displayed

setText

public void setText(String text)
Sets the text object's value to the String text.

Parameters:
text - the text

toString

public String toString()
Generates a string representation of the object.

Overrides:
toString in class Object
Returns:
a string representation of the object