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

📄 textbasic.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        } else {            if (curPos > numChars) {                curPos = numChars;            }        }        return policy.contentChanged(buffer, numChars, offset, curPos);    }    /**     * Replace a section of characters in the buffer     *     * @param data The new characters     * @param offset The offset into the buffer to start to replace     * @param length The number of characters to replace     * @return int The delta height change caused by this replacement     */    int setChars(char[] data, int offset, int length)  {        if (data == null) {            numChars = curPos = 0;            return policy.contentChanged(buffer, numChars, 0, curPos);        }        if ((offset < 0 || length < 0) || (offset + length > data.length)) {            throw new ArrayIndexOutOfBoundsException();        }        if (length > buffer.length) {            throw new IllegalArgumentException();        }        if (!policy.validateContent(data, offset, length)) {            throw new IllegalArgumentException();        }        System.arraycopy(data, offset, buffer, 0, length);        numChars = length;        curPos = numChars;        return policy.contentChanged(buffer, numChars, 0, curPos);    }    /**     * Set the string for this text object     *     * @param text The new text for this text object     * @return int The delta height change caused by this set     */    int setString(String text) {        // System.out.println("inside TextBasics setString for "+text);        if (text == null) {            numChars = 0;            curPos = 0;        } else {            int length = text.length();            if (length > buffer.length) {                throw new IllegalArgumentException();            }            text.getChars(0, length, buffer, 0);            if (!policy.validateContent(buffer, 0, length)) {                throw new IllegalArgumentException();            }            numChars = length;            curPos = length;        }        return policy.contentChanged(buffer, numChars, 0, curPos);    }    /**     * Retrieve this text object's characters into an array     *     * @param data The array to fill with characters     * @return int The number of characters placed into the array     */    int getChars(char[] data)  {        if (numChars > data.length) {            throw new ArrayIndexOutOfBoundsException();        }        if ((buffer != null) && (numChars > 0)) {            System.arraycopy(buffer, 0, data, 0, numChars);            return numChars;        } else {            return 0;        }    }    /**     * Traverse this text object     *     * @param dir The direction of traversal     * @param top     * @param bottom     * @return int     */    int traverse(int dir, int top, int bottom) {        // No traversal is possible if dir is not a traversal direction        // and if numChars is 0        if ((numChars == 0) ||                ((dir != Canvas.UP) && (dir != Canvas.DOWN) &&                (dir != Canvas.LEFT) && (dir != Canvas.RIGHT))) {            return -1;        }        int oldCurPos = curPos;        curPos = policy.moveCursor(dir, curPos, buffer, numChars);        if (curPos != oldCurPos) {            int cursorY1 = policy.cursorY;            int cursorY2 = cursorY1 + policy.lineHeight;            if (top <= cursorY1 && bottom >= cursorY2) {                return 0;            }            int t1 = cursorY2 - bottom;            int t2 = top - cursorY1;            return t1 >= t2 ? t1 : t2;        }        return -1;    }    /**     * Set the width of this text object     * @param width The width of this object     * @return new height after width was set     */    int setWidth(int width) {        return policy.setWidth(width, buffer, numChars, curPos);    }    /**     * Set the horizontal scroll indicators for this text object     *     * @param parent The Screen object who is the parent of this     *                  text object     */    void setHorizontalScroll(Screen parent) {        if (parent instanceof TextBox) {            if (numChars == 0) {                parent.setHorizontalScroll(0, 100);            } else {                parent.setHorizontalScroll(curPos * 100 / numChars,                                           100 / (numChars + 1));            }        }    }    /**     * Get the maximum width of this text object     *     * @param allowedWidth The maximum allowed width of this object     * @return int The actual width of this text object     */    int getMaxWidth(int allowedWidth) {        return policy.getMaxWidth(allowedWidth, buffer.length);    }    static {        /**         * A special input mode client to handle multiple input modes         * on text components.         */        InputModeClient imc = new InputModeClient() {            /**             * Set the mode of this input client             *             * @param tb The TextBox this imc belongs to             * @param defaultMode The default mode for this imc             */            public void setMode(TextBox tb, String defaultMode) {                tb.sD.defaultMode = defaultMode;            }            /**             * Get the mode of this input client             *             * @param tb The TextBox this imc belongs to             * @return String The default mode of the TextBox             */            public String getMode(TextBox tb) {                return tb.sD.defaultMode;            }            /**             * Set the allowed input modes of the TextBox             *             * @param tb The TextBox to set the allowed modes on             * @param allowedMode The set of allowed input modes             */            public void setAllowedModes(TextBox tb, String[] allowedMode) {                tb.sD.allowedMode = allowedMode;            }            /**             * Get all the allowed modes of this textbox             *             * @param tb The TextBox to get the allowed modes for             * @return String[] The allowed input modes of the TextBox             */            public String[] getAllowedModes(TextBox tb) {                return tb.sD.allowedMode;            }            /**             * Set the input mode for the TextField to the given mode             *             * @param tf The TextField to set the input mode             * @param defaultMode The input mode to set on the TextField             */            public void setMode(TextField tf, String defaultMode) {                tf.sD.defaultMode = defaultMode;            }            /**             * Get the mode of the given TextField             *             * @param tf The TextField to get the input mode of             * @return String The input mode of the TextField             */            public String getMode(TextField tf) {                return tf.sD.defaultMode;            }            /**             * Set the allowed input modes of the given TextField             *             * @param tf The TextField to set the allowed input modes of             * @param allowedMode An array of allowed input modes             */            public void setAllowedModes(TextField tf, String[] allowedMode) {                tf.sD.allowedMode = allowedMode;            }            /**             * Get the allowed input modes of the given TextField             *             * @param tf The TextField to get the allowed input modes of             * @return String[] An array of allowed input modes             */            public String[] getAllowedModes(TextField tf) {                return tf.sD.allowedMode;            }        };        InputModeHelper.setInputModeHelper(imc);    }}

⌨️ 快捷键说明

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