|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectobjectdraw.Drawable
objectdraw.Drawable2D
objectdraw.Text
public class Text
Text is an implementation of text strings that can be drawn on a Drawingcanvas.
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 |
---|
protected double baseHeight
protected DrawingCanvas canvas
protected FontMetrics fm
protected Font font
protected Graphics g
protected double height
protected Location origin
protected String text
protected double width
Constructor Detail |
---|
public Text(boolean text, double x, double y, DrawingCanvas canvas)
text
- the boolean to be displayedx
- coordinate of the upper left corner of the bounding rectangley
- coordinate of the upper left corner of the bounding rectanglecanvas
- the canvas into which the text will be drawnpublic Text(boolean text, Location origin, DrawingCanvas canvas)
text
- the boolean to be displayedorigin
- the upper left corner of the bounding region for the text
displayedcanvas
- the canvas into which the text will be drawnpublic Text(char text, double x, double y, DrawingCanvas canvas)
text
- the char to be displayedx
- coordinate of the upper left corner of the bounding rectangley
- coordinate of the upper left corner of the bounding rectanglecanvas
- the canvas into which the text will be drawnpublic Text(char text, Location origin, DrawingCanvas canvas)
text
- the char to be displayedorigin
- the upper left corner of the bounding region for the text
displayedcanvas
- the canvas into which the text will be drawnpublic Text(double text, double x, double y, DrawingCanvas canvas)
text
- the numeric value to be displayedx
- coordinate of the upper left corner of the bounding rectangley
- coordinate of the upper left corner of the bounding rectanglecanvas
- the canvas into which the text will be drawnpublic Text(double text, Location origin, DrawingCanvas canvas)
text
- the numeric value to be displayedorigin
- the upper left corner of the bounding region for the displaycanvas
- the canvas into which the text will be drawnpublic Text(long text, double x, double y, DrawingCanvas canvas)
text
- the numeric value to be displayedx
- coordinate of the upper left corner of the bounding rectangley
- coordinate of the upper left corner of the bounding rectanglecanvas
- the canvas into which the text will be drawnpublic Text(long text, Location origin, DrawingCanvas canvas)
text
- the numeric value to be displayedorigin
- the upper left corner of the bounding region for the
information displayedcanvas
- the canvas into which the text will be drawnpublic Text(Object text, double x, double y, DrawingCanvas canvas)
text
- the object to be displayedx
- coordinate of the upper left corner of the bounding rectangley
- coordinate of the upper left corner of the bounding rectanglecanvas
- the canvas into which the text will be drawnpublic Text(Object text, Location origin, DrawingCanvas canvas)
text
- the object to be displayedorigin
- the upper left corner of the bounding region for the text that
appearscanvas
- the canvas into which the text will be drawnMethod Detail |
---|
public void addToCanvas(DrawingCanvas canvas)
DrawableInterface
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.
addToCanvas
in interface DrawableInterface
addToCanvas
in class Drawable
canvas
- the canvas on which the object should be drawnvoid draw(Graphics g)
draw
in class Drawable2D
g
- the graphics context into which the object is drawnBounds getBounds()
getBounds
in class Drawable2D
public Font getFont()
public double getHeight()
Drawable2DInterface
getHeight
in interface Drawable2DInterface
getHeight
in class Drawable2D
public String getText()
public double getWidth()
Drawable2DInterface
getWidth
in interface Drawable2DInterface
getWidth
in class Drawable2D
public void move(double dx, double dy)
DrawableInterface
move
in interface DrawableInterface
move
in class Drawable
dx
- the amount to move in the x-direction.dy
- the amount to move in the y-direction.public void moveTo(Location point)
DrawableInterface
moveTo
in interface DrawableInterface
moveTo
in class Drawable
point
- the destination for moving the object.public void setBold(boolean bool)
bool
- defines whether the text object is bold or notpublic void setFont(Font f)
f
- the fontpublic void setFont(String fname)
fname
- -
the fontpublic void setFontSize(int size)
size
- the font size in pointspublic void setItalic(boolean bool)
bool
- defines whether the text object is italics or notpublic void setPlain()
public void setText(boolean text)
text
- the boolean to be displayedpublic void setText(char text)
text
- the char to be displayedpublic void setText(double text)
text
- the number to be displayedpublic void setText(long text)
text
- the numeric value to be displayedpublic void setText(Object text)
text
- the object to be displayedpublic void setText(String text)
text
- the textpublic String toString()
toString
in class Object
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |