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

📄 textfield.java.svn-base

📁 j2me设计的界面包
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
        defaultInputModeOrder = order;    }        /**     * Used for the case of first sentence character should be upper case     */    private String pickLowerOrUpper(String inputMode) {        // check the character before the cursor..        int pos = cursorCharPosition - 1;        // we have input which has moved the cursor position further        if(pendingCommit) {            pos--;        }        String text = getText();        if(pos >= text.length()) {            pos = text.length() - 1;        }        while(pos > -1) {            if(text.charAt(pos) == '.') {                return inputMode.toUpperCase();            }            if(text.charAt(pos) != ' ') {                return inputMode.toLowerCase();            }            pos--;        }        return inputMode.toUpperCase();    }        /**     * Returns the input mode for the ong click mode     *      * @return returns 123 by default     */    protected String getLongClickInputMode() {        return "123";    }        /**     * Returns the character matching the given key code after the given amount     * of user presses     *      * @param pressCount number of times this keycode was pressed     * @param keyCode the actual keycode input by the user     * @param longClick does this click constitute a long click     * @return the char mapping to this key or 0 if no appropriate char was found      * (navigation, input mode change etc...).     */    protected char getCharPerKeyCode(int pressCount, int keyCode, boolean longClick) {        initInputModes();        String input = inputMode;                // if this is a first letter uppercase input mode then we need to pick either        // the upper case mode or the lower case mode...        if(longClick) {            input = getLongClickInputMode();        } else {            if(firstUppercaseInputMode.contains(input)) {                input = pickLowerOrUpper(input);            }        }                Hashtable mode = (Hashtable)inputModes.get(input);        String s = (String)mode.get(new Integer(keyCode));        if(s != null) {            pressCount = pressCount % s.length();            return s.charAt(pressCount);        }        return 0;    }        /**     * Blocks the text area from opening the native text box editing on touchscreen click     */    void onClick() {    }    /**     * Set the position of the cursor     */    public void setCursorPosition(int pos) {        if(pos < -1 || pos > getText().length()) {            throw new IllegalArgumentException("Illegal cursor position: " + pos);        }        cursorCharPosition = pos;    }        /**     * Returns the position of the cursor     */    public int getCursorPosition() {        if(getText() == null) {            return 0;        }        return Math.min(getText().length(), cursorCharPosition);    }        /**     * @inheritDoc     */    public void setText(String text) {        super.setText(text);        fireDataChanged(DataChangedListener.CHANGED, -1);        if(cursorCharPosition < 0) {            cursorCharPosition = text.length();        } else {            if(cursorCharPosition > text.length()) {                cursorCharPosition = text.length();            }        }    }            /**     * Invoked on a long click by the user     */    private void longClick(int keyCode) {        longClick = true;        keyReleaseOrLongClick(keyCode, true);    }    /**     * Returns true if this is the clear key on the device, many devices don't contain     * a clear key and even in those that contain it this might be an issue     *      * @param keyCode the key code that might be the clear key     * @return true if this is the clear key.     */    protected boolean isClearKey(int keyCode) {        return keyCode == Form.clearSK;    }        /**     * True is this is a qwerty device or a device that is currently in     * qwerty mode.     *      * @return currently defaults to false     */    public boolean isQwertyInput() {        return qwerty;    }    /**     * True is this is a qwerty device or a device that is currently in     * qwerty mode.     */    public void setQwertyInput(boolean qwerty) {        this.qwerty = qwerty;    }        private boolean keyReleaseOrLongClick(int keyCode, boolean longClick) {        // user pressed a different key, autocommit everything        if(lastKeyCode != keyCode && pendingCommit) {            commitChange();        }        lastKeyCode = keyCode;                if(isQwertyInput()) {            if(keyCode > 0) {                String text;                if(previousText == null) {                    previousText = getText();                }                if(cursorCharPosition < 0) {                    cursorCharPosition = 0;                }                cursorCharPosition++;                text = previousText.substring(0, cursorCharPosition - 1) + ((char)keyCode) +                     previousText.substring(cursorCharPosition - 1, previousText.length());                super.setText(text);                commitChange();                fireDataChanged(DataChangedListener.ADDED, cursorCharPosition);                return true;            }        } else {            char c = getCharPerKeyCode(pressCount, keyCode, longClick);            cursorCharPosition = Math.max(cursorCharPosition, 0);            if (c != 0) {                String text;                if(previousText == null) {                    previousText = getText();                }                if(!pendingCommit) {                    cursorCharPosition++;                }                text = previousText.substring(0, cursorCharPosition - 1) + c +                     previousText.substring(cursorCharPosition - 1, previousText.length());                pendingCommit = true;                pressCount++;                super.setText(text);                if(inputMode.equals("123")) {                    commitChange();                    fireDataChanged(DataChangedListener.ADDED, cursorCharPosition);                } else {                    if(pressCount == 1) {                        fireDataChanged(DataChangedListener.ADDED, cursorCharPosition);                    } else {                        fireDataChanged(DataChangedListener.CHANGED, cursorCharPosition);                    }                }                return true;            }        }        int game = Display.getInstance().getGameAction(keyCode);        if(game == Display.GAME_RIGHT) {            cursorCharPosition++;            if(cursorCharPosition > getText().length()) {                if(isCursorPositionCycle()) {                    cursorCharPosition = 0;                } else {                    cursorCharPosition = getText().length();                }            }            repaint();            return true;        } else {            if(game == Display.GAME_LEFT) {                cursorCharPosition--;                if(cursorCharPosition < 0) {                    if(isCursorPositionCycle()) {                        cursorCharPosition = getText().length();                    } else {                        cursorCharPosition = 0;                    }                }                repaint();                return true;            }        }        if(isChangeInputMode(keyCode)) {            for(int iter = 0 ; iter < inputModeOrder.length ; iter++) {                if(inputModeOrder[iter].equals(inputMode)) {                    iter++;                    if(iter < inputModeOrder.length) {                        setInputMode(inputModeOrder[iter]);                    } else {                        setInputMode(inputModeOrder[0]);                    }                    return true;                }            }            return true;        }        if(isClearKey(keyCode)) {            deleteChar();            return true;        }        if(isSymbolDialogKey(keyCode)) {            ActionListener listener = new ActionListener() {                public void actionPerformed(ActionEvent evt) {                    String text = ((Button)evt.getSource()).getText();                    String currentText = getText();                    cursorCharPosition++;                    setText(currentText.substring(0, cursorCharPosition - 1) + text +                         currentText.substring(cursorCharPosition - 1, currentText.length()));                    fireDataChanged(DataChangedListener.ADDED, cursorCharPosition);                    Display.getInstance().getCurrent().dispose();                }            };            char[] symbolArray = getSymbolTable();            Container symbols = new Container(new GridLayout(symbolArray.length / 5, 5));            for(int iter = 0 ; iter < symbolArray.length ; iter++) {                Button button = new Button("" + symbolArray[iter]);                button.setAlignment(CENTER);                button.addActionListener(listener);                symbols.addComponent(button);            }            Command cancel = new Command("Cancel");            Dialog.show(null, symbols, new Command[] {cancel});            return true;        }        return false;    }        /**     * @inheritDoc     */    public void keyReleased(int keyCode) {        pressedAndNotReleased = false;        releaseTime = System.currentTimeMillis();        if(!longClick) {            if(keyReleaseOrLongClick(keyCode, false)) {                return;            }        }        longClick = false;        super.keyReleased(keyCode);    }        /**     * The amount of time considered as a "long click" causing the long click method     * to be invoked.     *      * @return currently defaults to 800     */    protected int getLongClickDuration() {        return 800;    }        /**     * Returns the symbol table for the device     */    public static char[] getSymbolTable() {        return symbolTable;    }    /**     * Sets the symbol table to show when the user clicks the symbol table key     */    public static void setSymbolTable(char[] table) {        symbolTable = table;;    }        /**     * Returns true if the cursor should cycle to the begining of the text when the     * user navigates beyond the edge of the text and visa versa.     * @return true by default     */    protected boolean isCursorPositionCycle() {        return true;    }        /**     * Returns true if this keycode is the one mapping to the symbol dialog popup     * 

⌨️ 快捷键说明

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