Java Code Examples for java.awt.event.InputMethodEvent

The following examples show how to use java.awt.event.InputMethodEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: jdk8u-jdk   Source File: X11InputMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Dispatches committed text from XIM to the awt event queue. This
 * method is invoked from the event handler in canvas.c in the
 * AWT Toolkit thread context and thus inside the AWT Lock.
 * @param   str     committed text
 * @param   long    when
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void dispatchCommittedText(String str, long when) {
    if (str == null)
        return;

    if (composedText == null) {
        AttributedString attrstr = new AttributedString(str);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             str.length(),
                             null,
                             null,
                             when);
    } else {
        // if there is composed text, wait until the preedit
        // callback is invoked.
        committedText = str;
    }
}
 
Example 2
/**
 * 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);
}
 
Example 3
/**
 * 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);
}
 
Example 4
Source Project: hottub   Source File: X11InputMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Dispatches committed text from XIM to the awt event queue. This
 * method is invoked from the event handler in canvas.c in the
 * AWT Toolkit thread context and thus inside the AWT Lock.
 * @param   str     committed text
 * @param   long    when
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void dispatchCommittedText(String str, long when) {
    if (str == null)
        return;

    if (composedText == null) {
        AttributedString attrstr = new AttributedString(str);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             str.length(),
                             null,
                             null,
                             when);
    } else {
        // if there is composed text, wait until the preedit
        // callback is invoked.
        committedText = str;
    }
}
 
Example 5
public void dispatchEvent(AWTEvent event) {
    // some host input method adapters may dispatch input method events
    // through the Java event queue. If the component that the event is
    // intended for isn't an active client, or if we're using below-the-spot
    // input, we need to dispatch this event
    // to the input window. Note that that component is not necessarily the
    // current client component, since we may have switched clients while
    // the event was in the queue.
    if (event instanceof InputMethodEvent) {
        if (((Component) event.getSource()).getInputMethodRequests() == null
                || (useBelowTheSpotInput() && !dispatchingCommittedText)) {
            getCompositionAreaHandler(true).processInputMethodEvent((InputMethodEvent) event);
        }
    } else {
        // make sure we don't dispatch our own key events back to the input method
        if (!dispatchingCommittedText) {
            super.dispatchEvent(event);
        }
    }
}
 
Example 6
public void dispatchInputMethodEvent(int id,
            AttributedCharacterIterator text, int committedCharacterCount,
            TextHitInfo caret, TextHitInfo visiblePosition) {
    // We need to record the client component as the source so
    // that we have correct information if we later have to break up this
    // event into key events.
    Component source;

    source = getClientComponent();
    if (source != null) {
        InputMethodEvent event = new InputMethodEvent(source,
                id, text, committedCharacterCount, caret, visiblePosition);

        if (haveActiveClient() && !useBelowTheSpotInput()) {
            source.dispatchEvent(event);
        } else {
            getCompositionAreaHandler(true).processInputMethodEvent(event);
        }
    }
}
 
Example 7
public void dispatchEvent(AWTEvent event) {
    // some host input method adapters may dispatch input method events
    // through the Java event queue. If the component that the event is
    // intended for isn't an active client, or if we're using below-the-spot
    // input, we need to dispatch this event
    // to the input window. Note that that component is not necessarily the
    // current client component, since we may have switched clients while
    // the event was in the queue.
    if (event instanceof InputMethodEvent) {
        if (((Component) event.getSource()).getInputMethodRequests() == null
                || (useBelowTheSpotInput() && !dispatchingCommittedText)) {
            getCompositionAreaHandler(true).processInputMethodEvent((InputMethodEvent) event);
        }
    } else {
        // make sure we don't dispatch our own key events back to the input method
        if (!dispatchingCommittedText) {
            super.dispatchEvent(event);
        }
    }
}
 
Example 8
Source Project: hottub   Source File: InputMethodContext.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void dispatchInputMethodEvent(int id,
            AttributedCharacterIterator text, int committedCharacterCount,
            TextHitInfo caret, TextHitInfo visiblePosition) {
    // We need to record the client component as the source so
    // that we have correct information if we later have to break up this
    // event into key events.
    Component source;

    source = getClientComponent();
    if (source != null) {
        InputMethodEvent event = new InputMethodEvent(source,
                id, text, committedCharacterCount, caret, visiblePosition);

        if (haveActiveClient() && !useBelowTheSpotInput()) {
            source.dispatchEvent(event);
        } else {
            getCompositionAreaHandler(true).processInputMethodEvent(event);
        }
    }
}
 
Example 9
Source Project: openjdk-jdk9   Source File: X11InputMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Flushes composed and committed text held in this context.
 * This method is invoked in the AWT Toolkit (X event loop) thread context
 * and thus inside the AWT Lock.
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void flushText() {
    String flush = (committedText != null ? committedText : "");
    if (composedText != null) {
        flush += composedText.toString();
    }

    if (!flush.equals("")) {
        AttributedString attrstr = new AttributedString(flush);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             flush.length(),
                             null,
                             null,
                             EventQueue.getMostRecentEventTime());
        composedText = null;
        committedText = null;
    }
}
 
Example 10
Source Project: openjdk-8   Source File: X11InputMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Dispatches committed text from XIM to the awt event queue. This
 * method is invoked from the event handler in canvas.c in the
 * AWT Toolkit thread context and thus inside the AWT Lock.
 * @param   str     committed text
 * @param   long    when
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void dispatchCommittedText(String str, long when) {
    if (str == null)
        return;

    if (composedText == null) {
        AttributedString attrstr = new AttributedString(str);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             str.length(),
                             null,
                             null,
                             when);
    } else {
        // if there is composed text, wait until the preedit
        // callback is invoked.
        committedText = str;
    }
}
 
Example 11
public void dispatchInputMethodEvent(int id,
            AttributedCharacterIterator text, int committedCharacterCount,
            TextHitInfo caret, TextHitInfo visiblePosition) {
    // We need to record the client component as the source so
    // that we have correct information if we later have to break up this
    // event into key events.
    Component source;

    source = getClientComponent();
    if (source != null) {
        InputMethodEvent event = new InputMethodEvent(source,
                id, text, committedCharacterCount, caret, visiblePosition);

        if (haveActiveClient() && !useBelowTheSpotInput()) {
            source.dispatchEvent(event);
        } else {
            getCompositionAreaHandler(true).processInputMethodEvent(event);
        }
    }
}
 
Example 12
Source Project: hottub   Source File: X11InputMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Flushes composed and committed text held in this context.
 * This method is invoked in the AWT Toolkit (X event loop) thread context
 * and thus inside the AWT Lock.
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void flushText() {
    String flush = (committedText != null ? committedText : "");
    if (composedText != null) {
        flush += composedText.toString();
    }

    if (!flush.equals("")) {
        AttributedString attrstr = new AttributedString(flush);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             flush.length(),
                             null,
                             null,
                             EventQueue.getMostRecentEventTime());
        composedText = null;
        committedText = null;
    }
}
 
Example 13
Source Project: jdk8u-jdk   Source File: X11InputMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Flushes composed and committed text held in this context.
 * This method is invoked in the AWT Toolkit (X event loop) thread context
 * and thus inside the AWT Lock.
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void flushText() {
    String flush = (committedText != null ? committedText : "");
    if (composedText != null) {
        flush += composedText.toString();
    }

    if (!flush.equals("")) {
        AttributedString attrstr = new AttributedString(flush);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             flush.length(),
                             null,
                             null,
                             EventQueue.getMostRecentEventTime());
        composedText = null;
        committedText = null;
    }
}
 
Example 14
Source Project: jdk8u-dev-jdk   Source File: X11InputMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Dispatches committed text from XIM to the awt event queue. This
 * method is invoked from the event handler in canvas.c in the
 * AWT Toolkit thread context and thus inside the AWT Lock.
 * @param   str     committed text
 * @param   long    when
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void dispatchCommittedText(String str, long when) {
    if (str == null)
        return;

    if (composedText == null) {
        AttributedString attrstr = new AttributedString(str);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             str.length(),
                             null,
                             null,
                             when);
    } else {
        // if there is composed text, wait until the preedit
        // callback is invoked.
        committedText = str;
    }
}
 
Example 15
Source Project: jdk8u60   Source File: InputMethodContext.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void dispatchInputMethodEvent(int id,
            AttributedCharacterIterator text, int committedCharacterCount,
            TextHitInfo caret, TextHitInfo visiblePosition) {
    // We need to record the client component as the source so
    // that we have correct information if we later have to break up this
    // event into key events.
    Component source;

    source = getClientComponent();
    if (source != null) {
        InputMethodEvent event = new InputMethodEvent(source,
                id, text, committedCharacterCount, caret, visiblePosition);

        if (haveActiveClient() && !useBelowTheSpotInput()) {
            source.dispatchEvent(event);
        } else {
            getCompositionAreaHandler(true).processInputMethodEvent(event);
        }
    }
}
 
Example 16
Source Project: jdk8u60   Source File: X11InputMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Flushes composed and committed text held in this context.
 * This method is invoked in the AWT Toolkit (X event loop) thread context
 * and thus inside the AWT Lock.
 */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void flushText() {
    String flush = (committedText != null ? committedText : "");
    if (composedText != null) {
        flush += composedText.toString();
    }

    if (!flush.equals("")) {
        AttributedString attrstr = new AttributedString(flush);
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                             attrstr.getIterator(),
                             flush.length(),
                             null,
                             null,
                             EventQueue.getMostRecentEventTime());
        composedText = null;
        committedText = null;
    }
}
 
Example 17
public void dispatchEvent(AWTEvent event) {
    // some host input method adapters may dispatch input method events
    // through the Java event queue. If the component that the event is
    // intended for isn't an active client, or if we're using below-the-spot
    // input, we need to dispatch this event
    // to the input window. Note that that component is not necessarily the
    // current client component, since we may have switched clients while
    // the event was in the queue.
    if (event instanceof InputMethodEvent) {
        if (((Component) event.getSource()).getInputMethodRequests() == null
                || (useBelowTheSpotInput() && !dispatchingCommittedText)) {
            getCompositionAreaHandler(true).processInputMethodEvent((InputMethodEvent) event);
        }
    } else {
        // make sure we don't dispatch our own key events back to the input method
        if (!dispatchingCommittedText) {
            super.dispatchEvent(event);
        }
    }
}
 
Example 18
/**
 * 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);
}
 
Example 19
/**
 * 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);
}
 
Example 20
/**
 * 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);
}
 
Example 21
public void caretPositionChanged(InputMethodEvent event) {
    if (compositionArea != null) {
        compositionArea.setCaret(event.getCaret());
    }

    // event has been handled, so consume it
    event.consume();
}
 
Example 22
Source Project: Bytecoder   Source File: CompositionAreaHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void caretPositionChanged(InputMethodEvent event) {
    if (compositionArea != null) {
        compositionArea.setCaret(event.getCaret());
    }

    // event has been handled, so consume it
    event.consume();
}
 
Example 23
/**
 * 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);
}
 
Example 24
Source Project: openjdk-8-source   Source File: bug6636983.java    License: GNU General Public License v2.0 5 votes vote down vote up
void sendInputMethodEvent() {
    InputMethodEvent ime = new InputMethodEvent(
            ep,
            InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
            Hiragana_A.getIterator(),
            0,
            null,
            null);
    ep.dispatchEvent(ime);
}
 
Example 25
public void caretPositionChanged(InputMethodEvent event) {
    if (compositionArea != null) {
        compositionArea.setCaret(event.getCaret());
    }

    // event has been handled, so consume it
    event.consume();
}
 
Example 26
/**
 * 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);
}
 
Example 27
void sendInputMethodEvent() {
    InputMethodEvent ime = new InputMethodEvent(
            ep,
            InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
            Hiragana_A.getIterator(),
            0,
            null,
            null);
    ep.dispatchEvent(ime);
}
 
Example 28
Source Project: jdk8u_jdk   Source File: bug6636983.java    License: GNU General Public License v2.0 5 votes vote down vote up
void sendInputMethodEvent() {
    InputMethodEvent ime = new InputMethodEvent(
            ep,
            InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
            Hiragana_A.getIterator(),
            0,
            null,
            null);
    ep.dispatchEvent(ime);
}
 
Example 29
public void caretPositionChanged(InputMethodEvent event) {
    if (compositionArea != null) {
        compositionArea.setCaret(event.getCaret());
    }

    // event has been handled, so consume it
    event.consume();
}
 
Example 30
Source Project: jdk8u60   Source File: CodePointInputMethod.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}