|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.northwestern.at.wordhoard.model.text.TextLine
public class TextLine
A line of text.
A line is a list of style runs (TextRun
objects)
plus line attributes: the line justification (left, center, or right),
indentation, numeric and string versions of the line number (if any), an optional
stanza label if this is the first line of a stanza, and marginalia
(if any).
Centering and right justification override indentation - the indentation attribute is used only with left justification.
Marginalia are short pieces of text that are rendered in the margin.
They are of type Text
,
so they may contain multiple lines and multiple runs.
They should not contain line numbers or nested marginalia (if they do,
they are not rendered).
Lines must be finalized by calling the finalize
method before they can be serialized or used. Some methods are
intended for use during construction, and can only be called before
finalization. Other methods are intended for use only after finalization.
Lines have a "marked" attribute that is set and used by the client. Marked lines are drawn with a marker character in the left margin.
Field Summary | |
---|---|
static byte |
CENTER
Center justification. |
static byte |
LEFT
Left justification. |
static byte |
RIGHT
Right justification. |
Constructor Summary | |
---|---|
TextLine()
Create a new plain line. |
|
TextLine(byte justification,
int indentation)
Creates a new line. |
|
TextLine(byte justification,
int indentation,
int number,
java.lang.String label)
Creates a new line. |
|
TextLine(byte justification,
int indentation,
int number,
java.lang.String label,
java.lang.String stanzaLabel)
Creates a new line. |
|
TextLine(int indentation)
Creates a new indented line. |
|
TextLine(java.lang.String text,
byte charset,
byte size,
boolean bold,
boolean italic,
byte justification,
int indentation,
int number,
java.lang.String label)
Creates a new line with a single run. |
|
TextLine(java.lang.String text,
byte charset,
byte size,
boolean bold,
boolean italic,
byte justification,
int indentation,
int number,
java.lang.String label,
java.lang.String stanzaLabel)
Creates a new line with a single run. |
|
TextLine(java.lang.String str,
FontInfo fontInfo)
Creates a new line with font information. |
Method Summary | |
---|---|
void |
addIndentation(int extra)
Adds extra indentation to the line. |
void |
appendRun(java.lang.String text,
byte charset,
byte size,
boolean bold,
boolean italic)
Appends a run to a line. |
void |
appendRun(java.lang.String text,
FontInfo fontInfo)
Appends a run with font information to a line. |
void |
appendRun(TextRun run)
Appends a run to a line. |
java.lang.Object |
clone()
Clones the line. |
void |
computeVerticalPositioningInformation()
Computes the line vertical positioning information. |
void |
computeWidth()
Computes the line width. |
(package private) void |
draw(DrawingContext context,
int x,
int y,
int selStartOffsetInLine,
int selEndOffsetInLine)
Draws the line. |
void |
finalize()
Finalizes the line. |
int |
getAscent()
Gets the ascent of the line in pixels. |
int |
getDescent()
Gets the descent of the line in pixels. |
int |
getHeight()
Gets the height of the line in pixels. |
int |
getIndentation()
Gets the indentation. |
byte |
getJustification()
Returns the line justification. |
java.lang.String |
getLabel()
Gets the line number label. |
int |
getLeading()
Gets the leading of the line in pixels. |
int |
getLength()
Gets the length of the line in characters. |
Text |
getMarginalia()
Gets the marginalia. |
int |
getNumber()
Gets the integer line number. |
TextRun[] |
getRuns()
Gets the style runs. |
java.lang.String |
getStanzaLabel()
Gets the stanza label. |
java.lang.String |
getText()
Gets the text of the line. |
int |
getWidth()
Gets the width of the the line in pixels. |
boolean |
isEmpty()
Returns true if the line is empty. |
boolean |
isMarked()
Returns true if the line is marked. |
void |
readExternal(java.io.ObjectInput in)
Reads the line from an object input stream (deserializes the object). |
void |
setIndentation(int indentation)
Sets the indentation. |
void |
setJustification(byte justification)
Sets the line justification. |
void |
setMarginalia(Text marginalia)
Sets the marginalia. |
void |
setMarked(boolean marked)
Sets the marked attribute. |
void |
setWidth(int width)
Sets the width of the line in pixels. |
(package private) LocationAndCharset |
viewToModel(DrawingContext context,
int lineIndex,
int x)
Converts a point to a location and character set. |
void |
writeExternal(java.io.ObjectOutput out)
Writes the line to an object output stream (serializes the object). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte LEFT
public static final byte CENTER
public static final byte RIGHT
Constructor Detail |
---|
public TextLine(byte justification, int indentation, int number, java.lang.String label, java.lang.String stanzaLabel)
The new line initially contains no runs or marginalia.
justification
- Justification (LEFT, CENTER, or RIGHT).indentation
- Indentation in pixels.number
- Integer line number.label
- Line number label.stanzaLabel
- Stanza label. public TextLine(byte justification, int indentation, int number, java.lang.String label)
The new line initially contains no runs, marginalia, or stanza label.
justification
- Justification (LEFT, CENTER, or RIGHT).indentation
- Indentation in pixels.number
- Integer line number.label
- Line number label. public TextLine(byte justification, int indentation)
The new line initially contains no runs, line number or label, stanza label, or marginalia.
justification
- Justification (LEFT, CENTER, or RIGHT).indentation
- Indentation in pixels. public TextLine(int indentation)
The new line has no numbers, labels, or marginalia, and initially contains no runs.
indentation
- Indentation in pixels. public TextLine()
The new line has no numbers, labels, or marginalia, is left justified with no indentation, and initially contains no runs.
public TextLine(java.lang.String text, byte charset, byte size, boolean bold, boolean italic, byte justification, int indentation, int number, java.lang.String label, java.lang.String stanzaLabel)
The new line has no stanza label or marginalia.
text
- Text.charset
- Character set.size
- Font size.bold
- True if bold.italic
- True if italic.justification
- Justification (LEFT, CENTER, or RIGHT).indentation
- Indentation in pixels.number
- Integer line number.label
- Line number label.stanzaLabel
- Optional stanza label if first line of
stanza, else null. public TextLine(java.lang.String text, byte charset, byte size, boolean bold, boolean italic, byte justification, int indentation, int number, java.lang.String label)
The new line has no stanza label or marginalia.
text
- Text.charset
- Character set.size
- Font size.bold
- True if bold.italic
- True if italic.justification
- Justification (LEFT, CENTER, or RIGHT).indentation
- Indentation in pixels.number
- Integer line number.label
- Line number label. public TextLine(java.lang.String str, FontInfo fontInfo)
The line contains a single plain run in the Roman character set, is left justified with no indentation, and has no line number, labels, or marginalia.
The line is finalized, and width and vertical positioning information are computed for the line.
str
- String.fontInfo
- Font info. Method Detail |
---|
public Text getMarginalia()
public void setMarginalia(Text marginalia)
marginalia
- Marginalia. public void appendRun(TextRun run)
This method can only be used during construction, before the line is finalized. If it is called after finalization a null pointer exception is thrown.
run
- Text run. public void appendRun(java.lang.String text, byte charset, byte size, boolean bold, boolean italic)
This method can only be used during construction, before the line is finalized. If it is called after finalization a null pointer exception is thrown.
text
- Text.charset
- Character set.size
- Font size.bold
- True if bold.italic
- True if italic. public void appendRun(java.lang.String text, FontInfo fontInfo)
This method can only be used during construction, before the line is finalized. If it is called after finalization a null pointer exception is thrown.
text
- Text.fontInfo
- Font info. public void finalize()
This method must be called before the line can be serialized or used. If the line has already been finalized, this method does nothing.
finalize
in class java.lang.Object
public boolean isEmpty()
This method may be called before or after finalization.
public TextRun[] getRuns()
public byte getJustification()
public void setJustification(byte justification)
justification
- Line justification (LEFT, CENTER, or RIGHT). public int getIndentation()
public void setIndentation(int indentation)
indentation
- Indentation in pixels. public void addIndentation(int extra)
extra
- Extra indentation to add to line. public int getNumber()
public java.lang.String getLabel()
public java.lang.String getStanzaLabel()
public java.lang.String getText()
The line must be finalized, or a null pointer exception is thrown.
public int getLength()
The line must be finalized, or a null pointer exception is thrown.
public int getWidth()
public void setWidth(int width)
width
- The width of the line in pixels. public int getHeight()
public int getLeading()
public int getAscent()
public int getDescent()
public void computeWidth()
The line must be finalized, or a null pointer exception is thrown.
The font info must be set for all the runs in the line.
public void computeVerticalPositioningInformation()
The line must be finalized, or a null pointer exception is thrown.
The font info must be set for all the runs in the line. The leading, ascent, and descent of the line are computed as the maximum of the corresponding values for all the runs in the line. The height of the line is computed as the sum of the line's leading, ascent, and descent.
The leading, ascent, and descent are further adjusted to guarentee enough room for any underline, overline, superscript, and/or subscript runs in the line.
public boolean isMarked()
public void setMarked(boolean marked)
marked
- True if line is marked. public java.lang.Object clone()
The line must be finalized, or a null pointer exception is thrown.
The clone is a deep copy of the line.
clone
in class java.lang.Object
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
The line must be finalized, or a null pointer exception is thrown.
out
- Object output stream.
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
The deserialized line is finalized.
in
- Object input stream.
java.io.IOException
java.lang.ClassNotFoundException
void draw(DrawingContext context, int x, int y, int selStartOffsetInLine, int selEndOffsetInLine)
The line must be finalized, the font info must be set for all the runs in the line, and the line's width and vertical postioning information must be computed.
context
- Drawing context.x
- X coordinate of left edge of line.y
- Y coordinate of top of line.selStartOffsetInLine
- Selection start offset in line.selEndOffsetInLine
- Selection end offset in line. LocationAndCharset viewToModel(DrawingContext context, int lineIndex, int x)
context
- Drawing context.lineIndex
- Index of line.x
- X coordinate of point in line.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |