com.ibm.richtext.styledtext
Class MConstText

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

public abstract class MConstText
extends java.lang.Object

MConstText is a base class for text with multiple character and paragraph styles. The text is a sequence of Unicode characters, represented by char. Character and paragraph styles are represented by the AttributeMap class.

Characters in the text are accessed with an integer index using the at method. Valid indices are between 0 and (length-1), where length is the number of characters in the text. Additionally, the characters in the text may be accessed through a java.text.CharacterIterator.

Every character in the text has a character style associated with it, represented by the AttributeMap class. The character style for a particular character can be obtained using the characterStyleAt method.

Each character in the text is contained in a paragraph. A paragraph is a range of text including and terminated by a paragraph separator (either \n or U+2029). Every paragraph has a paragraph style associated with it, represented by the AttributeMap class. Paragraph boundaries and styles can be obtained from the MConstText.

This class does not have methods for modifying the text or styles. However, subclasses may add this capability, so it is not safe to assume that an MConstText instance is immutable. In particular, the MText class adds modification protocol to this class. Clients can detect whether an MConstText has changed by keeping track of its timestamp.

A DataFlavor for clipboard content is defined in this class. Using this DataFlavor insures that all clients will recognize MConstText content on the clipboard.

See Also:
MText, AttributeMap, CharacterIterator, DataFlavor

Field Summary
static java.awt.datatransfer.DataFlavor styledTextFlavor
          The DataFlavor for MConstText clipboard content.
 
Constructor Summary
protected MConstText()
           
 
Method Summary
abstract  char at(int pos)
          Return the character at offset pos.
abstract  AttributeMap characterStyleAt(int pos)
          Return the style applied to the character at offset pos.
abstract  int characterStyleLimit(int pos)
          Return the index after the last character in the character style run containing pos.
abstract  int characterStyleStart(int pos)
          Return the index of the first character in the character style run containing pos.
 java.text.CharacterIterator createCharacterIterator()
          Create a java.text.CharacterIterator over all of the characters in the text.
abstract  java.text.CharacterIterator createCharacterIterator(int start, int limit)
          Create a java.text.CharacterIterator over the given range of characters in the text.
abstract  int damagedRangeLimit()
          Return the limit of the damaged range.
abstract  int damagedRangeStart()
          Return the start of the damaged range.
 boolean equals(MConstText rhs)
          Compare this to another MConstText for equality.
 boolean equals(java.lang.Object rhs)
          Compare this to another Object for equality.
abstract  MConstText extract(int start, int limit)
          Create an MConstText containing the characters and styles in the range [start, limit).
abstract  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.
abstract  int getTimeStamp()
          Return the current time stamp.
 int hashCode()
          Return the hashCode for this MConstText.
abstract  int length()
          Return the length of the MConstText object.
abstract  int paragraphLimit(int pos)
          Return the limit of the paragraph containing the character at offset pos.
abstract  int paragraphStart(int pos)
          Return the start of the paragraph containing the character at offset pos.
abstract  AttributeMap paragraphStyleAt(int pos)
          Return the paragraph style applied to the paragraph containing offset pos.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

styledTextFlavor

public static final java.awt.datatransfer.DataFlavor styledTextFlavor
The DataFlavor for MConstText clipboard content. Used to indicate that clipboard data has an MConstText representation.
Constructor Detail

MConstText

protected MConstText()
Method Detail

at

public abstract char at(int pos)
Return the character at offset pos.
Parameters:
pos - a valid offset into the text

extractChars

public abstract 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.
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 abstract MConstText extract(int start,
                                   int limit)
Create an MConstText 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

createCharacterIterator

public java.text.CharacterIterator createCharacterIterator()
Create a java.text.CharacterIterator over all of the characters in the text. Default implementation calls createCharacterIterator(0, length())
Returns:
a java.text.CharacterIterator over all of the characters in the text

createCharacterIterator

public abstract java.text.CharacterIterator createCharacterIterator(int start,
                                                                    int limit)
Create a java.text.CharacterIterator over the given range of characters in the text.
Parameters:
start - the first index in the iteration range
limit - the index after the last character in the iteration range
Returns:
a java.text.CharacterIterator over the given range

length

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

characterStyleStart

public abstract 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.

characterStyleLimit

public abstract 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.

characterStyleAt

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

paragraphStart

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

paragraphLimit

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

paragraphStyleAt

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

getTimeStamp

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

damagedRangeStart

public abstract int damagedRangeStart()
Return the start of the damaged range. If the start is not less than the the limit of the damaged range, then the damaged range is empty.
Returns:
the start of the damaged range
See Also:
damagedRangeLimit(), MText.resetDamagedRange()

damagedRangeLimit

public abstract int damagedRangeLimit()
Return the limit of the damaged range. If the start is not less than the the limit of the damaged range, then the damaged range is empty.
Returns:
the start of the damaged range
See Also:
damagedRangeStart(), MText.resetDamagedRange()

equals

public final boolean equals(java.lang.Object rhs)
Compare this to another Object for equality. This is equal to rhs if rhs is an MConstText which is equal to this.
Overrides:
equals in class java.lang.Object
Parameters:
rhs - Object to compare to
Returns:
true if this equals rhs

equals

public boolean equals(MConstText rhs)
Compare this to another MConstText for equality. This is equal to rhs if the characters and styles in rhs are the same as this. Subclasses may override this implementation for efficiency, but they should preserve these semantics. Determining that two MConstText instances are equal may be an expensive operation, since every character and style must be compared.
Parameters:
rhs - Object to compare to
Returns:
true if this equals rhs

hashCode

public final int hashCode()
Return the hashCode for this MConstText. An empty MConstText has hashCode 0; a nonempty MConstText's hashCode is
       at(0) +
       at(length/2)*31^1 +
       at(length-1)*31^2 +
       characterStyleAt(0).hashCode()*31^3 +
       paragraphStyleAt(length-1).hashCode()*31^4
 
where ^ is exponentiation (not bitwise XOR).
Overrides:
hashCode in class java.lang.Object


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