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

📄 codepointinputmethod.java

📁 input method tool using java
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                buffer.append(c);                insertionPoint = 9;                sendComposedText();            } else {                beep();            }        } else {            beep();        }    }    /**     * Send the composed text to the client.     */    private void sendComposedText() {        AttributedString as = new AttributedString(buffer.toString());        as.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT,                        InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT);        context.dispatchInputMethodEvent(                                  InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,                                  as.getIterator(), 0,                                  TextHitInfo.leading(insertionPoint), null);    }    /**     * Send the committed text to the client.     */    private void sendCommittedText() {        AttributedString as = new AttributedString(buffer.toString());        context.dispatchInputMethodEvent(                                  InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,                                  as.getIterator(), buffer.length(),                                  TextHitInfo.leading(insertionPoint), null);        buffer.setLength(0);        insertionPoint = 0;        format = UNSET;    }    /**     * Move the insertion point one position to the left in the composed text.     * Do not let the caret move to the left of the "\\u" or "\\U".     */    private void moveCaretLeft() {        int len = buffer.length();        if (--insertionPoint < 2) {            insertionPoint++;            beep();        } else if (format == SURROGATE_PAIR && insertionPoint == 7) {            insertionPoint = 8;            beep();        }        context.dispatchInputMethodEvent(                                  InputMethodEvent.CARET_POSITION_CHANGED,                                  null, 0,                                  TextHitInfo.leading(insertionPoint), null);    }    /**     * Move the insertion point one position to the right in the composed text.     */    private void moveCaretRight() {        int len = buffer.length();        if (++insertionPoint > len) {            insertionPoint = len;            beep();        }        context.dispatchInputMethodEvent(                                  InputMethodEvent.CARET_POSITION_CHANGED,                                  null, 0,                                  TextHitInfo.leading(insertionPoint), null);    }    /**     * Delete the character preceding the insertion point in the composed text.     * If the insertion point is not at the end of the composed text and the     * preceding text is "\\u" or "\\U", ring the bell.     */    private void deletePreviousCharacter() {        if (insertionPoint == 2) {            if (buffer.length() == 2) {                cancelComposition();            } else {                // Do not allow deletion of the leading "\\u" or "\\U" if there                // are other digits in the composed text.                beep();            }        } else if (insertionPoint == 8) {            if (buffer.length() == 8) {                if (format == SURROGATE_PAIR) {                    buffer.deleteCharAt(--insertionPoint);                }                buffer.deleteCharAt(--insertionPoint);                sendComposedText();            } else {                // Do not allow deletion of the second "\\u" if there are other                // digits in the composed text.                beep();            }        } else {            buffer.deleteCharAt(--insertionPoint);            if (buffer.length() == 0) {                sendCommittedText();            } else {                sendComposedText();            }        }    }    /**     * Delete the character following the insertion point in the composed text.     * If the insertion point is at the end of the composed text, ring the bell.     */    private void deleteCharacter() {        if (insertionPoint < buffer.length()) {            buffer.deleteCharAt(insertionPoint);            sendComposedText();        } else {            beep();        }    }    private void startComposition() {        buffer.append('\\');        insertionPoint = 1;        sendComposedText();    }    private void cancelComposition() {        buffer.setLength(0);        insertionPoint = 0;        sendCommittedText();    }    private void finishComposition() {        int len = buffer.length();        if (len == 6 && format != SPECIAL_ESCAPE) {            char codePoint = (char)getCodePoint(buffer, 2, 5);            if (Character.isValidCodePoint(codePoint) && codePoint != 0xFFFF) {                buffer.setLength(0);                buffer.append(codePoint);	        sendCommittedText();                return;            }        } else if (len == 8 && format == SPECIAL_ESCAPE) {            int codePoint = getCodePoint(buffer, 2, 7);            if (Character.isValidCodePoint(codePoint) && codePoint != 0xFFFF) {                buffer.setLength(0);                buffer.appendCodePoint(codePoint);	        sendCommittedText();                return;            }        } else if (len == 12 && format == SURROGATE_PAIR) {	    char[] codePoint = {                (char)getCodePoint(buffer, 2, 5),	        (char)getCodePoint(buffer, 8, 11)            };            if (Character.isHighSurrogate(codePoint[0]) &&                Character.isLowSurrogate(codePoint[1])) {	        buffer.setLength(0);	        buffer.append(codePoint);	        sendCommittedText();                return;            }        }        beep();    }    private int getCodePoint(StringBuffer sb, int from, int to) {        int value = 0;        for (int i = from; i <= to; i++) {            value = (value<<4) + Character.digit(sb.charAt(i), 16);        }        return value;    }    private static void beep() {        Toolkit.getDefaultToolkit().beep();    }    public void activate() {        if (buffer == null) {            buffer = new StringBuffer(12);            insertionPoint = 0;        }    }    public void deactivate(boolean isTemporary) {        if (!isTemporary) {            buffer = null;        }    }    public void dispose() {    }    public Object getControlObject() {        return null;    }    public void endComposition() {        sendCommittedText();    }    public Locale getLocale() {        return locale;    }    public void hideWindows() {    }    public boolean isCompositionEnabled() {        // always enabled        return true;    }    public void notifyClientWindowChange(Rectangle location) {    }    public void reconvert() {        // not supported yet        throw new UnsupportedOperationException();    }    public void removeNotify() {    }    public void setCharacterSubsets(Character.Subset[] subsets) {    }    public void setCompositionEnabled(boolean enable) {        // not supported yet        throw new UnsupportedOperationException();    }    public void setInputMethodContext(InputMethodContext context) {        this.context = context;    }    /*     * The Code Point Input Method supports all locales.     */    public boolean setLocale(Locale locale) {        this.locale = locale;        return true;    }}

⌨️ 快捷键说明

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