inputmethodevent.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 411 行 · 第 1/2 页

JAVA
411
字号
/* * @(#)InputMethodEvent.java	1.23 04/06/14 * * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation.  *  * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt).  *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA  *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions.  */package java.awt.event;import java.awt.AWTEvent;import java.awt.Component;import java.awt.EventQueue;import java.awt.font.TextHitInfo;//import com.sun.java.swing.font.TextHitInfo;import java.io.IOException;import java.io.ObjectInputStream;import java.lang.Integer;import java.text.AttributedCharacterIterator;import java.text.CharacterIterator;/** * Input method events contain information about text that is being * composed using an input method. Whenever the text changes, the * input method sends an event. If the text component that's currently * using the input method is an active client, the event is dispatched * to that component. Otherwise, it is dispatched to a separate * composition window. * * <p> * The text included with the input method event consists of two parts: * committed text and composed text. Either part may be empty. The two * parts together replace any uncommitted composed text sent in previous events, * or the currently selected committed text. * Committed text should be integrated into the text component's persistent * data, it will not be sent again. Composed text may be sent repeatedly, * with changes to reflect the user's editing operations. Committed text * always precedes composed text. * * @author JavaSoft Asia/Pacific * @version 1.23 06/14/04 * @since 1.2 */public class InputMethodEvent extends AWTEvent {    /**     * Serial Version ID.     */    private static final long serialVersionUID = 4727190874778922661L;    /**     * Marks the first integer id for the range of input method event ids.     */    public static final int INPUT_METHOD_FIRST = 1100;    /**     * The event type indicating changed input method text. This event is     * generated by input methods while processing input.     */    public static final int INPUT_METHOD_TEXT_CHANGED = INPUT_METHOD_FIRST;    /**     * The event type indicating a changed insertion point in input method text.     * This event is     * generated by input methods while processing input if only the caret changed.     */    public static final int CARET_POSITION_CHANGED = INPUT_METHOD_FIRST + 1;    /**     * Marks the last integer id for the range of input method event ids.     */    public static final int INPUT_METHOD_LAST = INPUT_METHOD_FIRST + 1;    /**     * The time stamp that indicates when the event was created.     *     * @serial     * @see #getWhen     * @since 1.4     */    long when;    // Text object    private transient AttributedCharacterIterator text;    private transient int committedCharacterCount;    private transient TextHitInfo caret;    private transient TextHitInfo visiblePosition;    /**     * Constructs an <code>InputMethodEvent</code> with the specified     * source component, type, time, text, caret, and visiblePosition.     * <p>     * The offsets of caret and visiblePosition are relative to the current     * composed text; that is, the composed text within <code>text</code>     * if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,     * the composed text within the <code>text</code> of the     * preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.     *     * @param source the object where the event originated     * @param id the event type     * @param when a long integer that specifies the time the event occurred     * @param text the combined committed and composed text,     *      committed text first; must be <code>null</code>     *      when the event type is <code>CARET_POSITION_CHANGED</code>;     *      may be <code>null</code> for     *      <code>INPUT_METHOD_TEXT_CHANGED</code> if there's no     *      committed or composed text     * @param committedCharacterCount the number of committed     *      characters in the text     * @param caret the caret (a.k.a. insertion point);     *      <code>null</code> if there's no caret within current     *      composed text     * @param visiblePosition the position that's most important     *      to be visible; <code>null</code> if there's no     *      recommendation for a visible position within current     *      composed text     * @exception IllegalArgumentException if <code>id</code> is not     *      in the range     *      <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>;     *      or if id is <code>CARET_POSITION_CHANGED</code> and     *      <code>text</code> is not <code>null</code>;     *      or if <code>committedCharacterCount</code> is not in the range     *      <code>0</code>..<code>(text.getEndIndex() - text.getBeginIndex())</code>     *     * @since 1.4     */    public InputMethodEvent(Component source, int id, long when,                            AttributedCharacterIterator text,                             int committedCharacterCount,                            TextHitInfo caret, TextHitInfo visiblePosition ) {        super(source, id);        if (id < INPUT_METHOD_FIRST || id > INPUT_METHOD_LAST) {            throw new IllegalArgumentException("id outside of valid range");        }        if (id == CARET_POSITION_CHANGED && text != null) {            throw new IllegalArgumentException("text must be null for CARET_POSITION_CHANGED");        }	this.when = when;        this.text = text;        int textLength = 0;        if (text != null) {            textLength = text.getEndIndex() - text.getBeginIndex();        }        if (committedCharacterCount < 0 || committedCharacterCount > textLength) {            throw new IllegalArgumentException("committedCharacterCount outside of valid range");        }        this.committedCharacterCount = committedCharacterCount;        this.caret = caret;        this.visiblePosition = visiblePosition;   }    /**     * Constructs an <code>InputMethodEvent</code> with the specified     * source component, type, text, caret, and visiblePosition.     * <p>     * The offsets of caret and visiblePosition are relative to the current     * composed text; that is, the composed text within <code>text</code>     * if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,     * the composed text within the <code>text</code> of the     * preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.     * The time stamp for this event is initialized by invoking     * {@link java.awt.EventQueue#getMostRecentEventTime()}.     *     * @param source the object where the event originated     * @param id the event type     * @param text the combined committed and composed text,     *      committed text first; must be <code>null</code>     *      when the event type is <code>CARET_POSITION_CHANGED</code>;     *      may be <code>null</code> for     *      <code>INPUT_METHOD_TEXT_CHANGED</code> if there's no     *      committed or composed text     * @param committedCharacterCount the number of committed     *      characters in the text     * @param caret the caret (a.k.a. insertion point);     *      <code>null</code> if there's no caret within current     *      composed text     * @param visiblePosition the position that's most important     *      to be visible; <code>null</code> if there's no     *      recommendation for a visible position within current     *      composed text     * @exception IllegalArgumentException if <code>id</code> is not     *      in the range     *      <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?