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

📄 textfield.java

📁 j2me设计的界面包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * @param keyCode the keycode to check     * @return true if this is the star symbol *     */    protected boolean isSymbolDialogKey(int keyCode) {        return keyCode == '*';    }        /**     * @inheritDoc     */    public void keyPressed(int keyCode) {        pressedAndNotReleased = true;        pressedKeyCode = keyCode;        pressTime = System.currentTimeMillis();        if((!handlesInput()) && isEditingTrigger(keyCode)) {            setHandlesInput(true);            if(useSoftkeys) {                T9_COMMAND.setDisposesDialog(false);                DELETE_COMMAND.setDisposesDialog(false);                originalClearCommand = installCommands(DELETE_COMMAND, T9_COMMAND);            }            return;        }        if(handlesInput() && isEditingEndTrigger(keyCode)) {            setHandlesInput(false);            if(useSoftkeys) {                removeCommands(DELETE_COMMAND, T9_COMMAND, originalClearCommand);            }            fireActionEvent();            return;        } else {            if(handlesInput()) {                return;            }        }        super.keyPressed(keyCode);    }        /**     * Installs the clear and t9 commands onto the parent form, this method can     * be overriden to provide device specific placement for these commands     *      * @param clear the clear command     * @param t9 the t9 command     * @return clear command already installed in the form if applicable, none if no     * clear command was installed before or not applicable.     */    protected Command installCommands(Command clear, Command t9) {        Form f = getComponentForm();        Command original = f.getClearCommand();        if(replaceMenu && originalCommands == null) {            originalCommands = new Command[f.getCommandCount()];            for(int iter = 0 ; iter < originalCommands.length ; iter++) {                originalCommands[iter] = f.getCommand(iter);            }            f.removeAllCommands();        }                f.addCommand(clear, 0);        f.addCommand(t9, 0);        f.setClearCommand(clear);        return original;    }        /**     * Removes the clear and t9 commands from the parent form, this method can     * be overriden to provide device specific placement for these commands     *      * @param clear the clear command     * @param t9 the t9 command     * @param originalClear the command originally assigned as the clear command (or null if no command was assigned before)     */    protected void removeCommands(Command clear, Command t9, Command originalClear) {        Form f = getComponentForm();        f.removeCommand(clear);        f.removeCommand(t9);        f.setClearCommand(originalClear);        if(replaceMenu && originalCommands != null) {            for(int iter = originalCommands.length - 1 ; iter >= 0 ; iter--) {                f.addCommand(originalCommands[iter]);            }            originalCommands = null;        }    }        void focusLostInternal() {        if(useSoftkeys) {            Form f = getComponentForm();            if(f != null) {                removeCommands(DELETE_COMMAND, T9_COMMAND, originalClearCommand);            }        }    }    /**     * Indicates whether the given key code should be ignored or should trigger     * editing, by default fire or any numeric key should trigger editing implicitly.     * This method is only called when handles input is false.     *      * @param keyCode the keycode passed to the keyPressed method     * @return true if this key code should cause a switch to editing mode.     */    protected boolean isEditingTrigger(int keyCode) {        if(isQwertyInput()) {            return keyCode > 0 || (Display.getInstance().getGameAction(keyCode) == Display.GAME_FIRE);        }        return (keyCode >= '0' && keyCode <= '9') ||             (Display.getInstance().getGameAction(keyCode) == Display.GAME_FIRE);    }        /**     * Indicates whether the given key code should be ignored or should trigger     * cause editing to end. By default the fire key, up or down will trigger     * the end of editing.     *      * @param keyCode the keycode passed to the keyPressed method     * @return true if this key code should cause a switch to editing mode.     */    protected boolean isEditingEndTrigger(int keyCode) {        int k =Display.getInstance().getGameAction(keyCode);        if(isQwertyInput()) {            return keyCode < 0 && (k == Display.GAME_FIRE || k == Display.GAME_UP || k == Display.GAME_DOWN);        }        return (k == Display.GAME_FIRE || k == Display.GAME_UP || k == Display.GAME_DOWN);    }        /**     * @inheritDoc     */    public void paint(Graphics g) {        UIManager.getInstance().getLookAndFeel().drawTextField(g, this);        if (drawCursor) {            UIManager.getInstance().getLookAndFeel().drawTextFieldCursor(g, this);        }    }    /**     * @inheritDoc     */    protected Dimension calcPreferredSize() {        return UIManager.getInstance().getLookAndFeel().getTextFieldPreferredSize(this);    }        /**     * @inheritDoc     */    protected void initComponent() {        getComponentForm().registerAnimated(this);    }        /**     * The amount of time in milliseconds in which the cursor is visible     */    public void setCursorBlinkTimeOn(int time) {        blinkOnTime = time;    }    /**     * The amount of time in milliseconds in which the cursor is invisible     */    public void setCursorBlinkTimeOff(int time) {        blinkOffTime = time;    }        /**     * The amount of time in milliseconds in which the cursor is visible     */    public int getCursorBlinkTimeOn() {        return blinkOnTime;    }    /**     * The amount of time in milliseconds in which the cursor is invisible     */    public int getCursorBlinkTimeOff() {        return blinkOffTime;    }    /**     * @inheritDoc     */    public boolean animate() {        boolean ani = super.animate();        if(hasFocus()) {            long currentTime = System.currentTimeMillis();            if (drawCursor) {                if ((currentTime - cursorBlinkTime) > blinkOnTime) {                    cursorBlinkTime = currentTime;                    drawCursor = false;                    return true;                }            } else {                if ((currentTime - cursorBlinkTime) > blinkOffTime) {                    cursorBlinkTime = currentTime;                    drawCursor = true;                    return true;                }            }            if(pressedAndNotReleased) {                 if(currentTime - pressTime >= getLongClickDuration()) {                    longClick(pressedKeyCode);                }            } else {                if(pendingCommit && currentTime - releaseTime > commitTimeout) {                    commitChange();                }            }        } else {            drawCursor = false;        }        return ani;    }        /**     * @inheritDoc     */    public void pointerReleased(int x, int y) {        // unlike text area the text field supports shifting the cursor with the touch screen        String text = getText();        int textLength = text.length();        int position = 0;        Font f = getStyle().getFont();        x -= getAbsoluteX();        for(int iter = 0 ; iter < textLength ; iter++) {            int width = f.substringWidth(text, 0, iter);            if(x > width) {                position = iter;            } else {                break;            }        }        if(position == textLength - 1) {            if(f.stringWidth(text) < x) {                position = textLength;            }        }        setCursorPosition(position);        repaint();    }    /**     * When set to true softkeys are used to enable delete functionality     */    public boolean isUseSoftkeys() {        return useSoftkeys;    }    /**     * When set to true softkeys are used to enable delete functionality     */    public void setUseSoftkeys(boolean useSoftkeys) {        this.useSoftkeys = useSoftkeys;    }        /**     * Adds a listener for data change events it will be invoked for every change     * made to the text field     */    public void addDataChangeListener(DataChangedListener d) {        if(listeners == null) {            listeners = new Vector();        }        if(!listeners.contains(d)) {            listeners.addElement(d);        }    }    /**     * Removes the listener for data change events      */    public void removeDataChangeListener(DataChangedListener d) {        if(listeners == null) {            listeners = new Vector();        }        listeners.removeElement(d);    }        private void fireDataChanged(int type, int index) {        if(listeners != null) {            for(int iter = 0 ; iter < listeners.size() ; iter++) {                DataChangedListener d = (DataChangedListener)listeners.elementAt(iter);                d.dataChanged(type, index);            }        }    }        /**     * @inheritDoc     */    void onEditComplete(String text) {        super.onEditComplete(text);        setCursorPosition(text.length());    }    /**     * Indicates whether the menu of the form should be replaced with the T9/Clear     * commands for the duration of interactivity with the text field     */    public boolean isReplaceMenu() {        return replaceMenu;    }    /**     * Indicates whether the menu of the form should be replaced with the T9/Clear     * commands for the duration of interactivity with the text field     */    public void setReplaceMenu(boolean replaceMenu) {        this.replaceMenu = replaceMenu;    }    /**     * Indicates whether the menu of the form should be replaced with the T9/Clear     * commands for the duration of interactivity with the text field     */    public static boolean isReplaceMenuDefault() {        return replaceMenuDefault;    }    /**     * Indicates whether the menu of the form should be replaced with the T9/Clear     * commands for the duration of interactivity with the text field     */    public static void setReplaceMenuDefault(boolean replaceMenu) {        replaceMenuDefault = replaceMenu;    }}

⌨️ 快捷键说明

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