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

The following examples show how to use java.awt.Component#getInputMethodRequests() . 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 check out the related API usage on the sidebar.
Example 1
/**
 * Creates the composition area.
 */
private void createCompositionArea() {
    synchronized(compositionAreaLock) {
        compositionArea = new CompositionArea();
        if (compositionAreaOwner != null) {
            compositionArea.setHandlerInfo(compositionAreaOwner, inputMethodContext);
        }
        // If the client component is an active client using below-the-spot style, then
        // make the composition window undecorated without a title bar.
        Component client = clientComponent.get();
        if(client != null){
            InputMethodRequests req = client.getInputMethodRequests();
            if (req != null && inputMethodContext.useBelowTheSpotInput()) {
                setCompositionAreaUndecorated(true);
            }
        }
    }
}
 
Example 2
/**
 * Creates the composition area.
 */
private void createCompositionArea() {
    synchronized(compositionAreaLock) {
        compositionArea = new CompositionArea();
        if (compositionAreaOwner != null) {
            compositionArea.setHandlerInfo(compositionAreaOwner, inputMethodContext);
        }
        // If the client component is an active client using below-the-spot style, then
        // make the composition window undecorated without a title bar.
        Component client = clientComponent.get();
        if(client != null){
            InputMethodRequests req = client.getInputMethodRequests();
            if (req != null && inputMethodContext.useBelowTheSpotInput()) {
                setCompositionAreaUndecorated(true);
            }
        }
    }
}
 
Example 3
/**
 * Creates the composition area.
 */
private void createCompositionArea() {
    synchronized(compositionAreaLock) {
        compositionArea = new CompositionArea();
        if (compositionAreaOwner != null) {
            compositionArea.setHandlerInfo(compositionAreaOwner, inputMethodContext);
        }
        // If the client component is an active client using below-the-spot style, then
        // make the composition window undecorated without a title bar.
        Component client = clientComponent.get();
        if(client != null){
            InputMethodRequests req = client.getInputMethodRequests();
            if (req != null && inputMethodContext.useBelowTheSpotInput()) {
                setCompositionAreaUndecorated(true);
            }
        }
    }
}
 
Example 4
/**
 * Returns the input method request handler of the client component.
 * When using the composition window for an active client (below-the-spot
 * input), input method requests that do not relate to the display of
 * the composed text are forwarded to the client component.
 */
InputMethodRequests getClientInputMethodRequests() {
    Component client = clientComponent.get();
    if (client != null) {
        return client.getInputMethodRequests();
    }

    return null;
}
 
Example 5
/**
 * Returns the input method request handler of the client component.
 * When using the composition window for an active client (below-the-spot
 * input), input method requests that do not relate to the display of
 * the composed text are forwarded to the client component.
 */
InputMethodRequests getClientInputMethodRequests() {
    Component client = clientComponent.get();
    if (client != null) {
        return client.getInputMethodRequests();
    }

    return null;
}
 
Example 6
/**
 * Returns the input method request handler of the client component.
 * When using the composition window for an active client (below-the-spot
 * input), input method requests that do not relate to the display of
 * the composed text are forwarded to the client component.
 */
InputMethodRequests getClientInputMethodRequests() {
    Component client = clientComponent.get();
    if (client != null) {
        return client.getInputMethodRequests();
    }

    return null;
}
 
Example 7
/**
 * Returns the input method request handler of the client component.
 * When using the composition window for an active client (below-the-spot
 * input), input method requests that do not relate to the display of
 * the composed text are forwarded to the client component.
 */
InputMethodRequests getClientInputMethodRequests() {
    Component client = clientComponent.get();
    if (client != null) {
        return client.getInputMethodRequests();
    }

    return null;
}
 
