All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class java.awt.font.TextHitInfo

java.lang.Object
    |
    +----java.awt.font.TextHitInfo

public final class TextHitInfo
extends Object
TextHitInfo 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". 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
 

See Also:
TextLayout

Variable Index

 o LEADING
 o TRAILING

Constructor Index

 o TextHitInfo(int, boolean)
Constructor for TextHitInfo.

Method Index

 o equals(Object)
Return true if the object is a TextHitInfo and this TextHitInfo is equal to it.
 o equals(TextHitInfo)
Return true if the hit's character index and edge are the same.
 o getCharIndex()
Returns the index of the character hit.
 o getInsertionIndex()
Returns the insertion index.
 o getOffsetHit(int)
Creates a hit whose character index is offset by delta from this hit.
 o getOtherHit()
Creates a hit on the other side of the insertion point.
 o hashCode()
Returns the hash code.
 o isLeadingEdge()
Returns true if the leading edge of the character was hit.
 o leading(int)
Create a hit on the leading edge of the character at charIndex.
 o toString()
Return a string representing the hit, for debugging use only.
 o trailing(int)
Create a hit on the trailing edge of the character at charIndex.

Variables

 o LEADING
public static boolean LEADING
 o TRAILING
public static boolean TRAILING

Constructors

 o TextHitInfo
public TextHitInfo(int charIndex,
                   boolean isLeadingEdge)
Constructor for TextHitInfo.

Parameters:
charIndex - the index of the character hit.
isLeadingEdge - true if the leading edge of the character was hit.

Methods

 o getCharIndex
public int getCharIndex()
Returns the index of the character hit.

 o isLeadingEdge
public boolean isLeadingEdge()
Returns true if the leading edge of the character was hit.

 o getInsertionIndex
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.

 o hashCode
public int hashCode()
Returns the hash code.

Overrides:
hashCode in class Object
 o equals
public boolean equals(Object obj)
Return true if the object is a TextHitInfo and this TextHitInfo is equal to it.

Overrides:
equals in class Object
 o equals
public boolean equals(TextHitInfo hitInfo)
Return true if the hit's character index and edge are the same. This is not the same as having the same insertion offset.

 o toString
public String toString()
Return a string representing the hit, for debugging use only.

Overrides:
toString in class Object
 o leading
public static TextHitInfo leading(int charIndex)
Create a hit on the leading edge of the character at charIndex.

 o trailing
public static TextHitInfo trailing(int charIndex)
Create a hit on the trailing edge of the character at charIndex.

 o getOtherHit
public TextHitInfo getOtherHit()
Creates a hit on the other side of the insertion point. This hit remains unchanged.

 o getOffsetHit
public TextHitInfo getOffsetHit(int delta)
Creates a hit whose character index is offset by delta from this hit. This hit remains unchanged.


All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Submit a bug or feature