objectdraw
Class Text

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

public class Text
extends objectdraw.Drawable2D
implements Drawable2DInterface

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

Version:
1.1.2 released July 2006
See Also:
Serialized Form

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(java.lang.Object text, double x, double y, DrawingCanvas canvas)
          Creates a new Text object that displays an arbitrary Object.
Text(java.lang.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.
 boolean contains(Location point)
          Determines if a particular position on the DrawingCanvas is contained within the object.
 DrawingCanvas getCanvas()
          Determine which (if any) DrawingCanvas this object is positioned on
 java.awt.Color getColor()
          Retrieves the color of the object.
 java.awt.Font getFont()
          Retrieves the text object's font.
 double getHeight()
          Get the height of a graphical object
 Location getLocation()
          Get a graphical object's position
 java.lang.String getText()
          Gets the text of the object.
 double getWidth()
          Get the width of a graphical object
 double getX()
          Get the x coordinate of left edge of rectangle bounding the object
 double getY()
          Get the y coordinate of top edge of rectangle bounding the object
 void hide()
          Temporarily hides an object on a DrawingCanvas from view.
 boolean isHidden()
          Determine whether an object is currently visible on its canvas
 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(double x, double y)
          Moves the object within the canvas to the x and y coordinates provided.
 void moveTo(Location point)
          Moves the object within the canvas to the specified Location
 boolean overlaps(Drawable2DInterface item)
          Determines if another Drawable's bounding rectangle overlaps with this object's bounding rectangle.
 void removeFromCanvas()
          Permanently removes the object from the canvas it is currently on.
 void sendBackward()
          Sends the object backward.
 void sendForward()
          Sends the object forward.
 void sendToBack()
          Sends the object to the back.
 void sendToFront()
          Sends the object to the front.
 void setBold()
          Deprecated. Use setBold(boolean) instead.
 void setBold(boolean bool)
          Toggles whether the text object's style is bold or not.
 void setColor(java.awt.Color c)
          Sets the color of the object.
 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. 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 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(java.lang.Object text)
          Sets the text object's value to a representation of the Object text
 void setText(java.lang.String text)
          Sets the text object's value to the String text.
 void show()
          Shows the object if it has been hidden.
 java.lang.String toString()
          Generates a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, 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
 

Constructor Detail

Text

public Text(java.lang.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

Text

public Text(java.lang.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(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(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(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(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(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(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(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(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
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

getWidth

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

Specified by:
getWidth in interface Drawable2DInterface

getHeight

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

Specified by:
getHeight in interface Drawable2DInterface

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

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

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 representation of a short, int, byte, or long value.

Parameters:
text - the numeric value to be displayed

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(java.lang.Object text)
Sets the text object's value to a representation of the Object text

Parameters:
text - the object to be displayed

getText

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

Returns:
the String displayed by the text object

setFont

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

Parameters:
f - the font

setFont

public void setFont(java.lang.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()
Deprecated. 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. 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.

Returns:
a string representation of the object

getX

public double getX()
Description copied from interface: Drawable2DInterface
Get the x coordinate of left edge of rectangle bounding the object

Specified by:
getX in interface Drawable2DInterface
Returns:
the x coordinate of the upper left corner of the object's bounding rectangle

getY

public double getY()
Description copied from interface: Drawable2DInterface
Get the y coordinate of top edge of rectangle bounding the object

Specified by:
getY in interface Drawable2DInterface
Returns:
the y coordinate of the upper left corner of the object's bounding rectangle

getLocation

public Location getLocation()
Description copied from interface: Drawable2DInterface
Get a graphical object's position

Specified by:
getLocation in interface Drawable2DInterface
Returns:
the location of the upper left corner of the object's bounding rectangle

contains

public boolean contains(Location point)
Description copied from interface: DrawableInterface
Determines if a particular position on the DrawingCanvas is contained within the object.

Specified by:
contains in interface DrawableInterface

overlaps

public boolean overlaps(Drawable2DInterface item)
Description copied from interface: Drawable2DInterface
Determines if another Drawable's bounding rectangle overlaps with this object's bounding rectangle.

Specified by:
overlaps in interface Drawable2DInterface
Parameters:
item - the other object
Returns:
true if item intersects this object; false otherwise.

removeFromCanvas

public void removeFromCanvas()
Description copied from interface: DrawableInterface
Permanently removes the object from the canvas it is currently on. If you want to just make an object temporarily invisible, use hide() instead.

Specified by:
removeFromCanvas in interface DrawableInterface

getCanvas

public DrawingCanvas getCanvas()
Description copied from interface: DrawableInterface
Determine which (if any) DrawingCanvas this object is positioned on

Specified by:
getCanvas in interface DrawableInterface
Returns:
the DrawingCanvas holding this object or null if it the object is not currently associated with any canvas

hide

public void hide()
Description copied from interface: DrawableInterface
Temporarily hides an object on a DrawingCanvas from view. This method should only be used if the object may later be made visible again using the show() method. If the goal is to remove an object from the display permanently, the removeFromCanvas() method should be used instead.

Specified by:
hide in interface DrawableInterface

show

public void show()
Description copied from interface: DrawableInterface
Shows the object if it has been hidden.

Specified by:
show in interface DrawableInterface

isHidden

public boolean isHidden()
Description copied from interface: DrawableInterface
Determine whether an object is currently visible on its canvas

Specified by:
isHidden in interface DrawableInterface
Returns:
true if the object is currently hidden.

moveTo

public void moveTo(double x,
                   double y)
Description copied from interface: DrawableInterface
Moves the object within the canvas to the x and y coordinates provided.

Specified by:
moveTo in interface DrawableInterface
Parameters:
x - horizontal coordinate of destination.
y - horizontal coordinate of destination.

setColor

public void setColor(java.awt.Color c)
Description copied from interface: DrawableInterface
Sets the color of the object.

Specified by:
setColor in interface DrawableInterface
Parameters:
c - the color.

getColor

public java.awt.Color getColor()
Description copied from interface: DrawableInterface
Retrieves the color of the object.

Specified by:
getColor in interface DrawableInterface
Returns:
the object's color.

sendForward

public void sendForward()
Description copied from interface: DrawableInterface
Sends the object forward.

Specified by:
sendForward in interface DrawableInterface

sendBackward

public void sendBackward()
Description copied from interface: DrawableInterface
Sends the object backward.

Specified by:
sendBackward in interface DrawableInterface

sendToFront

public void sendToFront()
Description copied from interface: DrawableInterface
Sends the object to the front.

Specified by:
sendToFront in interface DrawableInterface

sendToBack

public void sendToBack()
Description copied from interface: DrawableInterface
Sends the object to the back.

Specified by:
sendToBack in interface DrawableInterface