edu.rit.draw.item
Class Text
- java.lang.Object
-
- edu.rit.draw.item.DrawingItem
-
- edu.rit.draw.item.Text
-
- All Implemented Interfaces:
- java.io.Externalizable, java.io.Serializable
public class Text extends DrawingItem implements java.io.Externalizable
Class Text provides a textual DrawingItem. A text item has these attributes:- Text -- The text to be displayed. The text consists of one or more lines. A newline character ('\n') separates each line from the next.
- Font -- The font in which to display the text. All the text is displayed in the same font.
- Fill -- The fill paint with which to display the text.
- Spacing -- The vertical distance between consecutive lines. This is specified as a factor which is multiplied by the font size to get the actual inter-line distance.
- Alignment -- Whether multiple lines are aligned left, center, or right.
- Bullet -- The bullet, if any, attached to the text. The bullet is always displayed to the left of the first line of the text.
- Position -- The text occupies a rectangular area. The text's position is specified by giving the (x,y) coordinates of the text area's northwest, north, northeast, west, center, east, southwest, south, or southeast point.
Class Text supports a subset of HTML for specifying attributes of characters. The following HTML tags may be embedded in the text:
- <B>Bold</B>
- <I>Italic</I>
- <SUP>Superscript</SUP>
- <SUB>Subscript</SUB>
To get literal less-than, greater-than, and ampersand characters in the text, use the following HTML character entities:
- < -- Less-than (<)
- > -- Greater-than (>)
- & -- Ampersand (&)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classText.AlignmentEnumeration Text.Alignment specifies the alignment of multiple lines in a Text item.
-
Field Summary
Fields Modifier and Type Field and Description static Text.AlignmentNORMAL_ALIGNMENTThe normal alignment (left).static BulletNORMAL_BULLETThe normal bullet (none).static FillNORMAL_FILLThe normal fill paint (black).static java.awt.FontNORMAL_FONTThe normal font (sanserif, plain, 12 point).static doubleNORMAL_SPACINGThe normal line spacing factor (7/6).
-
Constructor Summary
Constructors Constructor and Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description Textadd()Add this text item to the end of the default drawing's sequence of drawing items.Textadd(Drawing theDrawing)Add this text item to the end of the given drawing's sequence of drawing items.TextaddFirst()Add this text item to the beginning of the default drawing's sequence of drawing items.TextaddFirst(Drawing theDrawing)Add this text item to the beginning of the given drawing's sequence of drawing items.Text.Alignmentalign()Returns this text item's text alignment.Textalign(Text.Alignment theAlignment)Set this text item's text alignment.Bulletbullet()Returns this text item's bullet.Textbullet(Bullet theBullet)Set this text item's bullet.Textc(double x, double y)Set the center point of this text item's bounding box.Textc(Point thePoint)Set the center point of this text item's bounding box.static Text.AlignmentdefaultAlign()Returns the default text alignment.static voiddefaultAlign(Text.Alignment theAlignment)Set the default text alignment.static BulletdefaultBullet()Returns the default bullet.static voiddefaultBullet(Bullet theBullet)Set the default bullet.static FilldefaultFill()Returns the default fill paint.static voiddefaultFill(Fill theFill)Set the default fill paint.static java.awt.FontdefaultFont()Returns the default font.static voiddefaultFont(java.awt.Font theFont)Set the default font.static doubledefaultSpacing()Returns the default line spacing factor.static voiddefaultSpacing(double theSpacing)Set the default line spacing factor.voiddraw(java.awt.Graphics2D g2d)Draw this text item in the given graphics context.Texte(double x, double y)Set the east middle point of this text item's bounding box.Texte(Point thePoint)Set the east middle point of this text item's bounding box.Fillfill()Returns this text item's fill paint.Textfill(Fill theFill)Set this text item's fill paint.java.awt.Fontfont()Returns this text item's font.Textfont(java.awt.Font theFont)Set this text item's font.doubleheight()Returns the height of this text item's bounding box.Textn(double x, double y)Set the north middle point of this text item's bounding box.Textn(Point thePoint)Set the north middle point of this text item's bounding box.Textne(double x, double y)Set the northeast corner point of this text item's bounding box.Textne(Point thePoint)Set the northeast corner point of this text item's bounding box.Pointnw()Returns the northwest corner point of this text item's bounding box.Textnw(double x, double y)Set the northwest corner point of this text item's bounding box.Textnw(Point thePoint)Set the northwest corner point of this text item's bounding box.voidreadExternal(java.io.ObjectInput in)Read this text item from the given object input stream.Texts(double x, double y)Set the south middle point of this text item's bounding box.Texts(Point thePoint)Set the south middle point of this text item's bounding box.Textse(double x, double y)Set the southeast corner point of this text item's bounding box.Textse(Point thePoint)Set the southeast corner point of this text item's bounding box.doublespacing()Returns this text item's line spacing factor.Textspacing(double theSpacing)Set this text item's line spacing factor.Textsw(double x, double y)Set the southwest corner point of this text item's bounding box.Textsw(Point thePoint)Set the southwest corner point of this text item's bounding box.java.lang.Stringtext()Returns this text item's text.Texttext(java.lang.String theText)Set this text item's text.Textw(double x, double y)Set the west middle point of this text item's bounding box.Textw(Point thePoint)Set the west middle point of this text item's bounding box.doublewidth()Returns the width of this text item's bounding box.voidwriteExternal(java.io.ObjectOutput out)Write this text item to the given object output stream.
-
-
-
Field Detail
-
NORMAL_FONT
public static final java.awt.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:
java.lang.NullPointerException- (unchecked exception) Thrown if theItem is null.
-
-
Method Detail
-
defaultFont
public static java.awt.Font defaultFont()
Returns the default font.- Returns:
- Default font.
-
defaultFont
public static void defaultFont(java.awt.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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 java.lang.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(java.lang.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 java.awt.Font font()
Returns this text item's font.- Returns:
- Font.
-
font
public Text font(java.awt.Font theFont)
Set this text item's font.- Parameters:
theFont- Font.- Returns:
- This text item.
- Throws:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
widthin classDrawingItem- Returns:
- Width.
-
height
public double height()
Returns the height of this text item's bounding box.- Specified by:
heightin classDrawingItem- Returns:
- Height.
-
nw
public Point nw()
Returns the northwest corner point of this text item's bounding box.- Specified by:
nwin classDrawingItem- 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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.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:
addin classDrawingItem- Returns:
- This text item.
- Throws:
java.lang.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:
addin classDrawingItem- Parameters:
theDrawing- Drawing.- Returns:
- This text item.
- Throws:
java.lang.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:
addFirstin classDrawingItem- Returns:
- This text item.
- Throws:
java.lang.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:
addFirstin classDrawingItem- Parameters:
theDrawing- Drawing.- Returns:
- This text item.
- Throws:
java.lang.NullPointerException- (unchecked exception) Thrown if theDrawing is null.
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionWrite this text item to the given object output stream.- Specified by:
writeExternalin interfacejava.io.Externalizable- Overrides:
writeExternalin classDrawingItem- Parameters:
out- Object output stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionRead this text item from the given object input stream.- Specified by:
readExternalin interfacejava.io.Externalizable- Overrides:
readExternalin classDrawingItem- Parameters:
in- Object input stream.- Throws:
java.io.IOException- Thrown if an I/O error occurred.java.lang.ClassNotFoundException- Thrown if any class needed to deserialize this text item cannot be found.
-
draw
public void draw(java.awt.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:
drawin classDrawingItem- Parameters:
g2d- 2-D graphics context.
-
-
DMelt 3.0 © DataMelt by jWork.ORG