Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----java.awt.font.TextHitInfo
For example, consider the text "abc". The TextHitInfo (1, TRAILING) 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 (1, TRAILING) 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 (1, TRAILING) would return (2, LEADING).
In general, getOtherHit
for (n, TRAILING) returns
(n+1, LEADING) and getOtherHit
for (n, LEADING)
returns (n-1, TRAILING).
Example:
Converting a graphical point to an insertion point within a text model
TextLayout layout = ...; Point2D hitPoint = ...; TextHitInfo hitInfo = layout.hitTestChar(hitPoint.x, hitPoint.y); int insPoint = hitInfo.getInsertionOffset(); // insPoint is relative to layout; may need to adjust for use // in a text model
Field Summary | |
static boolean | LEADING
|
static boolean | TRAILING
|
Method Summary | |
static TextHitInfo | afterOffset(int offset)
|
static TextHitInfo | beforeOffset(int offset)
|
boolean | equals(Object obj)
|
boolean | equals(TextHitInfo hitInfo)
|
int | getCharIndex()
|
int | getInsertionIndex()
|
TextHitInfo | getOffsetHit(int delta)
|
TextHitInfo | getOtherHit()
|
int | hashCode()
|
boolean | isLeadingEdge()
|
static TextHitInfo | leading(int charIndex)
|
String | toString()
|
static TextHitInfo | trailing(int charIndex)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static boolean LEADING
public static boolean TRAILING
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)
Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |