TextHitInfo class represents a character position in a
text model, and a bias, or "side," of the character. Biases are
either leading (the left edge, for a left-to-right character)
or trailing (the right edge, for a left-to-right character).
Instances of TextHitInfo are used to specify caret and
insertion positions within text.
For example, consider the text "abc". TextHitInfo.trailing(1) corresponds to the right side of the 'b' in the text.
TextHitInfo is used primarily by TextLayout and
clients of TextLayout. Clients of TextLayout
query TextHitInfo instances for an insertion offset, where
new text is inserted into the text model. The insertion offset is equal
to the character position in the TextHitInfo if the bias
is leading, and one character after if the bias is trailing. The
insertion offset for TextHitInfo.trailing(1) is 2.
Sometimes it is convenient to construct a TextHitInfo with
the same insertion offset as an existing one, but on the opposite
character. The getOtherHit method constructs a new
TextHitInfo with the same insertion offset as an existing
one, with a hit on the character on the other side of the insertion offset.
Calling getOtherHit on trailing(1) would return leading(2).
In general, getOtherHit for trailing(n) returns
leading(n+1) and getOtherHit for leading(n)
returns trailing(n-1).
Example:
Converting a graphical point to an insertion point within a text model
TextLayout layout = ...; Point2D.Float hitPoint = ...; TextHitInfo hitInfo = layout.hitTestChar(hitPoint.x, hitPoint.y); int insPoint = hitInfo.getInsertionIndex(); // insPoint is relative to layout; may need to adjust for use // in a text model
TextLayout
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| private | TextHitInfo(int
the index of the character hit charIndex, boolean true if the leading edge of the
character was hitConstructs a new |
| Modifier and Type | Method and Description |
|---|---|
| public static TextHitInfo | Returns: aTextHitInfo at the specified offset.an offset associated with the character after
the offset offset)Creates a |
| public static TextHitInfo | Returns: aTextHitInfo at the specified offset.an offset associated with the character before
the offset offset)Creates a |
| public boolean | Returns: true if the specified Object
equals this TextHitInfo; false otherwise.the obj)Object to test for equalityOverrides java. Returns |
| public boolean | Returns: true if the specified TextHitInfo
has the same charIndex and isLeadingEdge
as this TextHitInfo.a specified hitInfo)TextHitInfoReturns |
| public int | |
| public int | |
| public TextHitInfo | Returns: aTextHitInfo whose charIndex is
offset by delta from the charIndex of
this TextHitInfo.the value to offset this delta)charIndexCreates a |
| public TextHitInfo | Returns: aTextHitInfo on the other side of the
insertion point.Creates a |
| public int | Returns: the hash code of thisTextHitInfo, which is
also the charIndex of this TextHitInfo.Overrides java. Returns the hash code. |
| public boolean | Returns: true if the leading edge of the character was
hit; false otherwise.Returns |
| public static TextHitInfo | Returns: aTextHitInfo on the leading edge of the
character at the specified charIndex.the index of the character hit charIndex)Creates a |
| public String | Returns: aString representing this
TextHitInfo.Overrides java. Returns a |
| public static TextHitInfo | Returns: aTextHitInfo on the trailing edge of the
character at the specified charIndex.the index of the character hit charIndex)Creates a hit on the trailing edge of the character at
the specified |
| charIndex | back to summary |
|---|---|
| private int charIndex | |
| isLeadingEdge | back to summary |
|---|---|
| private boolean isLeadingEdge | |
| TextHitInfo | back to summary |
|---|---|
| private TextHitInfo(int charIndex, boolean isLeadingEdge) Constructs a new
| |
| afterOffset | back to summary |
|---|---|
| public static TextHitInfo afterOffset(int offset) Creates a
| |
| beforeOffset | back to summary |
|---|---|
| public static TextHitInfo beforeOffset(int offset) Creates a
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Returns
| |
| equals | back to summary |
|---|---|
| public boolean equals(TextHitInfo hitInfo) Returns
| |
| getCharIndex | back to summary |
|---|---|
| public int getCharIndex() Returns the index of the character hit.
| |
| getInsertionIndex | back to summary |
|---|---|
| public int getInsertionIndex() Returns the insertion index. This is the character index if the leading edge of the character was hit, and one greater than the character index if the trailing edge was hit.
| |
| getOffsetHit | back to summary |
|---|---|
| public TextHitInfo getOffsetHit(int delta) Creates a
| |
| getOtherHit | back to summary |
|---|---|
| public TextHitInfo getOtherHit() Creates a
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns the hash code.
| |
| isLeadingEdge | back to summary |
|---|---|
| public boolean isLeadingEdge() Returns
| |
| leading | back to summary |
|---|---|
| public static TextHitInfo leading(int charIndex) Creates a
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a
| |
| trailing | back to summary |
|---|---|
| public static TextHitInfo trailing(int charIndex) Creates a hit on the trailing edge of the character at
the specified
| |