nativeinputmode.jpp

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

JPP
447
字号
/* *   * * Copyright  1990-2007 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 com.sun.midp.chameleon.input;import javax.microedition.lcdui.Displayable;/** */public class NativeInputMode implements InputMode {    /** this index selects in the function state data array     *  the integer result returned from an interface function */    private final int STATE_CALLBACK_RES = 0;    /** this index selects in the function state data array     *  the integer id of interface function to be called */    private final int STATE_FUNC_TOKEN = 1;    /** this index selects in the function state data array     *  the integer id of the next state to be entered */    private final int STATE_NEXT_STATE = 2;    /** this index selects in the function state data array     *  the integer argument for an interface function */    private final int STATE_INT_ARG = 3;    /** this index selects in the function state data array     *  the value to be returned as a result of the enclosing Java function */    private final int STATE_FINAL_RES = 4;    /** this index selects in the function state data array     *  the value to be internally used by native function */    private final int STATE_INTERNAL = 5;    /** this index selects in the function state data array     *  the value to be internally used by native function */    private final int STATE_INTERNAL_EXT = 6;    /** the number of integer elements in the function state data array */    private final int STATE_DATA_ARRAY_SIZE = 7;    /** this value, when stored as stateArgs[STATE_FUNC_TOKEN],     *  tells the executeMediatorCommand function     * to perform no action with the mediator */    private final int MEDIATOR_NOOP = 0;    /** this value, when stored as stateArgs[STATE_FUNC_TOKEN],     *  tells the executeMediatorCommand function     * to perform the mediator.commit(String) function */    private final int MEDIATOR_COMMIT = 1;    /** this value, when stored as stateArgs[STATE_FUNC_TOKEN],     *  tells the executeMediatorCommand function     * to perform the mediator.clear(int) function */    private final int MEDIATOR_CLEAR = 2;    /** this value, when stored as stateArgs[STATE_FUNC_TOKEN],     *  tells the executeMediatorCommand function     * to perform the mediator.subInputModeChanged() function */    private final int MEDIATOR_SUBINPUTMODECHANGED = 3;    /** this value, when stored as stateArgs[STATE_FUNC_TOKEN],     *  tells the executeMediatorCommand function     * to perform the mediator.inputModeCompleted() function */    private final int MEDIATOR_INPUTMODECOMPLETED = 4;    /** this value, when stored as stateArgs[STATE_FUNC_TOKEN],     *  tells the executeMediatorCommand function     * to perform the mediator.isClearKey(int) function */    private final int MEDIATOR_ISCLEARKEY = 5;    /** this value, when stored as stateArgs[STATE_FUNC_TOKEN],     *  tells the executeMediatorCommand function     * to perform the mediator.getAvailableSize() function */    private final int MEDIATOR_GETAVAILABLESIZE = 6;    /** this value, when stored as stateArgs[STATE_FUNC_TOKEN],     *  tells the executeMediatorCommand function     * to perform the mediator.isNewlineKey(int) function */    private final static int MEDIATOR_ISNEWLINEKEY = 7;    /** constructor; the real initialization is done     * in the initialize(int) function */    public NativeInputMode() {    }    /**     * Initialize the instance.     *     * @param theId the value to be stored as id     * @return error code, 0 if ok     */    public native int initialize(int theId);    /**     * Finalizer. Free the data structures allocated in initialize(int).     */// #ifdef ENABLE_CDC    protected native void finalize();// #else    private native void finalize();// #endif    /**     * Input method identifier. For a given platform, this class may     * support multiple input methods, and id determines which one is     * supported by this particular instance.     */    public int id;    /** reserved for instance data */    protected int instanceData;     /** The InputModeMediator for the current input session */    protected InputModeMediator mediator;    /**     * This method is called to determine if this InputMode supports     * the given text input constraints. The semantics of the constraints     * value are defined in the javax.microedition.lcdui.TextField API.      * If this InputMode returns false, this InputMode must not be used     * to process key input for the selected text component.     *     * @param constraints text input constraints. The semantics of the      * constraints value are defined in the TextField API.     *     * @return true if this InputMode supports the given text component     *         constraints, as defined in the MIDP TextField API     */    public native boolean supportsConstraints(int constraints);        /**     * Returns the display name which will represent this InputMode to      * the user, such as in a selection list or the softbutton bar.     *     * @return the locale-appropriate name to represent this InputMode     *         to the user     */    public native String getName();    /**     * Returns the command name which will represent this InputMode in     * the input menu     *     * @return the locale-appropriate name to represent this InputMode     *         to the user     */    public native String getCommandName();        /**     * This method will be called before any input keys are passed     * to this InputMode to allow the InputMode to perform any needed     * initialization. A reference to the InputModeMediator which is     * currently managing the relationship between this InputMode and     * the input session is passed in. This reference can be used     * by this InputMode to commit text input as well as end the input     * session with this InputMode. The reference is only valid until     * this InputMode's endInput() method is called.     *     * @param constraints text input constraints. The semantics of the      * constraints value are defined in the TextField API.     *     * @param theMediator the InputModeMediator which is negotiating the     *        relationship between this InputMode and the input session     *     * @param inputSubset current input subset     */    public void beginInput(InputModeMediator theMediator, String inputSubset,                           int constraints)         throws IllegalStateException {        mediator = theMediator;        beginInput0(theMediator, inputSubset, constraints);    }    public native void beginInput0(InputModeMediator theMediator, String inputSubset,                           int constraints);    /**     * Process the given key code as input.     *      * This method will return true if the key was processed successfully,     * false otherwise.     *     * @param keyCode the keycode of the key which was input     * @param longPress return true if it's long key press otherwise false     * @return true if the key was processed by this InputMode, false     *         otherwise.     */    public int processKey(int keyCode, boolean longPress)        throws IllegalStateException {        int iterationCount = 0;        final int maxIterations = 32767;        final int clearKeyFlag =            mediator == null ? -1 :            mediator.isClearKey(keyCode) ? 1 : 0;        int[] stateArgs = new int[STATE_DATA_ARRAY_SIZE];        String stringArg;        do {            if (iterationCount++ > maxIterations) {                throw new RuntimeException("too many iterations inside processKey()");            }            stringArg = processKey0(keyCode, longPress, clearKeyFlag,stateArgs);            executeMediatorCommand(stateArgs, stringArg);        } while (0 != stateArgs[STATE_NEXT_STATE]);        if (0 != stateArgs[STATE_INTERNAL]         || 0 != stateArgs[STATE_INTERNAL_EXT]) {            // If we are here,            // the programmer has either forgot to free memory,            // or has not modified the next_state number.            throw new RuntimeException("the internal state parameter "                                        +"record have not been released");        }        return stateArgs[STATE_FINAL_RES];    }    /**

⌨️ 快捷键说明

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