Example 8
/**
 * Handles focus gained events for any component that's using
 * this input context.
 * These events are generated by AWT when the keyboard focus
 * moves to a component.
 * Besides actual client components, the source components
 * may also be the composition area or any component in an
 * input method window.
 * <p>
 * When handling the focus event for a client component, this
 * method checks whether the input context was previously
 * active for a different client component, and if so, calls
 * endComposition for the previous client component.
 *
 * @param source the component gaining the focus
 */
private void focusGained(Component source) {

    /*
     * NOTE: When a Container is removing its Component which
     * invokes this.removeNotify(), the Container has the global
     * Component lock. It is possible to happen that an
     * application thread is calling this.removeNotify() while an
     * AWT event queue thread is dispatching a focus event via
     * this.dispatchEvent(). If an input method uses AWT
     * components (e.g., IIIMP status window), it causes deadlock,
     * for example, Component.show()/hide() in this situation
     * because hide/show tried to obtain the lock.  Therefore,
     * it's necessary to obtain the global Component lock before
     * activating or deactivating an input method.
     */
    synchronized (source.getTreeLock()) {
        synchronized (this) {
            if ("sun.awt.im.CompositionArea".equals(source.getClass().getName())) {
                // no special handling for this one
            } else if (getComponentWindow(source) instanceof InputMethodWindow) {
                // no special handling for this one either
            } else {
                if (!source.isDisplayable()) {
                    // Component is being disposed
                    return;
                }

                // Focus went to a real client component.
                // Check whether we're switching between client components
                // that share an input context. We can't do that earlier
                // than here because we don't want to end composition
                // until we really know we're switching to a different component
                if (inputMethod != null) {
                    if (currentClientComponent != null && currentClientComponent != source) {
                        if (!isInputMethodActive) {
                            activateInputMethod(false);
                        }
                        endComposition();
                        deactivateInputMethod(false);
                    }
                }

                currentClientComponent = source;
            }

            awtFocussedComponent = source;
            if (inputMethod instanceof InputMethodAdapter) {
                ((InputMethodAdapter) inputMethod).setAWTFocussedComponent(source);
            }

            // it's possible that the input method is still active because
            // we suppressed a deactivate cause by an input method window
            // coming up
            if (!isInputMethodActive) {
                activateInputMethod(true);
            }


            // If the client component is an active client with the below-the-spot
            // input style, then make the composition window undecorated without a title bar.
            InputMethodContext inputContext = ((InputMethodContext)this);
            if (!inputContext.isCompositionAreaVisible()) {
                  InputMethodRequests req = source.getInputMethodRequests();
                  if (req != null && inputContext.useBelowTheSpotInput()) {
                      inputContext.setCompositionAreaUndecorated(true);
                  } else {
                      inputContext.setCompositionAreaUndecorated(false);
                  }
            }
            // restores the composition area if it was set to invisible
            // when focus got lost
            if (compositionAreaHidden == true) {
                ((InputMethodContext)this).setCompositionAreaVisible(true);
                compositionAreaHidden = false;
            }
        }
    }
}
 
Example 9
private boolean haveActiveClient() {
    Component client = getClientComponent();
    return client != null
           && client.getInputMethodRequests() != null;
}
 
Example 10
/**
 * 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 11
private boolean haveActiveClient() {
    Component client = getClientComponent();
    return client != null
           && client.getInputMethodRequests() != null;
}
 
Example 12
/**
 * 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
/**
 * Handles focus gained events for any component that's using
 * this input context.
 * These events are generated by AWT when the keyboard focus
 * moves to a component.
 * Besides actual client components, the source components
 * may also be the composition area or any component in an
 * input method window.
 * <p>
 * When handling the focus event for a client component, this
 * method checks whether the input context was previously
 * active for a different client component, and if so, calls
 * endComposition for the previous client component.
 *
 * @param source the component gaining the focus
 */
private void focusGained(Component source) {

    /*
     * NOTE: When a Container is removing its Component which
     * invokes this.removeNotify(), the Container has the global
     * Component lock. It is possible to happen that an
     * application thread is calling this.removeNotify() while an
     * AWT event queue thread is dispatching a focus event via
     * this.dispatchEvent(). If an input method uses AWT
     * components (e.g., IIIMP status window), it causes deadlock,
     * for example, Component.show()/hide() in this situation
     * because hide/show tried to obtain the lock.  Therefore,
     * it's necessary to obtain the global Component lock before
     * activating or deactivating an input method.
     */
    synchronized (source.getTreeLock()) {
        synchronized (this) {
            if ("sun.awt.im.CompositionArea".equals(source.getClass().getName())) {
                // no special handling for this one
            } else if (getComponentWindow(source) instanceof InputMethodWindow) {
                // no special handling for this one either
            } else {
                if (!source.isDisplayable()) {
                    // Component is being disposed
                    return;
                }

                // Focus went to a real client component.
                // Check whether we're switching between client components
                // that share an input context. We can't do that earlier
                // than here because we don't want to end composition
                // until we really know we're switching to a different component
                if (inputMethod != null) {
                    if (currentClientComponent != null && currentClientComponent != source) {
                        if (!isInputMethodActive) {
                            activateInputMethod(false);
                        }
                        endComposition();
                        deactivateInputMethod(false);
                    }
                }

                currentClientComponent = source;
            }

            awtFocussedComponent = source;
            if (inputMethod instanceof InputMethodAdapter) {
                ((InputMethodAdapter) inputMethod).setAWTFocussedComponent(source);
            }

            // it's possible that the input method is still active because
            // we suppressed a deactivate cause by an input method window
            // coming up
            if (!isInputMethodActive) {
                activateInputMethod(true);
            }


            // If the client component is an active client with the below-the-spot
            // input style, then make the composition window undecorated without a title bar.
            InputMethodContext inputContext = ((InputMethodContext)this);
            if (!inputContext.isCompositionAreaVisible()) {
                  InputMethodRequests req = source.getInputMethodRequests();
                  if (req != null && inputContext.useBelowTheSpotInput()) {
                      inputContext.setCompositionAreaUndecorated(true);
                  } else {
                      inputContext.setCompositionAreaUndecorated(false);
                  }
            }
            // restores the composition area if it was set to invisible
            // when focus got lost
            if (compositionAreaHidden == true) {
                ((InputMethodContext)this).setCompositionAreaVisible(true);
                compositionAreaHidden = false;
            }
        }
    }
}
 
Example 14
/**
 * 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
/**
 * 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 16
/**
 * 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
/**
 * Handles focus gained events for any component that's using
 * this input context.
 * These events are generated by AWT when the keyboard focus
 * moves to a component.
 * Besides actual client components, the source components
 * may also be the composition area or any component in an
 * input method window.
 * <p>
 * When handling the focus event for a client component, this
 * method checks whether the input context was previously
 * active for a different client component, and if so, calls
 * endComposition for the previous client component.
 *
 * @param source the component gaining the focus
 */
private void focusGained(Component source) {

    /*
     * NOTE: When a Container is removing its Component which
     * invokes this.removeNotify(), the Container has the global
     * Component lock. It is possible to happen that an
     * application thread is calling this.removeNotify() while an
     * AWT event queue thread is dispatching a focus event via
     * this.dispatchEvent(). If an input method uses AWT
     * components (e.g., IIIMP status window), it causes deadlock,
     * for example, Component.show()/hide() in this situation
     * because hide/show tried to obtain the lock.  Therefore,
     * it's necessary to obtain the global Component lock before
     * activating or deactivating an input method.
     */
    synchronized (source.getTreeLock()) {
        synchronized (this) {
            if ("sun.awt.im.CompositionArea".equals(source.getClass().getName())) {
                // no special handling for this one
            } else if (getComponentWindow(source) instanceof InputMethodWindow) {
                // no special handling for this one either
            } else {
                if (!source.isDisplayable()) {
                    // Component is being disposed
                    return;
                }

                // Focus went to a real client component.
                // Check whether we're switching between client components
                // that share an input context. We can't do that earlier
                // than here because we don't want to end composition
                // until we really know we're switching to a different component
                if (inputMethod != null) {
                    if (currentClientComponent != null && currentClientComponent != source) {
                        if (!isInputMethodActive) {
                            activateInputMethod(false);
                        }
                        endComposition();
                        deactivateInputMethod(false);
                    }
                }

                currentClientComponent = source;
            }

            awtFocussedComponent = source;
            if (inputMethod instanceof InputMethodAdapter) {
                ((InputMethodAdapter) inputMethod).setAWTFocussedComponent(source);
            }

            // it's possible that the input method is still active because
            // we suppressed a deactivate cause by an input method window
            // coming up
            if (!isInputMethodActive) {
                activateInputMethod(true);
            }


            // If the client component is an active client with the below-the-spot
            // input style, then make the composition window undecorated without a title bar.
            InputMethodContext inputContext = ((InputMethodContext)this);
            if (!inputContext.isCompositionAreaVisible()) {
                  InputMethodRequests req = source.getInputMethodRequests();
                  if (req != null && inputContext.useBelowTheSpotInput()) {
                      inputContext.setCompositionAreaUndecorated(true);
                  } else {
                      inputContext.setCompositionAreaUndecorated(false);
                  }
            }
            // restores the composition area if it was set to invisible
            // when focus got lost
            if (compositionAreaHidden == true) {
                ((InputMethodContext)this).setCompositionAreaVisible(true);
                compositionAreaHidden = false;
            }
        }
    }
}
 
Example 18
/**
 * Handles focus gained events for any component that's using
 * this input context.
 * These events are generated by AWT when the keyboard focus
 * moves to a component.
 * Besides actual client components, the source components
 * may also be the composition area or any component in an
 * input method window.
 * <p>
 * When handling the focus event for a client component, this
 * method checks whether the input context was previously
 * active for a different client component, and if so, calls
 * endComposition for the previous client component.
 *
 * @param source the component gaining the focus
 */
private void focusGained(Component source) {

    /*
     * NOTE: When a Container is removing its Component which
     * invokes this.removeNotify(), the Container has the global
     * Component lock. It is possible to happen that an
     * application thread is calling this.removeNotify() while an
     * AWT event queue thread is dispatching a focus event via
     * this.dispatchEvent(). If an input method uses AWT
     * components (e.g., IIIMP status window), it causes deadlock,
     * for example, Component.show()/hide() in this situation
     * because hide/show tried to obtain the lock.  Therefore,
     * it's necessary to obtain the global Component lock before
     * activating or deactivating an input method.
     */
    synchronized (source.getTreeLock()) {
        synchronized (this) {
            if ("sun.awt.im.CompositionArea".equals(source.getClass().getName())) {
                // no special handling for this one
            } else if (getComponentWindow(source) instanceof InputMethodWindow) {
                // no special handling for this one either
            } else {
                if (!source.isDisplayable()) {
                    // Component is being disposed
                    return;
                }

                // Focus went to a real client component.
                // Check whether we're switching between client components
                // that share an input context. We can't do that earlier
                // than here because we don't want to end composition
                // until we really know we're switching to a different component
                if (inputMethod != null) {
                    if (currentClientComponent != null && currentClientComponent != source) {
                        if (!isInputMethodActive) {
                            activateInputMethod(false);
                        }
                        endComposition();
                        deactivateInputMethod(false);
                    }
                }

                currentClientComponent = source;
            }

            awtFocussedComponent = source;
            if (inputMethod instanceof InputMethodAdapter) {
                ((InputMethodAdapter) inputMethod).setAWTFocussedComponent(source);
            }

            // it's possible that the input method is still active because
            // we suppressed a deactivate cause by an input method window
            // coming up
            if (!isInputMethodActive) {
                activateInputMethod(true);
            }


            // If the client component is an active client with the below-the-spot
            // input style, then make the composition window undecorated without a title bar.
            InputMethodContext inputContext = ((InputMethodContext)this);
            if (!inputContext.isCompositionAreaVisible()) {
                  InputMethodRequests req = source.getInputMethodRequests();
                  if (req != null && inputContext.useBelowTheSpotInput()) {
                      inputContext.setCompositionAreaUndecorated(true);
                  } else {
                      inputContext.setCompositionAreaUndecorated(false);
                  }
            }
            // restores the composition area if it was set to invisible
            // when focus got lost
            if (compositionAreaHidden == true) {
                ((InputMethodContext)this).setCompositionAreaVisible(true);
                compositionAreaHidden = false;
            }
        }
    }
}
 
Example 19
/**
 * Handles focus gained events for any component that's using
 * this input context.
 * These events are generated by AWT when the keyboard focus
 * moves to a component.
 * Besides actual client components, the source components
 * may also be the composition area or any component in an
 * input method window.
 * <p>
 * When handling the focus event for a client component, this
 * method checks whether the input context was previously
 * active for a different client component, and if so, calls
 * endComposition for the previous client component.
 *
 * @param source the component gaining the focus
 */
private void focusGained(Component source) {

    /*
     * NOTE: When a Container is removing its Component which
     * invokes this.removeNotify(), the Container has the global
     * Component lock. It is possible to happen that an
     * application thread is calling this.removeNotify() while an
     * AWT event queue thread is dispatching a focus event via
     * this.dispatchEvent(). If an input method uses AWT
     * components (e.g., IIIMP status window), it causes deadlock,
     * for example, Component.show()/hide() in this situation
     * because hide/show tried to obtain the lock.  Therefore,
     * it's necessary to obtain the global Component lock before
     * activating or deactivating an input method.
     */
    synchronized (source.getTreeLock()) {
        synchronized (this) {
            if ("sun.awt.im.CompositionArea".equals(source.getClass().getName())) {
                // no special handling for this one
            } else if (getComponentWindow(source) instanceof InputMethodWindow) {
                // no special handling for this one either
            } else {
                if (!source.isDisplayable()) {
                    // Component is being disposed
                    return;
                }

                // Focus went to a real client component.
                // Check whether we're switching between client components
                // that share an input context. We can't do that earlier
                // than here because we don't want to end composition
                // until we really know we're switching to a different component
                if (inputMethod != null) {
                    if (currentClientComponent != null && currentClientComponent != source) {
                        if (!isInputMethodActive) {
                            activateInputMethod(false);
                        }
                        endComposition();
                        deactivateInputMethod(false);
                    }
                }

                currentClientComponent = source;
            }

            awtFocussedComponent = source;
            if (inputMethod instanceof InputMethodAdapter) {
                ((InputMethodAdapter) inputMethod).setAWTFocussedComponent(source);
            }

            // it's possible that the input method is still active because
            // we suppressed a deactivate cause by an input method window
            // coming up
            if (!isInputMethodActive) {
                activateInputMethod(true);
            }


            // If the client component is an active client with the below-the-spot
            // input style, then make the composition window undecorated without a title bar.
            InputMethodContext inputContext = ((InputMethodContext)this);
            if (!inputContext.isCompositionAreaVisible()) {
                  InputMethodRequests req = source.getInputMethodRequests();
                  if (req != null && inputContext.useBelowTheSpotInput()) {
                      inputContext.setCompositionAreaUndecorated(true);
                  } else {
                      inputContext.setCompositionAreaUndecorated(false);
                  }
            }
            // restores the composition area if it was set to invisible
            // when focus got lost
            if (compositionAreaHidden == true) {
                ((InputMethodContext)this).setCompositionAreaVisible(true);
                compositionAreaHidden = false;
            }
        }
    }
}
 
Example 20
/**
 * 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;
    }
}