| 1 | /* InputMethodRequests.java -- handles text insertion via input methods
|
|---|
| 2 | Copyright (C) 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 | package java.awt.im;
|
|---|
| 39 |
|
|---|
| 40 | import java.awt.Rectangle;
|
|---|
| 41 | import java.awt.font.TextHitInfo;
|
|---|
| 42 | import java.text.AttributedCharacterIterator;
|
|---|
| 43 | import java.text.AttributedCharacterIterator.Attribute;
|
|---|
| 44 |
|
|---|
| 45 | /**
|
|---|
| 46 | * This interface handles requests made by input methods on text editing
|
|---|
| 47 | * components. A component must specify a handler for input methods that
|
|---|
| 48 | * implements this interface, and which supports one of two user interfaces:
|
|---|
| 49 | * <ul><li><em>on-the-spot</em>: composed text is shown in place</li>
|
|---|
| 50 | * <li><em>below-the-spot</em>: composed text is in a separate window,
|
|---|
| 51 | * usually below the main text window, until it is committed into place at
|
|---|
| 52 | * the insertion point, overwriting any selected text</li></ul>
|
|---|
| 53 | *
|
|---|
| 54 | * @author Eric Blake <[email protected]>
|
|---|
| 55 | * @see Component#getInputMethodRequests()
|
|---|
| 56 | * @see InputMethodListener
|
|---|
| 57 | * @since 1.2
|
|---|
| 58 | * @status updated to 1.4
|
|---|
| 59 | */
|
|---|
| 60 | public interface InputMethodRequests
|
|---|
| 61 | {
|
|---|
| 62 | /**
|
|---|
| 63 | * Gets the location of a given offset of the text. This can be used to
|
|---|
| 64 | * position a composition window near the location of where the composed
|
|---|
| 65 | * text will be inserted.
|
|---|
| 66 | *
|
|---|
| 67 | * <p>If the component has composed text (from the most recent
|
|---|
| 68 | * InputMethodEvent), then offset 0 indicates the location of the first
|
|---|
| 69 | * character of this composed text. Otherwise, the offset is ignored, and
|
|---|
| 70 | * the location should be the beginning of the final line of selected
|
|---|
| 71 | * text (in horizontal left-to-right text, like English, this would be the
|
|---|
| 72 | * lower left corner of the selction; in vertical top-to-bottom text, like
|
|---|
| 73 | * Chinese, this would be the top right corner of the selection).
|
|---|
| 74 | *
|
|---|
| 75 | * <p>The location returned is a 0-thickness caret (either horizontal or
|
|---|
| 76 | * vertical, depending on text flow), mapped to absolute screen coordinates.
|
|---|
| 77 | *
|
|---|
| 78 | * @param offset offset within composed text, or null
|
|---|
| 79 | * @return the screen location of the caret at the offset
|
|---|
| 80 | */
|
|---|
| 81 | Rectangle getTextLocation(TextHitInfo offset);
|
|---|
| 82 |
|
|---|
| 83 | /**
|
|---|
| 84 | * Get the text offset for the given screen coordinate. The offset is
|
|---|
| 85 | * relative to the composed text, and the return is null if it is outside
|
|---|
| 86 | * the range of composed text. For example, this can be used to find
|
|---|
| 87 | * where a mouse click should pop up a text composition window.
|
|---|
| 88 | *
|
|---|
| 89 | * @param x the x screen coordinate
|
|---|
| 90 | * @param y the y screen coordinate
|
|---|
| 91 | * @return a text hit info describing the composed text offset
|
|---|
| 92 | */
|
|---|
| 93 | TextHitInfo getLocationOffset(int x, int y);
|
|---|
| 94 |
|
|---|
| 95 | /**
|
|---|
| 96 | * Gets the offset where the committed text exists in the text editing
|
|---|
| 97 | * component. This can be used to examine the text surrounding the insert
|
|---|
| 98 | * position.
|
|---|
| 99 | *
|
|---|
| 100 | * @return the offset of the insert position
|
|---|
| 101 | */
|
|---|
| 102 | int getInsertPositionOffset();
|
|---|
| 103 |
|
|---|
| 104 | /**
|
|---|
| 105 | * Gets an interator which provides access to the text and its attributes,
|
|---|
| 106 | * except for the uncommitted text. The input method may provide a list of
|
|---|
| 107 | * attributes it is interested in; and the iterator need not provide
|
|---|
| 108 | * information on the remaining attributes. If the attribute list is null,
|
|---|
| 109 | * the iterator must list all attributes.
|
|---|
| 110 | *
|
|---|
| 111 | * @param beginIndex the index of the first character in the iteration
|
|---|
| 112 | * @param endIndex the index of the last character in the iteration
|
|---|
| 113 | * @param attributes a list of attributes interested in, or null
|
|---|
| 114 | * @return an iterator over the region of text with its attributes
|
|---|
| 115 | */
|
|---|
| 116 | AttributedCharacterIterator getCommittedText(int beginIndex, int endIndex,
|
|---|
| 117 | Attribute[] attributes);
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | * Gets the length of committed text.
|
|---|
| 121 | *
|
|---|
| 122 | * @return the number of committed characters
|
|---|
| 123 | */
|
|---|
| 124 | int getCommittedTextLength();
|
|---|
| 125 |
|
|---|
| 126 | /**
|
|---|
| 127 | * Gets the latest committed text, and removes it from the component's text
|
|---|
| 128 | * body. This allows an input method to provide an "Undo" command. In
|
|---|
| 129 | * general, this should only be supported immediately after a commit, and
|
|---|
| 130 | * not when other actions intervene; if not supported, simply return null.
|
|---|
| 131 | * The input method may provide a list of attributes it is interested in;
|
|---|
| 132 | * and the iterator need not provide information on the remaining attributes.
|
|---|
| 133 | * If the attribute list is null, the iterator must list all attributes.
|
|---|
| 134 | *
|
|---|
| 135 | * @param attributes a list of attributes interested in, or null
|
|---|
| 136 | * @return the latest committed text, or null
|
|---|
| 137 | */
|
|---|
| 138 | AttributedCharacterIterator cancelLatestCommittedText
|
|---|
| 139 | (Attribute[] attributes);
|
|---|
| 140 |
|
|---|
| 141 | /**
|
|---|
| 142 | * Gets the currently selected text. One use of this is to implement a
|
|---|
| 143 | * "Reconvert" feature in an input method, which modifies the selection
|
|---|
| 144 | * based on the text in the composition window. The input method may
|
|---|
| 145 | * provide a list of attributes it is interested in; and the iterator need
|
|---|
| 146 | * not provide information on the remaining attributes. If the attribute
|
|---|
| 147 | * list is null, the iterator must list all attributes.
|
|---|
| 148 | *
|
|---|
| 149 | * @param attributes a list of attributes interested in, or null
|
|---|
| 150 | * @return the current selection
|
|---|
| 151 | */
|
|---|
| 152 | AttributedCharacterIterator getSelectedText(Attribute[] attributes);
|
|---|
| 153 | } // interface InputMethodRequests
|
|---|