Java Code Examples for java.awt.peer.ComponentPeer#isFocusable()

The following examples show how to use java.awt.peer.ComponentPeer#isFocusable() . 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: KeyboardFocusManagerPeerImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? acc.getPeer(component) : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick && acc.canBeFocusOwner(component);
}
 
Example 2
Source File: KeyboardFocusManagerPeerImpl.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? acc.getPeer(component) : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick && acc.canBeFocusOwner(component);
}
 
Example 3
Source File: DefaultFocusTraversalPolicy.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * <code>Component.isFocusTraversable()</code> or
 * <code>Component.isFocusable()</code>, or by calling
 * <code>Component.setFocusable()</code>, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return <code>true</code> if aComponent meets the above requirements;
 *         <code>false</code> otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.getPeer();
    return (peer != null && peer.isFocusable());
}
 
Example 4
Source File: DefaultFocusTraversalPolicy.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * <code>Component.isFocusTraversable()</code> or
 * <code>Component.isFocusable()</code>, or by calling
 * <code>Component.setFocusable()</code>, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return <code>true</code> if aComponent meets the above requirements;
 *         <code>false</code> otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.getPeer();
    return (peer != null && peer.isFocusable());
}
 
Example 5
Source File: KeyboardFocusManagerPeerImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? component.getPeer() : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick &&
           AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}
 
Example 6
Source File: KeyboardFocusManagerPeerImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? component.getPeer() : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick &&
           AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}
 
Example 7
Source File: DefaultFocusTraversalPolicy.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * <code>Component.isFocusTraversable()</code> or
 * <code>Component.isFocusable()</code>, or by calling
 * <code>Component.setFocusable()</code>, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return <code>true</code> if aComponent meets the above requirements;
 *         <code>false</code> otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.getPeer();
    return (peer != null && peer.isFocusable());
}
 
Example 8
Source File: DefaultFocusTraversalPolicy.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * {@code Component.isFocusTraversable()} or
 * {@code Component.isFocusable()}, or by calling
 * {@code Component.setFocusable()}, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return {@code true} if aComponent meets the above requirements;
 *         {@code false} otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.peer;
    return (peer != null && peer.isFocusable());
}
 
Example 9
Source File: DefaultFocusTraversalPolicy.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * {@code Component.isFocusTraversable()} or
 * {@code Component.isFocusable()}, or by calling
 * {@code Component.setFocusable()}, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return {@code true} if aComponent meets the above requirements;
 *         {@code false} otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.peer;
    return (peer != null && peer.isFocusable());
}
 
Example 10
Source File: DefaultFocusTraversalPolicy.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * <code>Component.isFocusTraversable()</code> or
 * <code>Component.isFocusable()</code>, or by calling
 * <code>Component.setFocusable()</code>, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return <code>true</code> if aComponent meets the above requirements;
 *         <code>false</code> otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.getPeer();
    return (peer != null && peer.isFocusable());
}
 
Example 11
Source File: KeyboardFocusManagerPeerImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? component.getPeer() : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick &&
           AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}
 
Example 12
Source File: DefaultFocusTraversalPolicy.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * <code>Component.isFocusTraversable()</code> or
 * <code>Component.isFocusable()</code>, or by calling
 * <code>Component.setFocusable()</code>, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return <code>true</code> if aComponent meets the above requirements;
 *         <code>false</code> otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.getPeer();
    return (peer != null && peer.isFocusable());
}
 
Example 13
Source File: DefaultFocusTraversalPolicy.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * <code>Component.isFocusTraversable()</code> or
 * <code>Component.isFocusable()</code>, or by calling
 * <code>Component.setFocusable()</code>, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return <code>true</code> if aComponent meets the above requirements;
 *         <code>false</code> otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.getPeer();
    return (peer != null && peer.isFocusable());
}
 
Example 14
Source File: DefaultFocusTraversalPolicy.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * <code>Component.isFocusTraversable()</code> or
 * <code>Component.isFocusable()</code>, or by calling
 * <code>Component.setFocusable()</code>, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return <code>true</code> if aComponent meets the above requirements;
 *         <code>false</code> otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.getPeer();
    return (peer != null && peer.isFocusable());
}
 
Example 15
Source File: KeyboardFocusManagerPeerImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? component.getPeer() : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick &&
           AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}
 
Example 16
Source File: DefaultFocusTraversalPolicy.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * <code>Component.isFocusTraversable()</code> or
 * <code>Component.isFocusable()</code>, or by calling
 * <code>Component.setFocusable()</code>, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return <code>true</code> if aComponent meets the above requirements;
 *         <code>false</code> otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.getPeer();
    return (peer != null && peer.isFocusable());
}
 
Example 17
Source File: KeyboardFocusManagerPeerImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? component.getPeer() : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick &&
           AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}
 
Example 18
Source File: KeyboardFocusManagerPeerImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? component.getPeer() : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick &&
           AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}
 
Example 19
Source File: DefaultFocusTraversalPolicy.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a Component is an acceptable choice as the new
 * focus owner. The Component must be visible, displayable, and enabled
 * to be accepted. If client code has explicitly set the focusability
 * of the Component by either overriding
 * <code>Component.isFocusTraversable()</code> or
 * <code>Component.isFocusable()</code>, or by calling
 * <code>Component.setFocusable()</code>, then the Component will be
 * accepted if and only if it is focusable. If, however, the Component is
 * relying on default focusability, then all Canvases, Labels, Panels,
 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
 * rejected.
 *
 * @param aComponent the Component whose fitness as a focus owner is to
 *        be tested
 * @return <code>true</code> if aComponent meets the above requirements;
 *         <code>false</code> otherwise
 */
protected boolean accept(Component aComponent) {
    if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
          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;
            }
        }
    }

    boolean focusable = aComponent.isFocusable();
    if (aComponent.isFocusTraversableOverridden()) {
        return focusable;
    }

    ComponentPeer peer = aComponent.getPeer();
    return (peer != null && peer.isFocusable());
}
 
Example 20
Source File: KeyboardFocusManagerPeerImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static boolean shouldFocusOnClick(Component component) {
    boolean acceptFocusOnClick = false;

    // A component is generally allowed to accept focus on click
    // if its peer is focusable. There're some exceptions though.


    // CANVAS & SCROLLBAR accept focus on click
    if (component instanceof Canvas ||
        component instanceof Scrollbar)
    {
        acceptFocusOnClick = true;

    // PANEL, empty only, accepts focus on click
    } else if (component instanceof Panel) {
        acceptFocusOnClick = (((Panel)component).getComponentCount() == 0);


    // Other components
    } else {
        ComponentPeer peer = (component != null ? component.getPeer() : null);
        acceptFocusOnClick = (peer != null ? peer.isFocusable() : false);
    }
    return acceptFocusOnClick &&
           AWTAccessor.getComponentAccessor().canBeFocusOwner(component);
}