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

The following examples show how to use java.awt.Component#isDisplayable() . 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
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 2
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 3
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 4
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 5
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 6
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 7
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 8
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 9
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 10
private boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          aComponent.isFocusable() && aComponent.isEnabled())) {
        return false;
    }

    // Verify that the Component is recursively enabled. Disabling a
    // heavyweight Container disables its children, whereas disabling
    // a lightweight Container does not.
    if (!(aComponent instanceof Window)) {
        for (Container enableTest = aComponent.getParent();
             enableTest != null;
             enableTest = enableTest.getParent())
        {
            if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                return false;
            }
            if (enableTest instanceof Window) {
                break;
            }
        }
    }

    return true;
}
 
Example 11
@SuppressWarnings("deprecation")
public static boolean deliverFocus(Component lightweightChild,
                                   Component target,
                                   boolean temporary,
                                   boolean focusedWindowChangeAllowed,
                                   long time,
                                   FocusEvent.Cause cause,
                                   Component currentFocusOwner) // provided by the descendant peers
{
    if (lightweightChild == null) {
        lightweightChild = target;
    }

    Component currentOwner = currentFocusOwner;
    if (currentOwner != null && !currentOwner.isDisplayable()) {
        currentOwner = null;
    }
    if (currentOwner != null) {
        FocusEvent fl = new FocusEvent(currentOwner, FocusEvent.FOCUS_LOST,
                                             false, lightweightChild, cause);

        if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
            focusLog.finer("Posting focus event: " + fl);
        }
        SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl);
    }

    FocusEvent fg = new FocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED,
                                         false, currentOwner, cause);

    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
        focusLog.finer("Posting focus event: " + fg);
    }
    SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg);
    return true;
}
 
Example 12
/**
 * 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 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
/**
 * 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 15
/**
 * 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 16
/**
 * 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 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
Source Project: Bytecoder   File: InputContext.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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
/**
 * 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;
            }
        }
    }
}