edu.northwestern.at.wordhoard.model.text
Class WrappedText

java.lang.Object
  extended by edu.northwestern.at.wordhoard.model.text.Text
      extended by edu.northwestern.at.wordhoard.model.text.WrappedText
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable

public class WrappedText
extends Text

Wrapped text.

In the persistent object model, lines are not word-wrapped to the right margin. While most lines are short and fit within the margin without wrapping, this is not always the case. Examples of long lines include title page publication statements, many of the stage directions in Shakespeare, and lines in Chaucer's "Melibee" Canterbury Tale.

This class performs word wrapping to break long lines into separate lines for presentation. It also provides methods for converting text locations and ranges between wrapped coordinates (view coordinates) and unwrapped coordinates (model coordinates).

Marginalia, if any, are also word wrapped.

Word wrapping is done in the client, not in the build programs. On different operating systems using different fonts, line breaks may occur at different locations in wrapped lines.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class edu.northwestern.at.wordhoard.model.text.Text
serialVersionUID
 
Constructor Summary
WrappedText(Text unwrappedText, int rightMargin)
          Creates new wrapped text without marginalia.
WrappedText(Text unwrappedText, int rightMargin, int marginaliaWidth)
          Creates new wrapped text.
 
Method Summary
 TextLocation baseToDerived(TextLocation loc)
          Converts a location from base to derived coordinates.
 TextLocation derivedToBase(TextLocation loc)
          Converts a location from derived to base coordinates.
 
Methods inherited from class edu.northwestern.at.wordhoard.model.text.Text
appendBlankLine, appendLine, appendLine, baseToDerived, clone, computeLineWidths, computeVerticalPositioningInformation, copyLine, copyLine, derivedToBase, draw, finalize, getLine, getLineLocation, getLineLocation, getLines, getNumLines, getText, getWordLocation, hasLineNumbers, hasMarginalia, initializeForDrawing, isMarked, readExternal, roundLocation, setCollapseBlankLines, setExtraIndentation, setLineNumberInterval, setMarkers, setSelection, viewToModel, writeExternal
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WrappedText

public WrappedText(Text unwrappedText,
                   int rightMargin,
                   int marginaliaWidth)
            throws java.lang.Exception
Creates new wrapped text.

On entry, the font information must be set for all the runs in the unwrapped text, and the widths must be set for all the runs and lines in the unwrapped text. See FontManager.initText.

On exit, the font information, width information, and vertical positioning information are set for all the runs and lines in the wrapped text.

Parameters:
unwrappedText - Unwrapped text.
rightMargin - Right margin in pixels.
marginaliaWidth - Width in pixels of marginalia, or 0 if text does not have marginalia.
Throws:
java.lang.Exception - Word longer than right margin.

WrappedText

public WrappedText(Text unwrappedText,
                   int rightMargin)
            throws java.lang.Exception
Creates new wrapped text without marginalia.

On entry, the font information must be set for all the runs in the unwrapped text, and the widths must be set for all the runs and lines in the unwrapped text. See FontManager.initText.

On exit, the font information, width information, and vertical positioning information are set for all the runs and lines in the wrapped text.

Parameters:
unwrappedText - Unwrapped text.
rightMargin - Right margin in pixels.
Throws:
java.lang.Exception - Word longer than right margin.
Method Detail

derivedToBase

public TextLocation derivedToBase(TextLocation loc)
Converts a location from derived to base coordinates.

See the package documentation for more details on derived and base coordinate systems.

Overrides:
derivedToBase in class Text
Parameters:
loc - Text location in derived coordinates.
Returns:
Text location in base coordinates.

baseToDerived

public TextLocation baseToDerived(TextLocation loc)
Converts a location from base to derived coordinates.

See the package documentation for more details on derived and base coordinate systems.

Overrides:
baseToDerived in class Text
Parameters:
loc - Text location in base cooordinates.
Returns:
Text location in derived coordinates.