APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.font

public final Class TextHitInfo

extends Object
Class Inheritance
Imports
java.lang.String

The 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
See Also
TextLayout

Field Summary

Modifier and TypeField and Description
private int
private boolean

Constructor Summary

AccessConstructor and Description
private
TextHitInfo(int
the index of the character hit
charIndex
,
boolean
true if the leading edge of the character was hit
isLeadingEdge
)

Constructs a new TextHitInfo.

Method Summary

Modifier and TypeMethod and Description
public static TextHitInfo

Returns:

a TextHitInfo at the specified offset.
afterOffset
(int
an offset associated with the character after the offset
offset
)

Creates a TextHitInfo at the specified offset, associated with the character after the offset.

public static TextHitInfo

Returns:

a TextHitInfo at the specified offset.
beforeOffset
(int
an offset associated with the character before the offset
offset
)

Creates a TextHitInfo at the specified offset, associated with the character before the offset.

public boolean

Returns:

true if the specified Object equals this TextHitInfo; false otherwise.
equals
(Object
the Object to test for equality
obj
)

Overrides java.lang.Object.equals.

Returns true if the specified Object is a TextHitInfo and equals this TextHitInfo.

public boolean

Returns:

true if the specified TextHitInfo has the same charIndex and isLeadingEdge as this TextHitInfo.
equals
(TextHitInfo
a specified TextHitInfo
hitInfo
)

Returns true if the specified TextHitInfo has the same charIndex and isLeadingEdge as this TextHitInfo.

public int

Returns:

the index of the character hit.
getCharIndex
()

Returns the index of the character hit.

public int

Returns:

the insertion index.
getInsertionIndex
()

Returns the insertion index.

public TextHitInfo

Returns:

a TextHitInfo whose charIndex is offset by delta from the charIndex of this TextHitInfo.
getOffsetHit
(int
the value to offset this charIndex
delta
)

Creates a TextHitInfo whose character index is offset by delta from the charIndex of this TextHitInfo.

public TextHitInfo

Returns:

a TextHitInfo on the other side of the insertion point.
getOtherHit
()

Creates a TextHitInfo on the other side of the insertion point.

public int

Returns:

the hash code of this TextHitInfo, which is also the charIndex of this TextHitInfo.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns the hash code.

public boolean

Returns:

true if the leading edge of the character was hit; false otherwise.
isLeadingEdge
()

Returns true if the leading edge of the character was hit.

public static TextHitInfo

Returns:

a TextHitInfo on the leading edge of the character at the specified charIndex.
leading
(int
the index of the character hit
charIndex
)

Creates a TextHitInfo on the leading edge of the character at the specified charIndex.

public String

Returns:

a String representing this TextHitInfo.
toString
()

Overrides java.lang.Object.toString.

Returns a String representing the hit for debugging use only.

public static TextHitInfo

Returns:

a TextHitInfo on the trailing edge of the character at the specified charIndex.
trailing
(int
the index of the character hit
charIndex
)

Creates a hit on the trailing edge of the character at the specified charIndex.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

charIndexback to summary
private int charIndex
isLeadingEdgeback to summary
private boolean isLeadingEdge

Constructor Detail

TextHitInfoback to summary
private TextHitInfo(int charIndex, boolean isLeadingEdge)

Constructs a new TextHitInfo.

Parameters
charIndex:int

the index of the character hit

isLeadingEdge:boolean

true if the leading edge of the character was hit

Method Detail

afterOffsetback to summary
public static TextHitInfo afterOffset(int offset)

Creates a TextHitInfo at the specified offset, associated with the character after the offset.

Parameters
offset:int

an offset associated with the character after the offset

Returns:TextHitInfo

a TextHitInfo at the specified offset.

beforeOffsetback to summary
public static TextHitInfo beforeOffset(int offset)

Creates a TextHitInfo at the specified offset, associated with the character before the offset.

Parameters
offset:int

an offset associated with the character before the offset

Returns:TextHitInfo

a TextHitInfo at the specified offset.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Returns true if the specified Object is a TextHitInfo and equals this TextHitInfo.

Parameters
obj:Object

the Object to test for equality

Returns:boolean

true if the specified Object equals this TextHitInfo; false otherwise.

equalsback to summary
public boolean equals(TextHitInfo hitInfo)

Returns true if the specified TextHitInfo has the same charIndex and isLeadingEdge as this TextHitInfo. This is not the same as having the same insertion offset.

Parameters
hitInfo:TextHitInfo

a specified TextHitInfo

Returns:boolean

true if the specified TextHitInfo has the same charIndex and isLeadingEdge as this TextHitInfo.

getCharIndexback to summary
public int getCharIndex()

Returns the index of the character hit.

Returns:int

the index of the character hit.

getInsertionIndexback 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.

Returns:int

the insertion index.

getOffsetHitback to summary
public TextHitInfo getOffsetHit(int delta)

Creates a TextHitInfo whose character index is offset by delta from the charIndex of this TextHitInfo. This TextHitInfo remains unchanged.

Parameters
delta:int

the value to offset this charIndex

Returns:TextHitInfo

a TextHitInfo whose charIndex is offset by delta from the charIndex of this TextHitInfo.

getOtherHitback to summary
public TextHitInfo getOtherHit()

Creates a TextHitInfo on the other side of the insertion point. This TextHitInfo remains unchanged.

Returns:TextHitInfo

a TextHitInfo on the other side of the insertion point.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hash code.

Returns:int

the hash code of this TextHitInfo, which is also the charIndex of this TextHitInfo.

isLeadingEdgeback to summary
public boolean isLeadingEdge()

Returns true if the leading edge of the character was hit.

Returns:boolean

true if the leading edge of the character was hit; false otherwise.

leadingback to summary
public static TextHitInfo leading(int charIndex)

Creates a TextHitInfo on the leading edge of the character at the specified charIndex.

Parameters
charIndex:int

the index of the character hit

Returns:TextHitInfo

a TextHitInfo on the leading edge of the character at the specified charIndex.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a String representing the hit for debugging use only.

Returns:String

a String representing this TextHitInfo.

trailingback to summary
public static TextHitInfo trailing(int charIndex)

Creates a hit on the trailing edge of the character at the specified charIndex.

Parameters
charIndex:int

the index of the character hit

Returns:TextHitInfo

a TextHitInfo on the trailing edge of the character at the specified charIndex.