edu.rit.draw.item
Class Text

java.lang.Object
  extended by edu.rit.draw.item.DrawingItem
      extended by edu.rit.draw.item.Text
All Implemented Interfaces:
Externalizable, Serializable

public class Text
extends DrawingItem
implements Externalizable

Class Text provides a textual DrawingItem. A text item has these attributes:

Class Text supports a subset of HTML for specifying attributes of characters. The following HTML tags may be embedded in the text:

To get literal less-than, greater-than, and ampersand characters in the text, use the following HTML character entities:

See Also:
Serialized Form

Nested Class Summary
static class Text.Alignment
          Enumeration Text.Alignment specifies the alignment of multiple lines in a Text item.
 
Field Summary
static Text.Alignment NORMAL_ALIGNMENT
          The normal alignment (left).
static Bullet NORMAL_BULLET
          The normal bullet (none).
static Fill NORMAL_FILL
          The normal fill paint (black).
static Font NORMAL_FONT
          The normal font (sanserif, plain, 12 point).
static double NORMAL_SPACING
          The normal line spacing factor (7/6).
 
Constructor Summary
Text()
          Construct a new text item.
Text(Text theItem)
          Construct a new text item with the same text, location, and attributes as the given text item.
 
Method Summary
 Text add()
          Add this text item to the end of the default drawing's sequence of drawing items.
 Text add(Drawing theDrawing)
          Add this text item to the end of the given drawing's sequence of drawing items.
 Text addFirst()
          Add this text item to the beginning of the default drawing's sequence of drawing items.
 Text addFirst(Drawing theDrawing)
          Add this text item to the beginning of the given drawing's sequence of drawing items.
 Text.Alignment align()
          Returns this text item's text alignment.
 Text align(Text.Alignment theAlignment)
          Set this text item's text alignment.
 Bullet bullet()
          Returns this text item's bullet.
 Text bullet(Bullet theBullet)
          Set this text item's bullet.
 Text c(double x, double y)
          Set the center point of this text item's bounding box.
 Text c(Point thePoint)
          Set the center point of this text item's bounding box.
static Text.Alignment defaultAlign()
          Returns the default text alignment.
static void defaultAlign(Text.Alignment theAlignment)
          Set the default text alignment.
static Bullet defaultBullet()
          Returns the default bullet.
static void defaultBullet(Bullet theBullet)
          Set the default bullet.
static Fill defaultFill()
          Returns the default fill paint.
static void defaultFill(Fill theFill)
          Set the default fill paint.
static Font defaultFont()
          Returns the default font.
static void defaultFont(Font theFont)
          Set the default font.
static double defaultSpacing()
          Returns the default line spacing factor.
static void defaultSpacing(double theSpacing)
          Set the default line spacing factor.
 void draw(Graphics2D g2d)
          Draw this text item in the given graphics context.
 Text e(double x, double y)
          Set the east middle point of this text item's bounding box.
 Text e(Point thePoint)
          Set the east middle point of this text item's bounding box.
 Fill fill()
          Returns this text item's fill paint.
 Text fill(Fill theFill)
          Set this text item's fill paint.
 Font font()
          Returns this text item's font.
 Text font(Font theFont)
          Set this text item's font.
 double height()
          Returns the height of this text item's bounding box.
 Text n(double x, double y)
          Set the north middle point of this text item's bounding box.
 Text n(Point thePoint)
          Set the north middle point of this text item's bounding box.
 Text ne(double x, double y)
          Set the northeast corner point of this text item's bounding box.
 Text ne(Point thePoint)
          Set the northeast corner point of this text item's bounding box.
 Point nw()
          Returns the northwest corner point of this text item's bounding box.
 Text nw(double x, double y)
          Set the northwest corner point of this text item's bounding box.
 Text nw(Point thePoint)
          Set the northwest corner point of this text item's bounding box.
 void readExternal(ObjectInput in)
          Read this text item from the given object input stream.
 Text s(double x, double y)
          Set the south middle point of this text item's bounding box.
 Text s(Point thePoint)
          Set the south middle point of this text item's bounding box.
 Text se(double x, double y)
          Set the southeast corner point of this text item's bounding box.
 Text se(Point thePoint)
          Set the southeast corner point of this text item's bounding box.
 double spacing()
          Returns this text item's line spacing factor.
 Text spacing(double theSpacing)
          Set this text item's line spacing factor.
 Text sw(double x, double y)
          Set the southwest corner point of this text item's bounding box.
 Text sw(Point thePoint)
          Set the southwest corner point of this text item's bounding box.
 String text()
          Returns this text item's text.
 Text text(String theText)
          Set this text item's text.
 Text w(double x, double y)
          Set the west middle point of this text item's bounding box.
 Text w(Point thePoint)
          Set the west middle point of this text item's bounding box.
 double width()
          Returns the width of this text item's bounding box.
 void writeExternal(ObjectOutput out)
          Write this text item to the given object output stream.
 
Methods inherited from class edu.rit.draw.item.DrawingItem
boundingBox, c, e, n, ne, s, se, size, sw, w
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORMAL_FONT

public static final Font NORMAL_FONT
The normal font (sanserif, plain, 12 point).


NORMAL_FILL

public static final Fill NORMAL_FILL
The normal fill paint (black).


NORMAL_SPACING

public static final double NORMAL_SPACING
The normal line spacing factor (7/6).

See Also:
Constant Field Values

NORMAL_ALIGNMENT

public static final Text.Alignment NORMAL_ALIGNMENT
The normal alignment (left).


NORMAL_BULLET

public static final Bullet NORMAL_BULLET
The normal bullet (none).

Constructor Detail

Text

public Text()
Construct a new text item. The text item's text is empty. The text item's northwest corner is located at (0,0). The text item's attributes have the default values.


Text

public Text(Text theItem)
Construct a new text item with the same text, location, and attributes as the given text item.

Parameters:
theItem - Text item.
Throws:
NullPointerException - (unchecked exception) Thrown if theItem is null.
Method Detail

defaultFont

public static Font defaultFont()
Returns the default font.

Returns:
Default font.

defaultFont

public static void defaultFont(Font theFont)
Set the default font. Before calling this method the first time, the default font is sanserif, plain, 12 point.

Parameters:
theFont - Default font.
Throws:
NullPointerException - (unchecked exception) Thrown if theFont is null.

defaultFill

public static Fill defaultFill()
Returns the default fill paint.

Returns:
Default fill paint.

defaultFill

public static void defaultFill(Fill theFill)
Set the default fill paint. Before calling this method the first time, the default fill paint is black.

Parameters:
theFill - Default fill paint.
Throws:
NullPointerException - (unchecked exception) Thrown if theFill is null.

defaultSpacing

public static double defaultSpacing()
Returns the default line spacing factor. The line spacing factor is multiplied by the font size to get the actual inter-line distance.

Returns:
Default line spacing factor.

defaultSpacing

public static void defaultSpacing(double theSpacing)
Set the default line spacing factor. The line spacing factor is multiplied by the font size to get the actual inter-line distance. Before calling this method the first time, the default line spacing factor is 7/6.

Parameters:
theSpacing - Default line spacing factor.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theSpacing is less than 0.

defaultAlign

public static Text.Alignment defaultAlign()
Returns the default text alignment.

Returns:
Default text alignment.

defaultAlign

public static void defaultAlign(Text.Alignment theAlignment)
Set the default text alignment. Before calling this method the first time, the default text alignment is left alignment.

Parameters:
theAlignment - Default text alignment.
Throws:
NullPointerException - (unchecked exception) Thrown if theAlignment is null.

defaultBullet

public static Bullet defaultBullet()
Returns the default bullet.

Returns:
Default bullet.

defaultBullet

public static void defaultBullet(Bullet theBullet)
Set the default bullet. Before calling this method the first time, the default bullet is none.

Parameters:
theBullet - Default bullet.

text

public String text()
Returns this text item's text. Newline characters ('\n') separate multiple lines within the text.

Returns:
Text (may be null).

text

public Text text(String theText)
Set this text item's text. Newline characters ('\n') separate multiple lines within the text.

Parameters:
theText - Text (may be null).
Returns:
This text item.

font

public Font font()
Returns this text item's font.

Returns:
Font.

font

public Text font(Font theFont)
Set this text item's font.

Parameters:
theFont - Font.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if theFont is null.

fill

public Fill fill()
Returns this text item's fill paint.

Returns:
Fill paint.

fill

public Text fill(Fill theFill)
Set this text item's fill paint.

Parameters:
theFill - Fill paint.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if theFill is null.

spacing

public double spacing()
Returns this text item's line spacing factor. The line spacing factor is multiplied by the font size to get the actual inter-line distance.

Returns:
Line spacing factor.

spacing

public Text spacing(double theSpacing)
Set this text item's line spacing factor. The line spacing factor is multiplied by the font size to get the actual inter-line distance.

Parameters:
theSpacing - Line spacing factor.
Returns:
This text item.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if theSpacing is less than 0.

align

public Text.Alignment align()
Returns this text item's text alignment.

Returns:
Text alignment.

align

public Text align(Text.Alignment theAlignment)
Set this text item's text alignment.

Parameters:
theAlignment - Text alignment.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if theAlignment is null.

bullet

public Bullet bullet()
Returns this text item's bullet.

Returns:
Bullet.

bullet

public Text bullet(Bullet theBullet)
Set this text item's bullet.

Parameters:
theBullet - Default bullet.
Returns:
This text item.

width

public double width()
Returns the width of this text item's bounding box.

Specified by:
width in class DrawingItem
Returns:
Width.

height

public double height()
Returns the height of this text item's bounding box.

Specified by:
height in class DrawingItem
Returns:
Height.

nw

public Point nw()
Returns the northwest corner point of this text item's bounding box.

Specified by:
nw in class DrawingItem
Returns:
Northwest corner point.

nw

public Text nw(double x,
               double y)
Set the northwest corner point of this text item's bounding box.

Parameters:
x - X coordinate of northwest corner point.
y - Y coordinate of northwest corner point.
Returns:
This text item.

nw

public Text nw(Point thePoint)
Set the northwest corner point of this text item's bounding box.

Parameters:
thePoint - Northwest corner point.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

n

public Text n(double x,
              double y)
Set the north middle point of this text item's bounding box.

Parameters:
x - X coordinate of north middle point.
y - Y coordinate of north middle point.
Returns:
This text item.

n

public Text n(Point thePoint)
Set the north middle point of this text item's bounding box.

Parameters:
thePoint - North middle point.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

ne

public Text ne(double x,
               double y)
Set the northeast corner point of this text item's bounding box.

Parameters:
x - X coordinate of northeast corner point.
y - Y coordinate of northeast corner point.
Returns:
This text item.

ne

public Text ne(Point thePoint)
Set the northeast corner point of this text item's bounding box.

Parameters:
thePoint - Northeast corner point.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

w

public Text w(double x,
              double y)
Set the west middle point of this text item's bounding box.

Parameters:
x - X coordinate of west middle point.
y - Y coordinate of west middle point.
Returns:
This text item.

w

public Text w(Point thePoint)
Set the west middle point of this text item's bounding box.

Parameters:
thePoint - West middle point.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

c

public Text c(double x,
              double y)
Set the center point of this text item's bounding box.

Parameters:
x - X coordinate of center point.
y - Y coordinate of center point.
Returns:
This text item.

c

public Text c(Point thePoint)
Set the center point of this text item's bounding box.

Parameters:
thePoint - Center point.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

e

public Text e(double x,
              double y)
Set the east middle point of this text item's bounding box.

Parameters:
x - X coordinate of east middle point.
y - Y coordinate of east middle point.
Returns:
This text item.

e

public Text e(Point thePoint)
Set the east middle point of this text item's bounding box.

Parameters:
thePoint - East middle point.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

sw

public Text sw(double x,
               double y)
Set the southwest corner point of this text item's bounding box.

Parameters:
x - X coordinate of southwest corner point.
y - Y coordinate of southwest corner point.
Returns:
This text item.

sw

public Text sw(Point thePoint)
Set the southwest corner point of this text item's bounding box.

Parameters:
thePoint - Southwest corner point.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

s

public Text s(double x,
              double y)
Set the south middle point of this text item's bounding box.

Parameters:
x - X coordinate of south middle point.
y - Y coordinate of south middle point.
Returns:
This text item.

s

public Text s(Point thePoint)
Set the south middle point of this text item's bounding box.

Parameters:
thePoint - South middle point.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

se

public Text se(double x,
               double y)
Set the southeast corner point of this text item's bounding box.

Parameters:
x - X coordinate of southeast corner point.
y - Y coordinate of southeast corner point.
Returns:
This text item.

se

public Text se(Point thePoint)
Set the southeast corner point of this text item's bounding box.

Parameters:
thePoint - Southeast corner point.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if thePoint is null.

add

public Text add()
Add this text item to the end of the default drawing's sequence of drawing items.

Overrides:
add in class DrawingItem
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no default drawing.
See Also:
Drawing.defaultDrawing()

add

public Text add(Drawing theDrawing)
Add this text item to the end of the given drawing's sequence of drawing items.

Overrides:
add in class DrawingItem
Parameters:
theDrawing - Drawing.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if theDrawing is null.

addFirst

public Text addFirst()
Add this text item to the beginning of the default drawing's sequence of drawing items.

Overrides:
addFirst in class DrawingItem
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if there is no default drawing.
See Also:
Drawing.defaultDrawing()

addFirst

public Text addFirst(Drawing theDrawing)
Add this text item to the beginning of the given drawing's sequence of drawing items.

Overrides:
addFirst in class DrawingItem
Parameters:
theDrawing - Drawing.
Returns:
This text item.
Throws:
NullPointerException - (unchecked exception) Thrown if theDrawing is null.

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Write this text item to the given object output stream.

Specified by:
writeExternal in interface Externalizable
Overrides:
writeExternal in class DrawingItem
Parameters:
out - Object output stream.
Throws:
IOException - Thrown if an I/O error occurred.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Read this text item from the given object input stream.

Specified by:
readExternal in interface Externalizable
Overrides:
readExternal in class DrawingItem
Parameters:
in - Object input stream.
Throws:
IOException - Thrown if an I/O error occurred.
ClassNotFoundException - Thrown if any class needed to deserialize this text item cannot be found.

draw

public void draw(Graphics2D g2d)
Draw this text item in the given graphics context. This method is allowed to change the graphics context's paint, stroke, and transform, and it doesn't have to change them back.

Overrides:
draw in class DrawingItem
Parameters:
g2d - 2-D graphics context.


Copyright © 2005-2012 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.