com.ibm.richtext.styledtext
Class StyledText

java.lang.Object
  |
  +--com.ibm.richtext.styledtext.MConstText
        |
        +--com.ibm.richtext.styledtext.MText
              |
              +--com.ibm.richtext.styledtext.StyledText
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable

public final class StyledText
extends MText
implements java.io.Externalizable

This class is an implementation of MText, a modifyable, styled text storage model. Additionally, it supports persistance through the Externalizable interface.

See Also:
MText, Serialized Form

Fields inherited from class com.ibm.richtext.styledtext.MConstText
styledTextFlavor
 
Constructor Summary
StyledText()
          Create an empty text object.
StyledText(int capacity)
          Create an empty text object ready to hold at least capacity chars.
StyledText(MConstText source)
          Create a text object from the given source.
StyledText(MConstText source, int srcStart, int srcLimit)
          Create a text object from a subrange of the given source.
StyledText(java.lang.String string, AttributeMap initialStyle)
          Create a text object with the characters in the string, in the given style.
 
Method Summary
 void append(MConstText srcText)
          Append the contents of srcText (both characters and styles) to the end of this MText.
 char at(int pos)
          Return the character at offset pos.
 AttributeMap characterStyleAt(int pos)
          Return the style applied to the character at offset pos.
 int characterStyleLimit(int pos)
          Return the index after the last character in the character style run containing pos.
 int characterStyleStart(int pos)
          Return the index of the first character in the character style run containing pos.
 void compress()
          Minimize the amount of memory used by the MText object.
 java.text.CharacterIterator createCharacterIterator(int start, int limit)
          Create a CharacterIterator over the range [start, limit).
 int damagedRangeLimit()
          Return the limit of the damaged range.
 int damagedRangeStart()
          Return the start of the damaged range.
 MConstText extract(int start, int limit)
          Create an MConstText containing the characters and styles in the range [start, limit).
 void extractChars(int start, int limit, char[] dst, int dstStart)
          Copy the characters in the range [start, limit) into the array dst, beginning at dstStart.
 MText extractWritable(int start, int limit)
          Create an MText containing the characters and styles in the range [start, limit).
 int getTimeStamp()
          Return the current time stamp.
 void insert(int pos, MConstText srcText)
          Insert the contents of srcText (both characters and styles) into this MText at the position specified by pos.
 int length()
          Return the length of the MConstText object.
 void modifyCharacterStyles(int start, int limit, StyleModifier modifier)
          Invoke the given modifier on all character styles from start to limit.
 void modifyParagraphStyles(int start, int limit, StyleModifier modifier)
          Invoke the given modifier on all paragraph styles in paragraphs containing characters in the range [start, limit).
 int paragraphLimit(int pos)
          Return the limit of the paragraph containing the character at offset pos.
 int paragraphStart(int pos)
          Return the start of the paragraph containing the character at offset pos.
 AttributeMap paragraphStyleAt(int pos)
          Return the paragraph style applied to the paragraph containing offset pos.
 void readExternal(java.io.ObjectInput in)
           
 void remove()
          Delete all characters and styles.
 void remove(int start, int limit)
          Delete the specified range of characters (and styles).
 void removeCharacterStyles()
          Set the style of all characters in the MText object to AttributeMap.EMPTY_ATTRIBUTE_MAP.
 void replace(int start, int limit, char[] srcChars, int srcStart, int srcLimit, AttributeMap charsStyle)
          Replace the characters in the range [start, limit) with the characters in srcChars in the range [srcStart, srcLimit).
 void replace(int start, int limit, char srcChar, AttributeMap charStyle)
          Replace the characters in the range [start, limit) with the character srcChar.
 void replace(int start, int limit, MConstText text)
          Replace the characters and styles in the range [start, limit) with the characters and styles in srcText.
 void replace(int start, int limit, MConstText text, int srcStart, int srcLimit)
          Replace the characters and styles in the range [start, limit) with the characters and styles in srcText in the range [srcStart, srcLimit).
 void replaceAll(MConstText srcText)
          Replace the entire contents of this MText (both characters and styles) with the contents of srcText.
 void resetDamagedRange()
          Reset the damaged range to an empty interval, and begin accumulating the damaged range.
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class com.ibm.richtext.styledtext.MConstText
createCharacterIterator, equals, equals, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StyledText

public StyledText()
Create an empty text object.

StyledText

public StyledText(int capacity)
Create an empty text object ready to hold at least capacity chars.
Parameters:
capacity - the minimum capacity of the internal text buffer

