com.ibm.richtext.textformat
Class TextOffset

java.lang.Object
  |
  +--com.ibm.richtext.textformat.TextOffset

public final class TextOffset
extends java.lang.Object

A TextOffset indicates both an integer offset into text and a placement on one of the characters adjacent to the offset. An offset is a position between two characters; offset n is between character n-1 and character n. The placement specifies whether it is associated with the character after the offset (character n) or the character before the offset (character n-1).

Knowing which character the TextOffset is associated with is necessary when displaying carets. In bidirectional text, a single offset may have two distinct carets. Also, in multiline text, an offset at a line break has a possible caret on each line.

Most clients will not be interested in the placement, and will just use the offset.


Field Summary
static boolean AFTER_OFFSET
          Indicates that the TextOffset is associated with character fOffset - ie the character after its offset.
static boolean BEFORE_OFFSET
          Indicates that the TextOffset is associated with character fOffset - 1 - ie the character before its offset.
 int fOffset
          The offset into the text.
 boolean fPlacement
          The placement - before or after.
 
Constructor Summary
TextOffset()
          Constructs a new TextOffset at 0, with placement AFTER_OFFSET.
TextOffset(int offset)
          Constructs a new TextOffset
TextOffset(int offset, boolean placement)
          Constructs a new TextOffset with the given offset and placement.
TextOffset(TextOffset rhs)
          Constructs a new TextOffset from an existing one.
 
Method Summary
 void assign(TextOffset other)
          Copy the value of another TextOffset into this
 boolean equals(java.lang.Object other)
          Compare this to another Object.
 boolean equals(TextOffset other)
          Return true if offset and placement are the same.
 boolean greaterThan(TextOffset other)
          Return true if this offset is 'greaterThan' other.
 int hashCode()
          Return the hashCode for this object.
 boolean lessThan(TextOffset other)
          Return true if this offset is 'lessThan' other.
 void setOffset(int offset, boolean placement)
          Set the value of the TextOffset
 java.lang.String toString()
          Return a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BEFORE_OFFSET

public static final boolean BEFORE_OFFSET
Indicates that the TextOffset is associated with character fOffset - 1 - ie the character before its offset.

AFTER_OFFSET

public static final boolean AFTER_OFFSET
Indicates that the TextOffset is associated with character fOffset - ie the character after its offset.

fOffset

public int fOffset
The offset into the text.

fPlacement

public boolean fPlacement
The placement - before or after.
Constructor Detail

TextOffset

public TextOffset(int offset)
Constructs a new TextOffset
Parameters:
offset - the offset into the text to represent. Placement is implicitly AFTER_OFFSET.

TextOffset

public TextOffset()
Constructs a new TextOffset at 0, with placement AFTER_OFFSET.

TextOffset

public TextOffset(int offset,
                  boolean placement)
Constructs a new TextOffset with the given offset and placement.
Parameters:
offset - the offset into the text
placement - indicates the position of the caret; one of BEFORE_OFFSET or AFTER_OFFSET

TextOffset

public TextOffset(TextOffset rhs)
Constructs a new TextOffset from an existing one.
Parameters:
ths - the TextOffset to copy
Method Detail

setOffset

public void setOffset(int offset,
                      boolean placement)
Set the value of the TextOffset
Parameters:
offset - the offset into the text
placement - indicates the position of the caret; one of BEFORE_OFFSET or AFTER_OFFSET

equals

public boolean equals(java.lang.Object other)
Compare this to another Object.
Overrides:
equals in class java.lang.Object

equals

public boolean equals(TextOffset other)
Return true if offset and placement are the same.
Parameters:
other - offset to compare against
Returns:
true if both offsets are equal

hashCode

public int hashCode()
Return the hashCode for this object.
Overrides:
hashCode in class java.lang.Object

greaterThan

public boolean greaterThan(TextOffset other)
Return true if this offset is 'greaterThan' other. If the fOffset fields are equal, the placement field is considered, and AFTER_OFFSET is considered 'greaterThan' BEFORE_OFFSET.
Parameters:
other - the other offset
Returns:
true if this offset appears after other

lessThan

public boolean lessThan(TextOffset other)
Return true if this offset is 'lessThan' other. If the fOffset fields are equal, the placement field is considered, and BEFORE_OFFSET is considered 'lessThan' AFTER_OFFSET.
Parameters:
other - the other offset
Returns:
true if this offset appears before other

assign

public void assign(TextOffset other)
Copy the value of another TextOffset into this
Parameters:
other - the TextOffset to copy

toString

public java.lang.String toString()
Return a string representation of this object.
Overrides:
toString in class java.lang.Object


Copyright (c) 2001 IBM Corporation and others.