basicinputmode.java

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

JAVA
686
字号
     * @return next key code      */     protected int getNextChar() {        pendingChar = KEYCODE_NONE;        return getPendingCharInternal();    }        /**     * Return the next possible match for the key input processed thus     * far by this InputMode. A call to this method should be preceeded     * by a check of hasMoreMatches(). If the InputMode has more available     * matches for the given input, this method will return them one by one.     *     * @return a String representing the next available match to the key      *         input thus far, or 'null' if no pending input is available     */    public String getNextMatch() {        String value = null;        int ch = getNextChar();        if (ch != KEYCODE_NONE) {            value = String.valueOf((char)ch);        }        hasMoreMatches = false;        return value;    }    /**     * True, if after processing a key, there is more than one possible     * match to the input. If this method returns true, the getNextMatch()     * method can be called to return the value.     *     * @return true if after processing a key, there is more than the one     *         possible match to the given input     */    public boolean hasMoreMatches() {        return hasMoreMatches;    }    /**     * Gets the possible string matches      *     * @return returns the set of options.     */    public String[] getMatchList() {        //   String[] value = null;        //   int ch = getPendingCharInternal();                //   if (ch != KEYCODE_NONE) {        //      value = new String[1];        //      value[0] = String.valueOf((char)ch);        //   } else {        //      value = new String[0];        //   }        //   return value;        //                 return new String[0];    }                /**     * Mark the end of this InputMode's processing. The only possible call     * to this InputMode after a call to endInput() is a call to beginInput()     * to begin a new input session.     */    public void endInput() {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,                "[basic.endInput]");        }        validateState(true);        this.mediator = null;        clickCount = 0;        lastKey = -1;        stopTimer();    }            /**     * By default the regular input method has no specific displayable     * representation so it returns null.       * @return null by default      */    public Displayable getDisplayable() {        return null;    }    /**     * Implementation of a timer routine which will attempt to commit     * a pending character after a certain timeout (depending on the     * state of the commitChar boolean).     */    public void run() {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,                "[run] sessionIsLive=" + sessionIsLive + " commitChar=" + commitChar);        }        // We initially block until the first key press is processed        if (!sessionIsLive) {            try {                synchronized (this) {                    wait();                }            } catch (Throwable t) {            } // ignore interruptions        }        while (sessionIsLive) {            try {                synchronized (this) {                    // Just before we start the timeout we set the                    // commit flag to true. If it doesn't get reset                    // to false by the processKey method, we will                    // commit the pending key when we wake up                    commitChar = true;                    wait(KEY_COMMIT_TIMEOUT);                }            } catch (Throwable t) {            } // ignore any exceptions here            if (sessionIsLive && commitChar) {                completeInputMode(true);            }        }    }        /**     * This method will validate the state of this InputMode. If this     * is a check for an "active" operation, the TextInputMediator must     * be non-null or else this method will throw an IllegalStateException.     * If this is a check for an "inactive" operation, then the     * TextInputMediator should be null.     * @param activeOperation true if any operation is active otherwise false.     */    protected void validateState(boolean activeOperation) {        if (activeOperation && this.mediator == null) {            throw new IllegalStateException(            "Illegal operation on an input session already in progress");        } else if (!activeOperation && this.mediator != null) {            throw new IllegalStateException(            "Illegal operation on an input session which is not in progress");        }    }        /**     * return the pending char for internal use      *     * @return return the pending char     */    public int getPendingCharInternal() {        if (pendingChar == KEYCODE_NONE) {            char[] chars = null;            char c;            // log("[basic.getPendingCharInternal] lastKey=" + lastKey);            if (lastKey == -1 || clickCount <= 0) {                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,                        "[getPendingCharInternal] returning KEYCODE_NONE");                }            } else {                chars = getCharOptions(lastKey);                if (chars == null) {                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {                        Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,                            "[getPendingCharInternal] returning KEYCODE_NONE");                    }                } else {                    if (clickCount > chars.length) {                        clickCount = 1;                    }                    if (chars.length > 0) {                        pendingChar = chars[clickCount - 1];                    }                    hasMoreMatches = true;                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {                        Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,                            "[getPendingCharInternal] returning " + pendingChar);                    }                }            }        }        return pendingChar;    }    /**     * Check if only one char option exists for the key code     * @param keyCode key code     * @return true if only one char option exists otherwise false.      */    private boolean hasOneCase(int keyCode) {        boolean ret = false;        if (keyCode != -1) {            char[] options = getCharOptions(keyCode);            ret = (options == null) || options.length <= 1;        }        return ret;    }            /**     * return the pending char     * used to bypass the asynchronous commit mechanism     * e.g. to immediately commit a char before moving the cursor     *     * @return return the pending char     */    public char getPendingChar() {        int code = getPendingCharInternal();        char c = code == KEYCODE_NONE ? 0 : (char) code;        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,                "[getPendingChar] returning " + c);        }        return c;    }    /**     * Gets the possible matches for the key code     *     * @param lastKey the key code     *     * @return returns the set of options. Return null if matches are not found.     */    protected abstract char[] getCharOptions(int lastKey);              /**     * This method is used to immediately commit the pending     * character because a new character is now pending.     *     * @return true if char has been committed otherwise false     */    protected boolean commitPendingChar() {        boolean committed = false;        int c = getPendingCharInternal();        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,                "[commitPendingChar] getPendingChar=" + c);        }        if (c != KEYCODE_NONE) {            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {                Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,                    "[commitPendingChar] commiting " + String.valueOf((char) c));            }            committed = true;            mediator.commit(String.valueOf((char) c));        }        lastKey = -1;        clickCount = 0;        pendingChar = KEYCODE_NONE;        return committed;    }        /**     * This method is used to immediately commit the given     * string and then call the TextInputMediator's inputModeCompleted()     * method     * @param commit true if the char is accepted, false if the char is rejected     */    protected void completeInputMode(boolean commit) {        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,                "[Basic.completeInputMode] commit = " + commit);        }        if (commit) {            commitPendingChar();        }        clickCount = 0;        lastKey = -1;        stopTimer();        startTimer();    }    /**      * Notify about current input subset     * @param inputSubset current input subset     */    protected void setInputSubset(String inputSubset) {    }    /**     * 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     */    abstract public 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     */    abstract public 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     */    abstract public String getCommandName();        /**     * Returns the map specifying this input mode is proper one for the     * particular pair of input subset and constraint. The form of the map is     *     *                       |ANY|EMAILADDR|NUMERIC|PHONENUMBER|URL|DECIMAL|     * ---------------------------------------------------------------------     * IS_FULLWIDTH_DIGITS   |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * IS_FULLWIDTH_LATIN    |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * IS_HALFWIDTH_KATAKANA |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * IS_HANJA              |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * IS_KANJI              |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * IS_LATIN              |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * IS_LATIN_DIGITS       |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * IS_SIMPLIFIED_HANZI   |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * IS_TRADITIONAL_HANZI  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * MIDP_UPPERCASE_LATIN  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * MIDP_LOWERCASE_LATIN  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     * NULL                  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |     *     * @return input subset x constraint map     */    abstract public boolean[][] getIsConstraintsMap();}

⌨️ 快捷键说明

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