StyledText

public StyledText(java.lang.String string,
                  AttributeMap initialStyle)
Create a text object with the characters in the string, in the given style.
Parameters:
string - the initial contents
initialStyle - the style of the initial text

StyledText

public StyledText(MConstText source)
Create a text object from the given source.
Parameters:
source - the text to copy

StyledText

public StyledText(MConstText source,
                  int srcStart,
                  int srcLimit)
Create a text object from a subrange of the given source.
Parameters:
source - the text to copy from
srcStart - the index of the first character to copy
srcLimit - the index after the last character to copy
Method Detail

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable

at

public char at(int pos)
Return the character at offset pos.
Overrides:
at in class MConstText
Parameters:
pos - a valid offset into the text

extractChars

public void extractChars(int start,
                         int limit,
                         char[] dst,
                         int dstStart)
Copy the characters in the range [start, limit) into the array dst, beginning at dstStart.
Overrides:
extractChars in class MConstText
Parameters:
start - offset of first character which will be copied into the array
limit - offset immediately after the last character which will be copied into the array
dst - array in which to copy characters. The length of dst must be at least (dstStart + limit - start).

extract

public MConstText extract(int start,
                          int limit)
Create an MConstText containing the characters and styles in the range [start, limit).
Overrides:
extract in class MConstText
Parameters:
start - offset of first character in the new text
limit - offset immediately after the last character in the new text
Returns:
an MConstText object containing the characters and styles in the given range

extractWritable

public MText extractWritable(int start,
                             int limit)
Create an MText containing the characters and styles in the range [start, limit).
Overrides:
extractWritable in class MText
Parameters:
start - offset of first character in the new text
limit - offset immediately after the last character in the new text
Returns:
an MConstText object containing the characters and styles in the given range

length

public int length()
Return the length of the MConstText object. The length is the number of characters in the text.
Overrides:
length in class MConstText
Returns:
the length of the MConstText object

createCharacterIterator

public java.text.CharacterIterator createCharacterIterator(int start,
                                                           int limit)
Create a CharacterIterator over the range [start, limit).
Overrides:
createCharacterIterator in class MConstText
Parameters:
start - the beginning of the iterator's range
limit - the limit of the iterator's range
See Also:
CharacterIterator

characterStyleStart

public int characterStyleStart(int pos)
Return the index of the first character in the character style run containing pos. All characters in a style run have the same character style.
Overrides:
characterStyleStart in class MConstText

characterStyleLimit

public int characterStyleLimit(int pos)
Return the index after the last character in the character style run containing pos. All characters in a style run have the same character style.
Overrides:
characterStyleLimit in class MConstText

characterStyleAt

public AttributeMap characterStyleAt(int pos)
Return the style applied to the character at offset pos.
Overrides:
characterStyleAt in class MConstText
Parameters:
pos - a valid offset into the text

paragraphStart

public int paragraphStart(int pos)
Return the start of the paragraph containing the character at offset pos.
Overrides:
paragraphStart in class MConstText
Parameters:
pos - a valid offset into the text

paragraphLimit

public int paragraphLimit(int pos)
Return the limit of the paragraph containing the character at offset pos.
Overrides:
paragraphLimit in class MConstText
Parameters:
pos - a valid offset into the text

paragraphStyleAt

public AttributeMap paragraphStyleAt(int pos)
Return the paragraph style applied to the paragraph containing offset pos.
Overrides:
paragraphStyleAt in class MConstText
Parameters:
pos - a valid offset into the text

getTimeStamp

public int getTimeStamp()
Return the current time stamp. The time stamp is incremented whenever the contents of the MConstText changes.
Overrides:
getTimeStamp in class MConstText
Returns:
the current paragraph style time stamp

replace

public void replace(int start,
                    int limit,
                    MConstText text,
                    int srcStart,
                    int srcLimit)
Replace the characters and styles in the range [start, limit) with the characters and styles in srcText in the range [srcStart, srcLimit). srcText is not modified.
Overrides:
replace in class MText
Parameters:
start - the offset at which the replace operation begins
limit - the offset at which the replace operation ends. The character and style at limit is not modified.
srcText - the source for the new characters and styles
srcStart - the offset into srcText where new characters and styles will be obtained
srcLimit - the offset into srcText where the new characters and styles end

replace

public void replace(int start,
                    int limit,
                    MConstText text)
