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

📄 textfield.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        if (super.equateNLB()) {	    return true;	}        return ((layout & Item.LAYOUT_2) != Item.LAYOUT_2);    }    /**     * Return the minimum width required for this TextField     *     * @return the minimum width for this TextField     */    int callMinimumWidth() {        if ((layout == Item.LAYOUT_DEFAULT) || (equateNLB() && equateNLA())) {	    if (owner != null) {		return owner.getWidth();	    }	}        return (Screen.CONTENT_FONT.charWidth('W') * 8);    }    /**     * Get the preferred width for this TextField for the given height     *     * @param h the height to calculate the width for     * @return the width preferred by this TextField for the given height     */    int callPreferredWidth(int h) {        // FIX ME: we ignore the 'h' value and just return        // a basic width based on our contents. That is, this        // StringItem's preferred width is always based on        // being one line high        int textW = Screen.CONTENT_FONT.charWidth('W') * buffer.capacity();        // Plus pixels to draw the box around the text        textW += (2 * BORDER_PAD);        int labelW = getLabelWidth();        if (labelW > 0) {            labelW += LABEL_PAD;        }        return textW + labelW;    }    /**     * Return the minimum height required for this TextField     *     * @return the minimum height for this TextField     */    int callMinimumHeight() {        // Plus pixels to draw the box around the text        return Screen.CONTENT_HEIGHT + (2 * BORDER_PAD);    }    /**     * Get the preferred height for this TextField for the given width     *     * @param w the width to fit within     * @return the height required for this TextField for the given width     */    int callPreferredHeight(int w) {        fitsOneLine = (w == -1) ? true : (w >= callPreferredWidth(-1));        if (fitsOneLine) {            return (2 * BORDER_PAD) + Screen.CONTENT_HEIGHT;        } else {            if (buffer.length() == 0) {                return (2 * BORDER_PAD) + getLabelHeight(w) +                        Screen.CONTENT_HEIGHT;            } else {                return (2 * BORDER_PAD) + getLabelHeight(w) +                    Text.getHeightForWidth(                        TextPolicy.getDisplayString(buffer,                                          currentInputChar,                                         inputClient.getConstraints(),                                          inputHandler, cursor),                        Screen.CONTENT_FONT, w - (2 * BORDER_PAD + 1), 0);            }        }    }    /**     * Paint this TextField     *     * @param g The Graphics object to paint to     * @param width the width granted to this TextField     * @param height the height granted to this TextField     */    void callPaint(Graphics g, int width, int height) {             //        // draw label        //        int labelHeight = getLabelHeight(width);        int labelWidth = getLabelWidth();        // Add some padding        if (labelWidth > 0) {            labelWidth += LABEL_PAD;        }        if (g.getClipY() < labelHeight) {            if (fitsOneLine) {                g.translate(0, LABEL_PAD);            }            super.paintLabel(g, width);            if (fitsOneLine) {                g.translate(0, -LABEL_PAD);            }        }        if (fitsOneLine) {            width = width - labelWidth;            g.translate(labelWidth, 0);        } else {            height = height - labelHeight;            g.translate(0, labelHeight);        }        if (hasBorder) {            if (!hasFocus) {                g.setColor(0x00AFAFAF);            }            // draw box            g.drawRect(0, 0, width - 1, height - 1);        }        g.setColor(editable ? Display.FG_COLOR : 0x00AFAFAF);        g.translate(BORDER_PAD + 1, BORDER_PAD);        TextPolicy.paint(buffer, currentInputChar,                          inputClient.getConstraints(), inputHandler,                         Screen.CONTENT_FONT,                         g, width - (2 * BORDER_PAD + 1), height, 0,                          Text.NORMAL, cursor);                                  g.translate(-(BORDER_PAD + 1), -BORDER_PAD);        if (fitsOneLine) {            g.translate(-labelWidth, 0);        } else {            g.translate(0, -labelHeight);        }        g.setColor(Display.FG_COLOR);        if (usePreferredX) {            cursor.preferredX = cursor.x;        }    }    /**     * Handle a key committed from the input handler     *     * @param keyCode key that was committed     */    void keyEntered(int keyCode) {        synchronized (Display.LCDUILock) {            oldNumChars = buffer.length();            cursor.visible = true;            currentInputChar = 0;            switch (keyCode) {                case InputMethodHandler.KEYCODE_CLEARALL:                    if (buffer.length() > 0) {                        delete(0, buffer.length());                        notifyStateChanged();                    }                    break;                case InputMethodHandler.KEYCODE_CLEAR:                    try {                        if (cursor.index > 0) {                            delete(cursor.index - 1, 1);                            notifyStateChanged();                        }                    } catch (IllegalArgumentException e) {                        if (buffer.length() > 0) {                            delete(0, buffer.length());                            notifyStateChanged();                        }                    }                    break;                case InputMethodHandler.KEYCODE_SIGNCHANGE:                    try {                        if (buffer.length() > 0) {                            if (buffer.charAt(0) == '-') {                                delete(0, 1);                            } else {                                insert('-', 0);                            }                            notifyStateChanged();                        }                    } catch (IllegalArgumentException e) {                        //                        // beep?                        //                        AlertType.WARNING.playSound(owner.currentDisplay);                    }                    break;                default:                    try {                        int inputLength = 0;                        if ((inputClient.getConstraints() & CONSTRAINT_MASK)                            == DECIMAL) {                            if (keyCode == '.' && buffer.length() == 0) {                                inputChars[inputLength] = '0';                                inputLength++;                            }                        }                        inputChars[inputLength] = (char)keyCode;                        inputLength++;                        insert(inputChars, 0, inputLength, cursor.index);                        notifyStateChanged();                    } catch (IllegalArgumentException e) {                        //                        // beep?                        //                        AlertType.WARNING.playSound(owner.currentDisplay);                    }                    break;            }        }    }    /**     * Handle a key press     *     * @param keyCode the code for the key which was pressed     */    void callKeyPressed(int keyCode) {        synchronized (Display.LCDUILock) {            if (Display.getSystemKey(keyCode) ==                        EventHandler.SYSTEM_KEY_SEND) {                if ((inputClient.getConstraints() & TextField.CONSTRAINT_MASK)                     == TextField.PHONENUMBER) {                    PhoneDial.call(getString());                }                return;            }            if (!editable) {                // play sound                AlertType.WARNING.playSound(owner.currentDisplay);                return;            }        /*         * At present, Form uses all of the arrow keys for traversal,         * so keystrokes for the arrow keys are never delivered here.         * If the traversal policy changes such that keystrokes on the         * arrow keys might be delivered here, this code should be         * uncommented.         *************************************************************         *            if (keyCode == Display.KEYCODE_UP                || keyCode == Display.KEYCODE_DOWN                || keyCode == Display.KEYCODE_LEFT                || keyCode == Display.KEYCODE_RIGHT) {                if (moveCursor(Display.getGameAction(keyCode))) {                    invalidate();                    return;                }            }         *         *************************************************************         */            int key;            if ((key = inputHandler.keyPressed(keyCode)) !=                 InputMethodHandler.KEYCODE_NONE) {                if (buffer.length() == buffer.capacity()) {                    // play sound                    AlertType.WARNING.playSound(owner.currentDisplay);                    inputHandler.flush();                    return;                }                currentInputChar = (char)key;                cursor.visible = false;                invalidate();                return;            }         }    }    /**     * Handle a key release event      *     * @param keyCode key that was released     */    void callKeyReleased(int keyCode) {        synchronized (Display.LCDUILock) {            inputHandler.keyReleased(keyCode);        }    }    /**     * Handle a key repeated event      *     * @param keyCode key that was repeated     */    void callKeyRepeated(int keyCode) {        callKeyPressed(keyCode);    }    /**     * Handle a key typed event     *     * @param c the character typed on the QWERTY keyboard     */    void callKeyTyped(char c) {        synchronized (Display.LCDUILock) {            if (!editable) {                // play sound                AlertType.WARNING.playSound(owner.currentDisplay);                return;            }            inputHandler.keyTyped(c);        }    }    /**     * Move the text cursor in the given direction     *     * @param dir direction to move     * @return true if the cursor was moved, false otherwise     */    boolean moveCursor(int dir) {        boolean keyUsed = false;        int height;        switch (dir) {            case Canvas.LEFT:                if (cursor.index > 0) {                    cursor.index--;

⌨️ 快捷键说明

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