jdk/src/share/classes/java/awt/im/InputMethodRequests.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.im;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.font.TextHitInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.text.AttributedCharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.text.AttributedCharacterIterator.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * InputMethodRequests defines the requests that a text editing component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * has to handle in order to work with input methods. The component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * can implement this interface itself or use a separate object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * implements it. The object implementing this interface must be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * from the component's getInputMethodRequests method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The text editing component also has to provide an input method event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The interface is designed to support one of two input user interfaces:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <li><em>on-the-spot</em> input, where the composed text is displayed as part
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *     of the text component's text body.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <li><em>below-the-spot</em> input, where the composed text is displayed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *     a separate composition window just below the insertion point where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *     the text will be inserted when it is committed. Note that, if text is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     selected within the component's text body, this text will be replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *     the committed text upon commitment; therefore it is not considered part
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     of the context that the text is input into.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see java.awt.Component#getInputMethodRequests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see java.awt.event.InputMethodListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author JavaSoft Asia/Pacific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
public interface InputMethodRequests {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Gets the location of a specified offset in the current composed text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * or of the selection in committed text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * This information is, for example, used to position the candidate window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * near the composed text, or a composition window near the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * where committed text will be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * If the component has composed text (because the most recent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * InputMethodEvent sent to it contained composed text), then the offset is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * relative to the composed text - offset 0 indicates the first character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * in the composed text. The location returned should be for this character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * If the component doesn't have composed text, the offset should be ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * and the location returned should reflect the beginning (in line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * direction) of the highlight in the last line containing selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * For example, for horizontal left-to-right text (such as English), the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * location to the left of the left-most character on the last line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * containing selected text is returned. For vertical top-to-bottom text,
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
    86
     * with lines proceeding from right to left, the location to the top of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * left-most line containing selected text is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * The location is represented as a 0-thickness caret, that is, it has 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * width if the text is drawn horizontally, and 0 height if the text is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * drawn vertically. Other text orientations need to be mapped to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * horizontal or vertical orientation. The rectangle uses absolute screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param offset the offset within the composed text, if there is composed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * text; null otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @return a rectangle representing the screen location of the offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    Rectangle getTextLocation(TextHitInfo offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Gets the offset within the composed text for the specified absolute x
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * and y coordinates on the screen. This information is used, for example
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * to handle mouse clicks and the mouse cursor. The offset is relative to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * the composed text, so offset 0 indicates the beginning of the composed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Return null if the location is outside the area occupied by the composed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param x the absolute x coordinate on screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param y the absolute y coordinate on screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return a text hit info describing the offset in the composed text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    TextHitInfo getLocationOffset(int x, int y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Gets the offset of the insert position in the committed text contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * in the text editing component. This is the offset at which characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * entered through an input method are inserted. This information is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * by an input method, for example, to examine the text surrounding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * insert position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return the offset of the insert position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    int getInsertPositionOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Gets an iterator providing access to the entire text and attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * contained in the text editing component except for uncommitted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * text. Uncommitted (composed) text should be ignored for index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * calculations and should not be made accessible through the iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * The input method may provide a list of attributes that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * interested in. In that case, information about other attributes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * the implementor may have need not be made accessible through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * iterator. If the list is null, all available attribute information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * should be made accessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param beginIndex the index of the first character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param endIndex the index of the character following the last character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param attributes a list of attributes that the input method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * interested in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @return an iterator providing access to the text and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                                 Attribute[] attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Gets the length of the entire text contained in the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * editing component except for uncommitted (composed) text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @return the length of the text except for uncommitted text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    int getCommittedTextLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Gets the latest committed text from the text editing component and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * removes it from the component's text body.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * This is used for the "Undo Commit" feature in some input methods, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * the committed text reverts to its previous composed state. The composed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * text will be sent to the component using an InputMethodEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Generally, this feature should only be supported immediately after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * text was committed, not after the user performed other operations on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * text. When the feature is not supported, return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * The input method may provide a list of attributes that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * interested in. In that case, information about other attributes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * the implementor may have need not be made accessible through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * iterator. If the list is null, all available attribute information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * should be made accessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param attributes a list of attributes that the input method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * interested in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return the latest committed text, or null when the "Undo Commit"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * feature is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    AttributedCharacterIterator cancelLatestCommittedText(Attribute[] attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Gets the currently selected text from the text editing component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * This may be used for a variety of purposes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * One of them is the "Reconvert" feature in some input methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * In this case, the input method will typically send an input method event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * to replace the selected text with composed text. Depending on the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * method's capabilities, this may be the original composed text for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * selected text, the latest composed text entered anywhere in the text, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * a version of the text that's converted back from the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * The input method may provide a list of attributes that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * interested in. In that case, information about other attributes that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * the implementor may have need not be made accessible through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * iterator. If the list is null, all available attribute information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * should be made accessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param attributes a list of attributes that the input method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * interested in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return the currently selected text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    AttributedCharacterIterator getSelectedText(Attribute[] attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
}