|
|||||||||
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.Text
public class Text
Text.
Text consists of a list of lines (TextLine
objects),
plus attributes that specify whether or not the text includes
line numbers or marginalia.
Text objects for work parts are created and made persistent in the object model by the build tools. They are stored as serialized objects in a type "mediumblob" column in the MySQL database. They are fetched as needed from the database and deserialized by Hibernate.
Some properties are used only during construction of the object, some are used only during presentation in the client, and some are used by both. Only the properties used by both are serialized and persisted.
The text must be finalized by calling the finalize
method before it 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.
Field Summary | |
---|---|
(package private) static long |
serialVersionUID
Serial version UID. |
Constructor Summary | |
---|---|
Text()
Creates a new text object. |
|
Text(boolean lineNumbers,
boolean marginalia)
Creates a new text object. |
|
Text(java.lang.String str,
FontInfo fontInfo)
Creates a new text object with a single plain line and no line numbers or marginalia. |
|
Text(TextLine line)
Creates a new text object with a single line and no line numbers or marginalia. |
Method Summary | |
---|---|
void |
appendBlankLine()
Appends a blank line to the text. |
int |
appendLine(java.lang.String str,
byte charset,
int number,
java.lang.String label)
Appends a plain line to the text. |
void |
appendLine(TextLine line)
Appends a line to the text. |
TextLocation |
baseToDerived(TextLocation loc)
Converts a location from base to derived coordinates. |
TextRange |
baseToDerived(TextRange range)
Converts a model range to view text coordinates. |
java.lang.Object |
clone()
Clones the text. |
void |
computeLineWidths()
Computes line widths. |
void |
computeVerticalPositioningInformation()
Computes vertical positioning information. |
void |
copyLine(java.lang.String str,
FontInfo fontInfo)
Copies a line with font information. |
void |
copyLine(TextLine line)
Copies a line to the text. |
TextLocation |
derivedToBase(TextLocation loc)
Converts a location from derived to base coordinates. |
TextRange |
derivedToBase(TextRange range)
Converts a range from derived to base coordinates. |
void |
draw(java.awt.Graphics2D g,
int x,
int y)
Draws the text. |
void |
finalize()
Finalizes the text. |
TextLine |
getLine(int lineIndex)
Gets a spcific line. |
int |
getLineLocation(int lineIndex)
Gets the location of a line. |
TextRange |
getLineLocation(TextLocation loc)
Gets the location of a line. |
TextLine[] |
getLines()
Gets the lines. |
int |
getNumLines()
Gets the number of lines. |
java.lang.String |
getText(TextRange range)
Gets a range of text. |
TextRange |
getWordLocation(TextLocation loc,
byte charset)
Gets the location of a word. |
boolean |
hasLineNumbers()
Returns true if the text has line numbers. |
boolean |
hasMarginalia()
Returns true if the text has marginalia. |
int |
initializeForDrawing(DrawingContext context)
Initializes the text for drawing. |
boolean |
isMarked(int lineIndex)
Returns true if a line is marked. |
void |
readExternal(java.io.ObjectInput in)
Reads the text from an object input stream (deserializes the object). |
TextLocation |
roundLocation(TextLocation loc)
Rounds a location to the nearest character of text. |
void |
setCollapseBlankLines(boolean collapseBlankLines)
Sets the collapse blank lines option. |
void |
setExtraIndentation(int extraIndentation)
Sets extra indentation. |
void |
setLineNumberInterval(int lineNumberInterval)
Sets the line number interval. |
void |
setMarkers(TextLocation[] locations)
Sets markers. |
void |
setSelection(TextRange selection)
Sets the selection. |
LocationAndCharset |
viewToModel(java.awt.Point p)
Converts a point to a location and character set. |
void |
writeExternal(java.io.ObjectOutput out)
Writes the text 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 |
---|
static final long serialVersionUID
Constructor Detail |
---|
public Text(boolean lineNumbers, boolean marginalia)
The new text object initially contains no lines.
lineNumbers
- True if this text has line numbers.marginalia
- True if this text has marginalia. public Text()
The new text object has no line numbers or marginalia and initially contains no lines.
public Text(TextLine line)
The width and vertical positioning information are computed for the line, and the text is finalized and ready to be used.
line
- Line. public Text(java.lang.String str, FontInfo fontInfo)
The width and vertical positioning information are computed for the line, and the text is finalized and ready to be used.
str
- Text.fontInfo
- Font info. Method Detail |
---|
public void appendLine(TextLine line)
This method can only be used during construction, before the text is finalized. If it is called after finalization a null pointer exception is thrown.
line
- The line. public int appendLine(java.lang.String str, byte charset, int number, java.lang.String label)
This method can only be used during construction, before the text is finalized. If it is called after finalization a null pointer exception is thrown.
str
- The text of the line.charset
- Character set.number
- Integer line number.label
- Line number label.
public void appendBlankLine()
This method can only be used during construction, before the text is finalized. If it is called after finalization a null pointer exception is thrown.
public void copyLine(TextLine line)
This method can only be used during construction, before the text is finalized. If it is called after finalization a null pointer exception is thrown.
The line is appended to the text unconditionally and without alteration. There is no check for collapsing blank lines, and no extra indentation is added.
line
- The line. public void copyLine(java.lang.String str, FontInfo fontInfo)
This method can only be used during construction, before the text is finalized. If it is called after finalization a null pointer exception is thrown.
The line is appended to the text unconditionally and without alteration. There is no check for collapsing blank lines, and no extra indentation is added.
The line is finalized, and width and vertical positioning information are computed for the line.
str
- String.fontInfo
- Font info. public int getNumLines()
This method can be used before or after finalization.
public void setCollapseBlankLines(boolean collapseBlankLines)
collapseBlankLines
- If true, multiple sequental blank lines
are collapsed to a single blank line.
This is the default. public void setExtraIndentation(int extraIndentation)
extraIndentation
- Extra indentation for all subsequent
lines. public void finalize()
Trims trailing blank lines and finalizes the text object and all of its lines. This method must be called before the text object can be serialized or used. If the text has already been finalized, this method does nothing.
finalize
in class java.lang.Object
public TextLine[] getLines()
public TextLine getLine(int lineIndex)
public boolean hasLineNumbers()
public boolean hasMarginalia()
public TextLocation roundLocation(TextLocation loc)
The text must be finalized, or a null pointer exception is thrown.
loc
- Location.
public TextRange getWordLocation(TextLocation loc, byte charset)
The text must be finalized, or a null pointer exception is thrown.
loc
- A location in the text.charset
- Character set.
public TextRange getLineLocation(TextLocation loc)
The text must be finalized, or a null pointer exception is thrown.
loc
- A location in the text.
public java.lang.String getText(TextRange range)
The text must be finalized, or a null pointer exception is thrown.
range
- Range.
public void computeLineWidths()
The text 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 text must be finalized, or a null pointer exception is thrown.
The font info must be set for all the runs in the line.
public TextLocation derivedToBase(TextLocation loc)
Subclasses which present derived views of model text (e.g., paragraph wapped views or views with translations) must override this method to convert a location in the derived coordinate system to the corresponding location in the base coordinate system.
This base class implementation does no translation. The location is returned unchanged.
See the package documentation for more details on derived and base coordinate systems.
loc
- Text location in derived coordinates.
public TextRange derivedToBase(TextRange range)
range
- Text range in derived coordinates.
public TextLocation baseToDerived(TextLocation loc)
Subclasses which present derived views of model text (e.g., paragraph wapped views or views with translations) must override this method to convert a location in the base coordinate system to the corresponding location in the derived coordinate system.
This base class implementation does no translation. The location is returned unchanged.
See the package documentation for more details on derived and base coordinate systems.
loc
- Text location in base cooordinates.
public TextRange baseToDerived(TextRange range)
range
- Text range in model text cooordinates.
public java.lang.Object clone()
The text must be finalized, or a null pointer exception is thrown.
The clone is a deep copy of the text.
clone
in class java.lang.Object
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
The text must be finalized, or a null pointer exception is thrown.
writeExternal
in interface java.io.Externalizable
out
- Object output stream.
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
in
- Object input stream.
java.io.IOException
java.lang.ClassNotFoundException
public int initializeForDrawing(DrawingContext context)
The text must be finalized, the font info must be set for all the runs in the line, and each line's width and vertical positioning information must be computed.
context
- Drawing context.
public void draw(java.awt.Graphics2D g, int x, int y)
The text must be initialized for drawing.
Drawing is done relative to the top and left pixel coordinates of the text in the graphics context. The top coordinate is the y coordinate of the top of the first line. The left coordinate is the x coordinate of the left edge of the text, not counting markers in the left margin. If the text contains markers, they are drawn to the left of the x coordinate, using an offset supplied by the drawing context.
g
- Graphics context.x
- X coordinate of left edge of text.y
- Y coordinate of top of text. public void setLineNumberInterval(int lineNumberInterval)
The line number interval controls the display of line numbers. 0 = no line numbers, 1 = every line numbered, n = every n'th line numbered, -1 = stanza numbers.
lineNumberInterval
- Line number interval. public void setSelection(TextRange selection)
selection
- The selection range, or null if none. public LocationAndCharset viewToModel(java.awt.Point p)
p
- Point.
public int getLineLocation(int lineIndex)
lineIndex
- Line index.
public void setMarkers(TextLocation[] locations)
locations
- Marker locations in base coordinates, or
null to clear all markers. public boolean isMarked(int lineIndex)
lineIndex
- Line index.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |