Java Code Examples for java.awt.Component#dispatchEvent()

The following examples show how to use java.awt.Component#dispatchEvent() . 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 check out the related API usage on the sidebar.
Example 1
Source File: InputMethodContext.java    From TencentKona-8 with 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 2
Source File: InputMethodContext.java    From jdk8u-dev-jdk with 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 3
Source File: InputMethodContext.java    From jdk8u60 with 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 4
Source File: InputMethodContext.java    From openjdk-jdk8u with 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 5
Source File: InputMethodContext.java    From jdk8u-jdk with 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 6
Source File: InputMethodContext.java    From openjdk-8-source with 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 7
Source File: InputMethodContext.java    From jdk8u_jdk with 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 8
Source File: SimpleTestStepLocation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void redispatchEvent(MouseEvent e, Component component) {
    Point componentPoint
            = SwingUtilities.convertPoint(glassPane,
                                          e.getPoint(),
                                          component);
    component.dispatchEvent(
            new MouseEvent(component,
                           e.getID(),
                           e.getWhen(),
                           e.getModifiers(),
                           componentPoint.x,
                           componentPoint.y,
                           e.getClickCount(),
                           e.isPopupTrigger()));
}
 
Example 9
Source File: EditableDisplayerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void ctrlPressKey(final Component target, final int key) throws Exception {
    if (SwingUtilities.isEventDispatchThread()) {
        KeyEvent k = new KeyEvent(target, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_MASK, key, (char) key);
        target.dispatchEvent(k);
    } else {
        
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                KeyEvent ke = new KeyEvent(target, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_MASK, key, (char) key);
                target.dispatchEvent(ke);
            }
        });
        sleep();
    }
}
 
Example 10
Source File: KeymapPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void processKeyEvent(KeyEvent e) {

    if (!isEditing())
        super.processKeyEvent(e);
    else {
        Component component = ((DefaultCellEditor) getCellEditor(lastRow, lastColumn)).getComponent();
        component.requestFocus();
        component.dispatchEvent(new KeyEvent(component, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar()));
    }
}
 
Example 11
Source File: JCheckTree.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void processMouseEvent(MouseEvent e) {
    if (e instanceof MouseWheelEvent) {
        Component target = JCheckTree.this.getParent();
        if (target == null || !(target instanceof JViewport))
            target = JCheckTree.this;
        MouseEvent mwe = SwingUtilities.convertMouseEvent(
                JCheckTree.this, (MouseWheelEvent)e, target);
        target.dispatchEvent((MouseWheelEvent)mwe);
    } else {
        super.processMouseEvent((MouseEvent)e);
    }
}
 
Example 12
Source File: InputMethodContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
 
Example 13
Source File: InputMethodContext.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
 
Example 14
Source File: InputMethodContext.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
 
Example 15
Source File: AbstractListUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean redispatchComponent(MouseEvent e) {
    Point p = e.getPoint();
    int index = list.locationToIndex(p);
    if (index < 0 || index >= list.getModel().getSize()) {
        return false;
    }

    ListCellRenderer renderer = list.getCellRenderer();
    if (null == renderer) {
        return false;
    }
    Component renComponent = renderer.getListCellRendererComponent(list, list.getModel().getElementAt(index), index, false, false);
    if (null == renComponent) {
        return false;
    }
    Rectangle rect = list.getCellBounds(index, index);
    if (null == rect) {
        return false;
    }
    renComponent.setBounds(0, 0, rect.width, rect.height);
    renComponent.doLayout();
    Point p3 = rect.getLocation();

    Point p2 = new Point(p.x - p3.x, p.y - p3.y);
    Component dispatchComponent =
            SwingUtilities.getDeepestComponentAt(renComponent,
            p2.x, p2.y);
    if ( e.isPopupTrigger() &&
         dispatchComponent instanceof LinkButton && 
         !((LinkButton)dispatchComponent).isHandlingPopupEvents() ) 
    {
        return false;
    } 
    if (dispatchComponent instanceof AbstractButton) {
        if (!((AbstractButton) dispatchComponent).isEnabled()) {
            return false;
        }
        Point p4 = SwingUtilities.convertPoint(renComponent, p2, dispatchComponent);
        MouseEvent newEvent = new MouseEvent(dispatchComponent,
                e.getID(),
                e.getWhen(),
                e.getModifiers(),
                p4.x, p4.y,
                e.getClickCount(),
                e.isPopupTrigger(),
                MouseEvent.NOBUTTON);
        dispatchComponent.dispatchEvent(newEvent);
        list.repaint(rect);
        e.consume();
        return true;
    }
    return false;
}
 
Example 16
Source File: InputMethodContext.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
 
Example 17
Source File: InputMethodContext.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
 
Example 18
Source File: InputMethodContext.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
 
Example 19
Source File: InputMethodContext.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
 
Example 20
Source File: InputMethodContext.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}