⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultinputmethodhandler.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * @(#)DefaultInputMethodHandler.java	1.75 02/09/17 @(#) * * Copyright (c) 2000-2002 Sun Microsystems, Inc.  All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */package com.sun.midp.lcdui;import java.util.Vector;import java.util.TimerTask;import java.util.Timer;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.TextField;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Font;import javax.microedition.lcdui.Form;/** * A Default implementation of the InputMethodHandler interface. */public class DefaultInputMethodHandler extends InputMethodHandler {    /** the client that receives callbacks */    protected InputMethodClient imc = null;    /*     * IDs for supported input modes     */    /** The 'none' input mode. */    protected static final int IM_NONE         = 0;    /** The 'roman caps' input mode. */    protected static final int IM_ROMAN_CAPS   = 1;    /** The 'lowercase roman' input mode. */    protected static final int IM_ROMAN_SMALL  = 2;    /** The 'numeric' input mode. */    protected static final int IM_NUMERIC      = 3;    /** The 'symbol' input mode. */    protected static final int IM_SYMBOL       = 4;    /** Number of supported input modes. */    protected static int NUM_INPUT_MODES = 5;    /** the constraints in use */    protected int currentConstraints;    /** the modifiers in use */    protected int currentModifiers;    /**     * Default input mode.     */    protected int defaultMode;    /**     * The number of allowed input modes.     */    protected int allowedModesNum;    /**     * The set of allowed input modes.     */    protected int allowedModes[] = new int[NUM_INPUT_MODES];    /**     * Current input mode.     */    protected int inputMode;    /**     * Old input mode.     */    protected int oldInputMode;    /**     * boolean to determine if the user had accessed the symbol table     * via the quick access method of holding SHIFT     */    protected boolean quickSymbolAccess = false;    /**     * Constraints allow a symbol table to be used     */    protected boolean canUseSymbolTable = true;    /**     * This is the "last" input mode before jumping into the SYM mode     * (by holding down the mode shift key for 1 sec). This last mode      * tells the input method to switch back to this mode after handling     * an character from the symbol table.     */    protected int lastInputMode;    /**     * Character Subset values for supported input modes.     */    protected String supportedCharSubset[] = {        "UCB_BASIC_LATIN",        "IS_LATIN",        "IS_LATIN_DIGITS",        "MIDP_UPPERCASE_LATIN",        "MIDP_LOWERCASE_LATIN",        "LATIN",        "LATIN_DIGITS",    };    /**     * values for supported input modes.     */    protected int supportedInputModes[] = {        IM_ROMAN_CAPS,        IM_ROMAN_SMALL,        IM_NUMERIC,        IM_SYMBOL,    };    /**     * Conversion table between character subsets and input modes.     */    protected Object inputModeConvTable[][] = {        {"UCB_BASIC_LATIN",      new Integer(IM_ROMAN_CAPS)},        {"UCB_BASIC_LATIN",      new Integer(IM_ROMAN_SMALL)},        {"UCB_BASIC_LATIN",      new Integer(IM_NUMERIC)},        {"UCB_BASIC_LATIN",      new Integer(IM_SYMBOL)},        {"IS_LATIN",             new Integer(IM_ROMAN_CAPS)},        {"IS_LATIN",             new Integer(IM_ROMAN_SMALL)},        {"IS_LATIN",             new Integer(IM_NUMERIC)},        {"IS_LATIN",             new Integer(IM_SYMBOL)},        {"IS_LATIN_DIGITS",      new Integer(IM_NUMERIC)},        {"MIDP_UPPERCASE_LATIN", new Integer(IM_ROMAN_CAPS)},        {"MIDP_LOWERCASE_LATIN", new Integer(IM_ROMAN_SMALL)},        {"LATIN",                new Integer(IM_ROMAN_CAPS)},        {"LATIN",                new Integer(IM_ROMAN_SMALL)},        {"LATIN_DIGITS",         new Integer(IM_NUMERIC)},        {"LATIN",                new Integer(IM_SYMBOL)},    };    /**     * mode and state variables to support INITIAL_CAPS_WORD/SENTENCE     * Refer to State Transition Diagram in handleCapMode().     */       /** cap word mode variable */    protected boolean capWord;    /** cap sentence mode variable */    protected boolean capSentence;    // Key definition for key maps    /** Unknown key. */    protected static final int KEY_UNKNOWN  = -1;    /** The '0' key. */    protected static final int KEY_NUM0   = 0;    /** The '1' key. */    protected static final int KEY_NUM1   = 1;    /** The '2' key. */    protected static final int KEY_NUM2   = 2;    /** The '3' key. */    protected static final int KEY_NUM3   = 3;    /** The '4' key. */    protected static final int KEY_NUM4   = 4;    /** The '5' key. */    protected static final int KEY_NUM5   = 5;    /** The '6' key. */    protected static final int KEY_NUM6   = 6;    /** The '7' key. */    protected static final int KEY_NUM7   = 7;    /** The '8' key. */    protected static final int KEY_NUM8   = 8;    /** The '9' key. */    protected static final int KEY_NUM9   = 9;    /** The '*' key. */    protected static final int KEY_STAR   = 10;    /** The '#' key. */    protected static final int KEY_POUND  = 11;    /** The 'CLR' key. */    protected static final int KEY_CLEAR  = 100;    /**     * The uppercase roman key map.     */    protected char upperRomanKeyMap[][] = {	{'0'},	{'1'},	{'A', 'B', 'C', '2'},	{'D', 'E', 'F', '3'},	{'G', 'H', 'I', '4'},	{'J', 'K', 'L', '5'},	{'M', 'N', 'O', '6'},	{'P', 'Q', 'R', 'S', '7'},	{'T', 'U', 'V', '8'},	{'W', 'X', 'Y', 'Z', '9'},	{'\0'},	{' '}    };    /**     * The lowercase roman key map.     */    protected char lowerRomanKeyMap[][] = {	{'0'},	{'1'},	{'a', 'b', 'c', '2'},	{'d', 'e', 'f', '3'},	{'g', 'h', 'i', '4'},	{'j', 'k', 'l', '5'},	{'m', 'n', 'o', '6'},	{'p', 'q', 'r', 's', '7'},	{'t', 'u', 'v', '8'},	{'w', 'x', 'y', 'z', '9'},	{'\0'},	{' '}    };    /**     * The numeric key map.     * Includes 0-9, *, and space.     */    protected char numericKeyMap[][] = {	{'0'},         {'1'},         {'2'},         {'3'},         {'4'},         {'5'},	{'6'},         {'7'},         {'8'},         {'9'},	{'*'},	{' '}    };    /**     * The decimal key map.     * Includes 0-9, and period.     */    protected char decimalKeyMap[][] = {        {'0'},         {'1'},         {'2'},         {'3'},         {'4'},         {'5'},        {'6'},         {'7'},         {'8'},         {'9'},        {'.'},        {' '}    };    /**     * The phone numeric key map.     * Includes 0-9, *, #, +.     */    protected char phoneNumericKeyMap[][] = {	{'0'},         {'1'},         {'2'},         {'3'},         {'4'},         {'5'},	{'6'},         {'7'},         {'8'},         {'9'},	{'*'},	{'#', '+'}    };    /**     * The number of symbol_table is designed to be 25 for 5x5 matrix,     * starting the selection at 12.  But if you have more, the total     * must be under 36 for 6x6 matrix.       */    protected char symbolTableChars[] = {        '_',	'$',	'(',	')',	'\\',        '~',	'"',	'\'',	'/',	'&',        '*',	'@',	'.',	'?',	'!',        '#',	'-',	',',	':',	';',        '%',	'=',	'+',	'<',	'>'};    /**     * Symbol table.     */    protected SymbolTable st = new SymbolTable();    /**     * Current input table that can be one of the previous maps.     */    protected char keyMap[][] = upperRomanKeyMap;    /**     * Sets the client that will receive callbacks      *     * @param imc the client to receive callbacks     */    public synchronized void setInputMethodClient(InputMethodClient imc) {        //        // we don't want keys to hang over onto someone else's turf        //        cancelTimer();         ignoreNextKeyRelease = true;        this.imc = imc;        lastKey = KEYCODE_NONE;        lastKeyIndex = KEY_UNKNOWN;        charIndex = 0;        if (imc != null) {            setConstraints(imc.getConstraints());        }    }    /**     * Clears the current input handler if it matches the specified one.     *     * @param imc the client that was set to receive callbacks     * @return true if the current client was cleared, false otherwise     */    public synchronized boolean clearInputMethodClient(InputMethodClient imc) {        if (this.imc == imc) {            //            // send any pending keys to the client before we clear it            //            endComposition(false);            setKeyMap(IM_NONE, currentConstraints);            this.imc = null;            return true;        }        return false;    }    /**     * Translate the given key code to its index in the key map.     *     * @param keyCode The key code of the key pressed     * @return int The index of the given key code in the key map     */    protected int getKeyMapIndex(int keyCode) {        switch (keyCode) {            case Canvas.KEY_NUM0:                return KEY_NUM0;            case Canvas.KEY_NUM1:                return KEY_NUM1;            case Canvas.KEY_NUM2:                return KEY_NUM2;            case Canvas.KEY_NUM3:                return KEY_NUM3;            case Canvas.KEY_NUM4:                return KEY_NUM4;            case Canvas.KEY_NUM5:                return KEY_NUM5;            case Canvas.KEY_NUM6:                return KEY_NUM6;            case Canvas.KEY_NUM7:                return KEY_NUM7;            case Canvas.KEY_NUM8:                return KEY_NUM8;            case Canvas.KEY_NUM9:                return KEY_NUM9;            case Canvas.KEY_STAR:                return KEY_STAR;            case Canvas.KEY_POUND:                return KEY_POUND;            case -8:                return KEY_CLEAR;            default:                return KEY_UNKNOWN;            }    }    /**     * Handle a key pressed event.     * Overrides InputMethodHandler.keyPressed.     *     * @param keyCode The code of the key that was pressed     * @return int Returns the character that was entered according to     *             to the current InputMode and constraints, or -1     *             if the keyCode was not recognized or will be handled     *             with a call back     */    public synchronized int keyPressed(int keyCode) {        cancelTimer();        //        // a new key press means a fresh start so we'll initialize some        // variables before we begin        //        ignoreNextKeyRelease = false;        quickSymbolAccess = false;        int idx = getKeyMapIndex(keyCode);        //        // the user has pressed another key so commit the previous one        //        if (idx != lastKeyIndex) {            endComposition(false);        }        //        // remember this key index for next time        //        lastKeyIndex = idx;        if (idx == KEY_UNKNOWN) {            lastKey = KEYCODE_NONE;            return KEYCODE_NONE;        }        //        // if the user holds the CLEAR key we need to tell the        // input client        //

⌨️ 快捷键说明

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