|
Java Platform 1.2 Beta 4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.font.TextHitInfo
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 will query TextHitInfo instances for an insertion offset, where new text will be inserted into the text model. The insertion offset is equals 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.
getOtherHit
will construct 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
Method Summary | |
static TextHitInfo | afterOffset(int offset)
Create a hit at offset, associated with the character after the offset. |
static TextHitInfo | beforeOffset(int offset)
Create a hit at offset, associated with the character before the offset. |
boolean | equals(Object obj)
Return true if the object is a TextHitInfo and this TextHitInfo is equal to it. |
boolean | equals(TextHitInfo hitInfo)
Return true if the hit's character index and edge are the same. |
int | getCharIndex()
Returns the index of the character hit. |
int | getInsertionIndex()
Returns the insertion index. |
TextHitInfo | getOffsetHit(int delta)
Creates a hit whose character index is offset by delta from this hit. |
TextHitInfo | getOtherHit()
Creates a hit on the other side of the insertion point. |
int | hashCode()
Returns the hash code. |
boolean | isLeadingEdge()
Returns true if the leading edge of the character was hit. |
static TextHitInfo | leading(int charIndex)
Create a hit on the leading edge of the character at charIndex. |
String | toString()
Return a string representing the hit, for debugging use only. |
static TextHitInfo | trailing(int charIndex)
Create a hit on the trailing edge of the character at charIndex. |
Methods inherited from class java.lang.Object | |
clone , finalize , getClass , notify , notifyAll , wait , wait , wait |
Method Detail |
public int getCharIndex()
public boolean isLeadingEdge()
public int getInsertionIndex()
public int hashCode()
public boolean equals(Object obj)
public boolean equals(TextHitInfo hitInfo)
public String toString()
public static TextHitInfo leading(int charIndex)
public static TextHitInfo trailing(int charIndex)
public static TextHitInfo beforeOffset(int offset)
public static TextHitInfo afterOffset(int offset)
public TextHitInfo getOtherHit()
public TextHitInfo getOffsetHit(int delta)
|
Java Platform 1.2 Beta 4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |