FileDocCategorySizeDatePackage
TextHitInfo.javaAPI DocAndroid 1.5 API6743Wed May 06 22:41:54 BST 2009java.awt.font

TextHitInfo

public final class TextHitInfo extends Object
The TextHitInfo class provides information about a caret position in a text model for insertion or deletion of a character in a text. The TextHitInfo defines two biases of the character: leading or trailing. Leading position means the left edge of the specified character (TextHitInfo.leading(2) method for "text" returns the left side of "x"). Trailing position means the right edge of the specified character (TextHitInfo.trailing(2) method for "text" returns the right side of "x").
since
Android 1.0

Fields Summary
private int
charIdx
The char idx.
private boolean
isTrailing
The is trailing.
Constructors Summary
private TextHitInfo(int idx, boolean isTrailing)
Instantiates a new text hit info.

param
idx the idx.
param
isTrailing the is trailing.

        charIdx = idx;
        this.isTrailing = isTrailing;
    
Methods Summary
public static java.awt.font.TextHitInfoafterOffset(int offset)
Returns a (leading) TextHitInfo object associated with the character after the specified offset.

param
offset the offset.
return
the TextHitInfo object associated with the character after the specified offset.

        return new TextHitInfo(offset, false);
    
public static java.awt.font.TextHitInfobeforeOffset(int offset)
Returns a (trailing) TextHitInfo object associated with the character before the specified offset.

param
offset the offset.
return
the TextHitInfo object associated with the character before the specified offset.

        return new TextHitInfo(offset - 1, true);
    
public booleanequals(java.lang.Object obj)
Compares this TextHitInfo object with the specified object.

param
obj the Object to be compared.
return
true, if the specified object is a TextHitInfo object with the same data values as this TextHitInfo, false otherwise.

        if (obj instanceof TextHitInfo) {
            return equals((TextHitInfo)obj);
        }
        return false;
    
public booleanequals(java.awt.font.TextHitInfo thi)
Compares this TextHitInfo object with the specified TextHitInfo object.

param
thi the TextHitInfo object to be compared.
return
true, if this TextHitInfo object has the same data values as the specified TextHitInfo object, false otherwise.

        return thi != null && thi.charIdx == charIdx && thi.isTrailing == isTrailing;
    
public intgetCharIndex()
Gets the index of the character hit.

return
the character hit's index.

        return charIdx;
    
public intgetInsertionIndex()
Gets the insertion index.

return
the insertion index: character index if the leading edge is hit, or character index + 1 if the trailing edge is hit.

        return isTrailing ? charIdx + 1 : charIdx;
    
public java.awt.font.TextHitInfogetOffsetHit(int offset)
Gets a TextHitInfo object with its character index at the specified offset from the character index of this TextHitInfo.

param
offset the offset.
return
the TextHitInfo.

        return new TextHitInfo(charIdx + offset, isTrailing);
    
public java.awt.font.TextHitInfogetOtherHit()
Gets a TextHitInfo associated with the other side of the insertion point.

return
the other hit.

        return isTrailing ? new TextHitInfo(charIdx + 1, false)
                : new TextHitInfo(charIdx - 1, true);
    
public inthashCode()
Returns the hash code value of this TextHitInfo instance.

return
the hash code value.

        return HashCode.combine(charIdx, isTrailing);
    
public booleanisLeadingEdge()
Returns true if the leading edge of the character is hit, false if the trailing edge of the character is hit.

return
true if the leading edge of the character is hit, false if the trailing edge of the character is hit.

        return !isTrailing;
    
public static java.awt.font.TextHitInfoleading(int charIndex)
Returns a TextHitInfo object associated with the leading edge of the character at the specified char index.

param
charIndex the char index.
return
the TextHitInfo object associated with the leading edge of the character at the specified char index.

        return new TextHitInfo(charIndex, false);
    
public java.lang.StringtoString()
Returns the textual string representation of this TextHitInfo instance.

return
the string representation.

        return new String("TextHitInfo[" + charIdx + ", " + //$NON-NLS-1$ //$NON-NLS-2$
                (isTrailing ? "Trailing" : "Leading") + "]" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        );
    
public static java.awt.font.TextHitInfotrailing(int charIndex)
Returns a TextHitInfo associated with the trailing edge of the character at the specified char index.

param
charIndex the char index.
return
the TextHitInfo associated with the trailing edge of the character at the specified char index.

        return new TextHitInfo(charIndex, true);