jdk/src/share/classes/java/awt/font/TextHitInfo.java
author mchung
Tue, 08 Dec 2009 09:02:09 -0800
changeset 4374 f672d9cf521e
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6907568: java/awt/KeyboardFocusManager.java inproperly merged and lost a changeset Summary: Reapply fix for 6879044 in java.awt.KeyboardFocusManager Reviewed-by: dcherepanov, asaha
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-1998 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The original version of this source code and documentation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * of IBM. These materials are provided under terms of a License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Agreement between Taligent and Sun. This technology is protected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * by multiple US and International patents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
package java.awt.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.lang.String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The <code>TextHitInfo</code> class represents a character position in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * text model, and a <b>bias</b>, or "side," of the character.  Biases are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * either <EM>leading</EM> (the left edge, for a left-to-right character)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * or <EM>trailing</EM> (the right edge, for a left-to-right character).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Instances of <code>TextHitInfo</code> are used to specify caret and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * insertion positions within text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * For example, consider the text "abc".  TextHitInfo.trailing(1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * corresponds to the right side of the 'b' in the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>TextHitInfo</code> is used primarily by {@link TextLayout} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * clients of <code>TextLayout</code>.  Clients of <code>TextLayout</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * query <code>TextHitInfo</code> instances for an insertion offset, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * new text is inserted into the text model.  The insertion offset is equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * to the character position in the <code>TextHitInfo</code> if the bias
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * is leading, and one character after if the bias is trailing.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * insertion offset for TextHitInfo.trailing(1) is 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Sometimes it is convenient to construct a <code>TextHitInfo</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * the same insertion offset as an existing one, but on the opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * character.  The <code>getOtherHit</code> method constructs a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <code>TextHitInfo</code> with the same insertion offset as an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * one, with a hit on the character on the other side of the insertion offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Calling <code>getOtherHit</code> on trailing(1) would return leading(2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * In general, <code>getOtherHit</code> for trailing(n) returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * leading(n+1) and <code>getOtherHit</code> for leading(n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * returns trailing(n-1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <strong>Example</strong>:<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Converting a graphical point to an insertion point within a text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * TextLayout layout = ...;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Point2D.Float hitPoint = ...;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * TextHitInfo hitInfo = layout.hitTestChar(hitPoint.x, hitPoint.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * int insPoint = hitInfo.getInsertionIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * // insPoint is relative to layout;  may need to adjust for use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * // in a text model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @see TextLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
public final class TextHitInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private int charIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private boolean isLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Constructs a new <code>TextHitInfo</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param charIndex the index of the character hit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param isLeadingEdge <code>true</code> if the leading edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * character was hit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private TextHitInfo(int charIndex, boolean isLeadingEdge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.charIndex = charIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.isLeadingEdge = isLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Returns the index of the character hit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return the index of the character hit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public int getCharIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return charIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Returns <code>true</code> if the leading edge of the character was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * hit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @return <code>true</code> if the leading edge of the character was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * hit; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public boolean isLeadingEdge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return isLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Returns the insertion index.  This is the character index if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * the leading edge of the character was hit, and one greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * than the character index if the trailing edge was hit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @return the insertion index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public int getInsertionIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return isLeadingEdge ? charIndex : charIndex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Returns the hash code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return the hash code of this <code>TextHitInfo</code>, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * also the <code>charIndex</code> of this <code>TextHitInfo</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return charIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Returns <code>true</code> if the specified <code>Object</code> is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <code>TextHitInfo</code> and equals this <code>TextHitInfo</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param obj the <code>Object</code> to test for equality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return <code>true</code> if the specified <code>Object</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * equals this <code>TextHitInfo</code>; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return (obj instanceof TextHitInfo) && equals((TextHitInfo)obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Returns <code>true</code> if the specified <code>TextHitInfo</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * has the same <code>charIndex</code> and <code>isLeadingEdge</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * as this <code>TextHitInfo</code>.  This is not the same as having
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * the same insertion offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param hitInfo a specified <code>TextHitInfo</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @return <code>true</code> if the specified <code>TextHitInfo</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * has the same <code>charIndex</code> and <code>isLeadingEdge</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * as this <code>TextHitInfo</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public boolean equals(TextHitInfo hitInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return hitInfo != null && charIndex == hitInfo.charIndex &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            isLeadingEdge == hitInfo.isLeadingEdge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Returns a <code>String</code> representing the hit for debugging
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * use only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @return a <code>String</code> representing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <code>TextHitInfo</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return "TextHitInfo[" + charIndex + (isLeadingEdge ? "L" : "T")+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Creates a <code>TextHitInfo</code> on the leading edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * character at the specified <code>charIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param charIndex the index of the character hit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return a <code>TextHitInfo</code> on the leading edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * character at the specified <code>charIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public static TextHitInfo leading(int charIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        return new TextHitInfo(charIndex, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Creates a hit on the trailing edge of the character at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * the specified <code>charIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param charIndex the index of the character hit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return a <code>TextHitInfo</code> on the trailing edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * character at the specified <code>charIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public static TextHitInfo trailing(int charIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return new TextHitInfo(charIndex, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Creates a <code>TextHitInfo</code> at the specified offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * associated with the character before the offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param offset an offset associated with the character before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * the offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return a <code>TextHitInfo</code> at the specified offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public static TextHitInfo beforeOffset(int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return new TextHitInfo(offset-1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Creates a <code>TextHitInfo</code> at the specified offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * associated with the character after the offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param offset an offset associated with the character after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * the offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @return a <code>TextHitInfo</code> at the specified offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public static TextHitInfo afterOffset(int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return new TextHitInfo(offset, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Creates a <code>TextHitInfo</code> on the other side of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * insertion point.  This <code>TextHitInfo</code> remains unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @return a <code>TextHitInfo</code> on the other side of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * insertion point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public TextHitInfo getOtherHit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (isLeadingEdge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            return trailing(charIndex - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return leading(charIndex + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Creates a <code>TextHitInfo</code> whose character index is offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * by <code>delta</code> from the <code>charIndex</code> of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <code>TextHitInfo</code>. This <code>TextHitInfo</code> remains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param delta the value to offset this <code>charIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @return a <code>TextHitInfo</code> whose <code>charIndex</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * offset by <code>delta</code> from the <code>charIndex</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * this <code>TextHitInfo</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public TextHitInfo getOffsetHit(int delta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        return new TextHitInfo(charIndex + delta, isLeadingEdge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
}