Replace the characters and styles in the range [start, limit) with the characters and styles in srcText. srcText is not modified.
Overrides:
replace in class MText
Parameters:
start - the offset at which the replace operation begins
limit - the offset at which the replace operation ends. The character and style at limit is not modified.
srcText - the source for the new characters and styles

replace

public void replace(int start,
                    int limit,
                    char[] srcChars,
                    int srcStart,
                    int srcLimit,
                    AttributeMap charsStyle)
Replace the characters in the range [start, limit) with the characters in srcChars in the range [srcStart, srcLimit). New characters take on the style charsStyle. srcChars is not modified.
Overrides:
replace in class MText
Parameters:
start - the offset at which the replace operation begins
limit - the offset at which the replace operation ends. The character at limit is not modified.
srcChars - the source for the new characters
srcStart - the offset into srcChars where new characters will be obtained
srcLimit - the offset into srcChars where the new characters end
charsStyle - the style of the new characters

replace

public void replace(int start,
                    int limit,
                    char srcChar,
                    AttributeMap charStyle)
Replace the characters in the range [start, limit) with the character srcChar. The new character takes on the style charStyle
Overrides:
replace in class MText
Parameters:
start - the offset at which the replace operation begins
limit - the offset at which the replace operation ends. The character at limit is not modified.
srcChar - the new character
charsStyle - the style of the new character

replaceAll

public void replaceAll(MConstText srcText)
Replace the entire contents of this MText (both characters and styles) with the contents of srcText.
Overrides:
replaceAll in class MText
Parameters:
srcText - the source for the new characters and styles

insert

public void insert(int pos,
                   MConstText srcText)
Insert the contents of srcText (both characters and styles) into this MText at the position specified by pos.
Overrides:
insert in class MText
Parameters:
pos - The character offset where the new text is to be inserted.
srcText - The text to insert.

append

public void append(MConstText srcText)
Append the contents of srcText (both characters and styles) to the end of this MText.
Overrides:
append in class MText
Parameters:
srcText - The text to append.

remove

public void remove(int start,
                   int limit)
Delete the specified range of characters (and styles).
Overrides:
remove in class MText
Parameters:
start - Offset of the first character to delete.
limit - Offset of the first character after the range to delete.

remove

public void remove()
Delete all characters and styles. Always increments time stamp.
Overrides:
remove in class MText

compress

public void compress()
Minimize the amount of memory used by the MText object.
Overrides:
compress in class MText

removeCharacterStyles

public void removeCharacterStyles()
Set the style of all characters in the MText object to AttributeMap.EMPTY_ATTRIBUTE_MAP.
Overrides:
removeCharacterStyles in class MText

modifyCharacterStyles

public void modifyCharacterStyles(int start,
                                  int limit,
                                  StyleModifier modifier)
Invoke the given modifier on all character styles from start to limit.
Overrides:
modifyCharacterStyles in class MText
Parameters:
modifier - the modifier to apply to the range.
start - the start of the range of text to modify.
limit - the limit of the range of text to modify.

modifyParagraphStyles

public void modifyParagraphStyles(int start,
                                  int limit,
                                  StyleModifier modifier)
Invoke the given modifier on all paragraph styles in paragraphs containing characters in the range [start, limit).
Overrides:
modifyParagraphStyles in class MText
Parameters:
modifier - the modifier to apply to the range.
start - the start of the range of text to modify.
limit - the limit of the range of text to modify.

resetDamagedRange

public void resetDamagedRange()
Reset the damaged range to an empty interval, and begin accumulating the damaged range. The damaged range includes every index where a character, character style, or paragraph style has changed.
Overrides:
resetDamagedRange in class MText
See Also:
damagedRangeStart(), damagedRangeLimit()

damagedRangeStart

public int damagedRangeStart()
Return the start of the damaged range. If the start is Integer.MAX_VALUE and the limit is Integer.MIN_VALUE, then the damaged range is empty.
Overrides:
damagedRangeStart in class MConstText
Returns:
the start of the damaged range
See Also:
damagedRangeLimit(), resetDamagedRange()

damagedRangeLimit

public int damagedRangeLimit()
Return the limit of the damaged range. If the start is Integer.MAX_VALUE and the limit is Integer.MIN_VALUE, then the damaged range is empty.
Overrides:
damagedRangeLimit in class MConstText
Returns:
the limit of the damaged range
See Also:
damagedRangeStart(), resetDamagedRange()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright (c) 1998-2000 IBM Corporation and others.