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

📄 lookup.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }        e.consume(); //any other non-character keys    }    /**     * Handle a typed character key.     *     * @param e DOCUMENT ME!     */    private final void handleTypedKey(KeyEvent e) {        char ch = e.getKeyChar();        int chkc = e.getKeyCode();        if ((lookupList != null) && lookupList.isVisible()) {            /* There is a lookup list.               The user continues a pinyin word             */            if ((' ' == ch) || (KeyEvent.VK_ENTER == ch)) {                selectCandidate(this.lookupSelection);                commit();                closeLookupWindow();                e.consume();                return;            }            if (KeyEvent.VK_ESCAPE == ch) {                cancelEdit();                e.consume();                return;            }            if (ch == '\b') {                if (rawText.length() != 0) {                    rawText.setLength(rawText.length() - 1);                    sendText(false);                }                e.consume();                return;            }            lookupCharacter(ch);            /*               The user typed a character, but the resulting               pinyin word does not exist.               we don't want such a word to be written.               The user should be notified, but I think it is quiet               obvious doing nothing.               beep would be too harsh               anyhow, if there is a lookup list: always consume, no matter if the word               results in the hash or not             */            e.consume();            return;        } else {            // There is no lookup list.		            // There should be no rawText, otherwise, there is something wrong.            if (rawText.length() != 0) {                System.out.println("ask Markus: why is there rawText?");            }            // We may have to open a lookup list.            if (lookupCharacter(ch)) {                /*                   The user starts a pinyin word.                   A lookup list will be opened.                 */                e.consume();            } else {                /*                   The character does not exist in the hash, not even as the beginning of a                   word.                   Pass through the underlying editor unchanged, and unconsumed.                 */            }        }    }    /**     * DOCUMENT ME!     */    private final void commit() {        sendText(true);        rawText.setLength(0);        convertedText = null;        converted = false;        closeLookupWindow();    }    /**     * Dispatches a more or less empty InputMethodEvent, resulting in     * cancellation of the edit operation. Resets object values and closes the     * LookupList  (when neccessary).     */    private void cancelEdit() {        inputMethodContext.dispatchInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,            null, 0, TextHitInfo.leading(0), null);        rawText.setLength(0);        convertedText = null;        converted = false;        closeLookupWindow();    }    /**     * DOCUMENT ME!     *     * @param committed DOCUMENT ME!     */    private final void sendText(boolean committed) {        String text;        InputMethodHighlight highlight;        int committedCharacterCount = 0;        if (converted) {            text = convertedText;            highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;        } else if (rawText.length() > 0) {            text = new String(rawText);            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;            // Redo list of characters in look up window based on latest pinyin string            String lookupName;            lookupName = rawText.toString().toLowerCase();            ArrayList templist = (ArrayList) (pinyinHash.get(lookupName.intern()));            if (templist == null) {                Toolkit.getDefaultToolkit().beep();                // TODO was soll das? //////////////////////////                templist = (ArrayList) (pinyinHash.get("a"));            }            //System.out.println(lookupName + " " + templist.size()) ;            lookupCandidates = new String[templist.size()];            for (int k = 0; k < lookupCandidates.length; k++) {                lookupCandidates[k] = (String) templist.get(k);            }            if (lookupCandidates != null) {                lookupCandidateCount = lookupCandidates.length;                lookupSelection = 0;                lookupCandidateIndex = 0;                if (lookupList != null) {                    lookupList.setVisible(false);                    lookupList = null;                }                openLookupWindow();            } else {                Toolkit.getDefaultToolkit().beep();            }        } else {            text = "";            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;            closeLookupWindow();        }        AttributedString as = new AttributedString(text);        if (committed) {            committedCharacterCount = text.length();        } else if (text.length() > 0) {            as.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, highlight);        }        inputMethodContext.dispatchInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,            as.getIterator(), committedCharacterCount,            TextHitInfo.leading(text.length()), null);    }    /**     * DOCUMENT ME!     *     * @param candidate DOCUMENT ME!     */    private final void selectCandidate(int candidate) {        lookupSelection = lookupCandidateIndex + candidate;        lookupList.selectCandidate(lookupSelection);        convertedText = lookupCandidates[lookupSelection];        converted = true;        sendText(false);    }    /**     * DOCUMENT ME!     */    private final void openLookupWindow() {        lookupList = new LookupList(this, inputMethodContext, lookupCandidates,                lookupCandidateCount);        lookupList.selectCandidate(lookupSelection);    }    /**     * DOCUMENT ME!     */    private final void closeLookupWindow() {        if (lookupList != null) {            lookupList.setVisible(false);            lookupList = null;        }    }    private void hideLookupWindow() {        if (lookupList != null) {            lookupList.setVisible(false);        }    }    private void showLookupWindow() {        if (lookupList != null) {            lookupList.setVisible(true);        }    }    /**     * @see java.awt.im.spi.InputMethod#activate     */    public void activate() {        if (statusWindowIsShown) {            if (!Lookup.statusWindow.isVisible()) {                Lookup.statusWindow.setVisible(true);            }            this.updateStatusWindow(this.locale);        }        showLookupWindow();    }    /**     * HS 05-feb-2004 On deactivation the editing is canceled. This prevents     * all kinds of exceptions that occur when the user switches to another     * application while the LookupList is open.  The argument     * <code>isTemporary</code> is ignored; the editing is always canceled.     *     * @param isTemporary ignored     *     * @see java.awt.im.spi.InputMethod#deactivate     * @see cancelEdit     */    public void deactivate(boolean isTemporary) {        cancelEdit();        /*           if (isTemporary) {               hideLookupWindow();           } else {                   hideWindows();           }         */    }    /**     * @see java.awt.im.spi.InputMethod#dispatchEvent     */    public void dispatchEvent(AWTEvent event) {        if (event instanceof KeyEvent) {            switch (((KeyEvent) event).getID()) {            case KeyEvent.KEY_TYPED:                this.handleTypedKey((KeyEvent) event);                break;            case KeyEvent.KEY_PRESSED:                this.handlePressedKey((KeyEvent) event);                break;            }        }        if (event instanceof MouseEvent) {            // MOUSE_PRESSED results in hiding the window...            // I don't see MOUSE_PRESSED here...            // a lot of work to do.            //HS 03-feb-2004 they come in, when the inline edit box is "attached"            MouseEvent mevent = (MouseEvent) event;            if (mevent.getID() == MouseEvent.MOUSE_PRESSED) {                int y = mevent.getY();                if ((lookupList != null) && (y >= lookupList.INSIDE_INSET) &&                        (y < (lookupList.INSIDE_INSET +                        (lookupCandidateCount * lookupList.LINE_SPACING)))) {                    selectCandidate((y - lookupList.INSIDE_INSET) / lookupList.LINE_SPACING);                    mevent.consume();                    commit(); //??                    //closeLookupWindow();                }            }        }    }    /**     * @see java.awt.im.spi.InputMethod#dispose     */    public void dispose() {        hideWindows();    }    /**     * @see java.awt.im.spi.InputMethod#endComposition     */    public void endComposition() {        if (this.rawText.length() != 0) {            this.commit(); // TODO do we want that?        }        hideWindows();    }    /**     * @see java.awt.im.spi.InputMethod#getControlObject     */    public Object getControlObject() {        return null;    }    /**     * @see java.awt.im.spi.InputMethod#getLocale     */    public Locale getLocale() {        return this.locale;    }    /**     * @see java.awt.im.spi.InputMethod#hideWindows     */    public void hideWindows() {        this.closeLookupWindow();        if (statusWindowIsShown) {            Lookup.statusWindow.hide();        }    }    /**     * @see java.awt.im.spi.InputMethod#isCompositionEnabled     */    public boolean isCompositionEnabled() {        return true;    }    /**     * @see java.awt.im.spi.InputMethod#notifyClientWindowChange     */    public void notifyClientWindowChange(Rectangle location) {    }    /**     * @see java.awt.im.spi.InputMethod#reconvert     */    public void reconvert() {        throw new UnsupportedOperationException();    }    /**     * @see java.awt.im.spi.InputMethod#removeNotify     */    public void removeNotify() {    }    /**     * @see java.awt.im.spi.InputMethod#setCharacterSubsets     */    public void setCharacterSubsets(Character.Subset[] subsets) {    }    /**     * @see java.awt.im.spi.InputMethod#setCompositionEnabled     */    public void setCompositionEnabled(boolean enable) {        throw new UnsupportedOperationException();    }    /**     * @see java.awt.im.spi.InputMethod#setInputMethodContext     */    public void setInputMethodContext(InputMethodContext context) {        this.inputMethodContext = context;        if ((statusWindow == null) && statusWindowIsShown) {            statusWindow = inputMethodContext.createInputMethodWindow("Language",                    false);            statusWindowLabel = new Label();            statusWindowLabel.setBackground(Color.white);            statusWindowLabel.setSize(200, 50);            statusWindow.add(statusWindowLabel);            updateStatusWindow(this.locale);            statusWindow.pack();            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();            statusWindow.setLocation(d.width - statusWindow.getWidth(),                d.height - statusWindow.getHeight());        }    }    /**     * @see java.awt.im.spi.InputMethod#setLocale     */    public boolean setLocale(Locale locale) {        //System.out.println("Lookup.java: request for " + locale);        //System.out.println("Lookup.java: was  " + this.locale);        if (locale == null) {            return false;        }        if (locale == this.locale) {            return true;        }        if (!hashedFilenames.containsKey(locale)) {            return false;        }        try {            initializeHash(locale);            this.updateStatusWindow(locale);            this.closeLookupWindow();            this.locale = locale;            return true;        } catch (Exception e) {            e.printStackTrace();        }        return false;    }}

⌨️ 快捷键说明

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