com.ibm.richtext.styledtext
Class MText

java.lang.Object
  |
  +--com.ibm.richtext.styledtext.MConstText
        |
        +--com.ibm.richtext.styledtext.MText
Direct Known Subclasses:
StyledText

public abstract class MText
extends MConstText

This class is a mutable extension of MConstText. It has methods for inserting, appending, replacing, and removing styled text. Additionally, it has methods for modifying paragraph and character styles.

Styled characters (from another MConstText instance) added to the text retain their original character styles. The style of plain characters (specified as a char or char[]) is always specified explicitly when they are added to the text. MText does not do character style "propagation", where unstyled characters take on the style of previous characters. Clients can implement this behavior by specifying the styles to propagate.

When unstyled characters are added to the text, their paragraph style is the paragraph style in effect immediately after the last new character. If the characters contain paragraph separators, then every new paragraph will have the same paragraph style. When styled characters are added to the text, their resulting paragraph style is determined by the following rule:

The paragraph styles in the new text become the paragraph styles in the target text, with the exception of the last paragraph in the new text, which takes on the paragraph style in effect immediately after the inserted text. If the new text is added at the end of the target text, the new text's paragraph styles take effect in any paragraph affected by the addition.
For example, suppose there is a single paragraph of text with style 'A', delimited with a paragraph separator 'P':
AAAAAAP
Suppose the following styled paragraphs are inserted into the above text after the fourth character:
BBBBPCCCPDDD
Then the original paragraph style of each character is:
AAAABBBBPCCCPDDDAAP
The resulting paragraph styles are:
BBBBBBBBPCCCPAAAAAP
Similarly, if characters are deleted, the paragraph style immediately after the deletion takes effect on the paragraph containing the deletion. So, if characters 4-16 were deleted in the example above, the paragraph styles would be:
AAAAAAP
This paragraph-style propagation policy is sometimes referred to as following styles win, since styles at the end of the paragraph become the style for the entire paragraph.

This class can accumulate a damaged range - an interval in which characters, character styles, or paragraph styles have changed. This is useful for clients such as text editors which reformat and draw text after changes. Usually the damaged range is exactly the range of characters operated upon; however, larger ranges may be damaged if paragraph styles change.

See Also:
StyleModifier

Fields inherited from class com.ibm.richtext.styledtext.MConstText
styledTextFlavor
 
Constructor Summary
protected MText()
           
 
Method Summary
abstract  void append(MConstText srcText)
          Append the contents of srcText (both characters and styles) to the end of this MText.
abstract  void compress()
          Minimize the amount of memory used by the MText object.
abstract  MText extractWritable(int start, int limit)
          Create an MText containing the characters and styles in the range [start, limit).
abstract  void insert(int pos, MConstText srcText)
          Insert the contents of srcText (both characters and styles) into this MText at the position specified by pos.
abstract  void modifyCharacterStyles(int start, int limit, StyleModifier modifier)
          Invoke the given modifier on all character styles from start to limit.
abstract  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).
abstract  void remove()
          Delete all characters and styles.
abstract  void remove(int start, int limit)
          Delete the specified range of characters (and styles).
abstract  void removeCharacterStyles()
          Set the character style of all characters in the MText object to AttributeMap.EMPTY_ATTRIBUTE_MAP.
abstract  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).
abstract  void replace(int start, int limit, char srcChar, AttributeMap charStyle)
          Replace the characters in the range [start, limit) with the character srcChar.
abstract  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.
abstract  void replace(int start, int limit, MConstText srcText, 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).
abstract  void replaceAll(MConstText srcText)
          Replace the entire contents of this MText (both characters and styles) with the contents of srcText.
abstract  void resetDamagedRange()
          Reset the damaged range to an empty interval, and begin accumulating the damaged range.
 
Methods inherited from class com.ibm.richtext.styledtext.MConstText
at, characterStyleAt, characterStyleLimit, characterStyleStart, createCharacterIterator, createCharacterIterator, damagedRangeLimit, damagedRangeStart, equals, equals, extract, extractChars, getTimeStamp, hashCode, length, paragraphLimit, paragraphStart, paragraphStyleAt
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MText

protected MText()
Method Detail

replace

public abstract void replace(int start,
                             int limit,
                             MConstText srcText,
                             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.
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 abstract 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.
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 abstract 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.
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 abstract 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
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 abstract void replaceAll(MConstText srcText)
Replace the entire contents of this MText (both characters and styles) with the contents of srcText.
Parameters:
srcText - the source for the new characters and styles

insert

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

append

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

remove

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

remove

public abstract void remove()
Delete all characters and styles.

extractWritable

public abstract MText extractWritable(int start,
                                      int limit)
Create an MText containing the characters and styles in the range [start, limit).
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

compress

public abstract void compress()
Minimize the amount of memory used by the MText object.

removeCharacterStyles

public abstract void removeCharacterStyles()
Set the character style of all characters in the MText object to AttributeMap.EMPTY_ATTRIBUTE_MAP.

modifyCharacterStyles

public abstract void modifyCharacterStyles(int start,
                                           int limit,
                                           StyleModifier modifier)
Invoke the given modifier on all character styles from start to limit.
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 abstract 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).
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 abstract 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.
See Also:
MConstText.damagedRangeStart(), MConstText.damagedRangeLimit()


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