java.awt.font
Class TextHitInfo

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.font.TextHitInfo

public final class TextHitInfo
extends Object sample code for java.lang.Object definition code for java.lang.Object

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 sample code for java.awt.font.TextLayout definition code for java.awt.font.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 sample code for java.awt.font.TextLayout definition code for java.awt.font.TextLayout

Method Summary
static TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo afterOffset sample code for java.awt.font.TextHitInfo.afterOffset(int) definition code for java.awt.font.TextHitInfo.afterOffset(int) (int offset)
          Creates a TextHitInfo at the specified offset, associated with the character after the offset.
static TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo beforeOffset sample code for java.awt.font.TextHitInfo.beforeOffset(int) definition code for java.awt.font.TextHitInfo.beforeOffset(int) (int offset)
          Creates a TextHitInfo at the specified offset, associated with the character before the offset.
 boolean equals sample code for java.awt.font.TextHitInfo.equals(java.lang.Object) definition code for java.awt.font.TextHitInfo.equals(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  obj)
          Returns true if the specified Object is a TextHitInfo and equals this TextHitInfo.
 boolean equals sample code for java.awt.font.TextHitInfo.equals(java.awt.font.TextHitInfo) definition code for java.awt.font.TextHitInfo.equals(java.awt.font.TextHitInfo) (TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  hitInfo)
          Returns true if the specified TextHitInfo has the same charIndex and isLeadingEdge as this TextHitInfo.
 int getCharIndex sample code for java.awt.font.TextHitInfo.getCharIndex() definition code for java.awt.font.TextHitInfo.getCharIndex() ()
          Returns the index of the character hit.
 int getInsertionIndex sample code for java.awt.font.TextHitInfo.getInsertionIndex() definition code for java.awt.font.TextHitInfo.getInsertionIndex() ()
          Returns the insertion index.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getOffsetHit sample code for java.awt.font.TextHitInfo.getOffsetHit(int) definition code for java.awt.font.TextHitInfo.getOffsetHit(int) (int delta)
          Creates a TextHitInfo whose character index is offset by delta from the charIndex of this TextHitInfo.
 TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo getOtherHit sample code for java.awt.font.TextHitInfo.getOtherHit() definition code for java.awt.font.TextHitInfo.getOtherHit() ()
          Creates a TextHitInfo on the other side of the insertion point.
 int hashCode sample code for java.awt.font.TextHitInfo.hashCode() definition code for java.awt.font.TextHitInfo.hashCode() ()
          Returns the hash code.
 boolean isLeadingEdge sample code for java.awt.font.TextHitInfo.isLeadingEdge() definition code for java.awt.font.TextHitInfo.isLeadingEdge() ()
          Returns true if the leading edge of the character was hit.
static TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo leading sample code for java.awt.font.TextHitInfo.leading(int) definition code for java.awt.font.TextHitInfo.leading(int) (int charIndex)
          Creates a TextHitInfo on the leading edge of the character at the specified charIndex.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.awt.font.TextHitInfo.toString() definition code for java.awt.font.TextHitInfo.toString() ()
          Returns a String representing the hit for debugging use only.
static TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo trailing sample code for java.awt.font.TextHitInfo.trailing(int) definition code for java.awt.font.TextHitInfo.trailing(int) (int charIndex)
          Creates a hit on the trailing edge of the character at the specified charIndex.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Method Detail

getCharIndex sample code for java.awt.font.TextHitInfo.getCharIndex() definition code for java.awt.font.TextHitInfo.getCharIndex()

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

Returns:
the index of the character hit.

isLeadingEdge sample code for java.awt.font.TextHitInfo.isLeadingEdge() definition code for java.awt.font.TextHitInfo.isLeadingEdge()

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

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

getInsertionIndex sample code for java.awt.font.TextHitInfo.getInsertionIndex() definition code for java.awt.font.TextHitInfo.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.

Returns:
the insertion index.

hashCode sample code for java.awt.font.TextHitInfo.hashCode() definition code for java.awt.font.TextHitInfo.hashCode()

public int hashCode()
Returns the hash code.

Overrides:
hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
the hash code of this TextHitInfo, which is also the charIndex of this TextHitInfo.
See Also:
Object.equals(java.lang.Object) sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

equals sample code for java.awt.font.TextHitInfo.equals(java.lang.Object) definition code for java.awt.font.TextHitInfo.equals(java.lang.Object)

public boolean equals(Object sample code for java.lang.Object definition code for java.lang.Object  obj)
Returns true if the specified Object is a TextHitInfo and equals this TextHitInfo.

Overrides:
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) in class Object sample code for java.lang.Object definition code for java.lang.Object
Parameters:
obj - the Object to test for equality
Returns:
true if the specified Object equals this TextHitInfo; false otherwise.
See Also:
Object.hashCode() sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , Hashtable sample code for java.util.Hashtable definition code for java.util.Hashtable

equals sample code for java.awt.font.TextHitInfo.equals(java.awt.font.TextHitInfo) definition code for java.awt.font.TextHitInfo.equals(java.awt.font.TextHitInfo)

public boolean equals(TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.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 - a specified TextHitInfo
Returns:
true if the specified TextHitInfo has the same charIndex and isLeadingEdge as this TextHitInfo.

toString sample code for java.awt.font.TextHitInfo.toString() definition code for java.awt.font.TextHitInfo.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns a String representing the hit for debugging use only.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a String representing this TextHitInfo.

leading sample code for java.awt.font.TextHitInfo.leading(int) definition code for java.awt.font.TextHitInfo.leading(int)

public static TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  leading(int charIndex)
Creates a TextHitInfo on the leading edge of the character at the specified charIndex.

Parameters:
charIndex - the index of the character hit
Returns:
a TextHitInfo on the leading edge of the character at the specified charIndex.

trailing sample code for java.awt.font.TextHitInfo.trailing(int) definition code for java.awt.font.TextHitInfo.trailing(int)

public static TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  trailing(int charIndex)
Creates a hit on the trailing edge of the character at the specified charIndex.

Parameters:
charIndex - the index of the character hit
Returns:
a TextHitInfo on the trailing edge of the character at the specified charIndex.

beforeOffset sample code for java.awt.font.TextHitInfo.beforeOffset(int) definition code for java.awt.font.TextHitInfo.beforeOffset(int)

public static TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  beforeOffset(int offset)
Creates a TextHitInfo at the specified offset, associated with the character before the offset.

Parameters:
offset - an offset associated with the character before the offset
Returns:
a TextHitInfo at the specified offset.

afterOffset sample code for java.awt.font.TextHitInfo.afterOffset(int) definition code for java.awt.font.TextHitInfo.afterOffset(int)

public static TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  afterOffset(int offset)
Creates a TextHitInfo at the specified offset, associated with the character after the offset.

Parameters:
offset - an offset associated with the character after the offset
Returns:
a TextHitInfo at the specified offset.

getOtherHit sample code for java.awt.font.TextHitInfo.getOtherHit() definition code for java.awt.font.TextHitInfo.getOtherHit()

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.TextHitInfo  getOtherHit()
Creates a TextHitInfo on the other side of the insertion point. This TextHitInfo remains unchanged.

Returns:
a TextHitInfo on the other side of the insertion point.

getOffsetHit sample code for java.awt.font.TextHitInfo.getOffsetHit(int) definition code for java.awt.font.TextHitInfo.getOffsetHit(int)

public TextHitInfo sample code for java.awt.font.TextHitInfo definition code for java.awt.font.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 - the value to offset this charIndex
Returns:
a TextHitInfo whose charIndex is offset by delta from the charIndex of this TextHitInfo.