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

The following examples show how to use java.awt.Component#isFocusCycleRoot() . 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: SortingFocusTraversalPolicy.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 2
Source File: SortingFocusTraversalPolicy.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 3
Source File: SortingFocusTraversalPolicy.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 4
Source File: SortingFocusTraversalPolicy.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 5
Source File: SortingFocusTraversalPolicy.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 6
Source File: SortingFocusTraversalPolicy.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 7
Source File: SortingFocusTraversalPolicy.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 8
Source File: SortingFocusTraversalPolicy.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 9
Source File: SortingFocusTraversalPolicy.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 10
Source File: SortingFocusTraversalPolicy.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 11
Source File: SortingFocusTraversalPolicy.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 12
Source File: SortingFocusTraversalPolicy.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 13
Source File: SortingFocusTraversalPolicy.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 14
Source File: SortingFocusTraversalPolicy.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 15
Source File: SortingFocusTraversalPolicy.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 16
Source File: SortingFocusTraversalPolicy.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}
 
Example 17
Source File: SortingFocusTraversalPolicy.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the Component that should receive the focus before aComponent.
 * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider.
 * <p>
 * By default, SortingFocusTraversalPolicy implicitly transfers focus down-
 * cycle. That is, during normal focus traversal, the Component
 * traversed after a focus cycle root will be the focus-cycle-root's
 * default Component to focus. This behavior can be disabled using the
 * <code>setImplicitDownCycleTraversal</code> method.
 * <p>
 * If aContainer is <a href="../../java/awt/doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus
 * traversal policy provider</a>, the focus is always transferred down-cycle.
 *
 * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider
 * @param aComponent a (possibly indirect) child of aContainer, or
 *        aContainer itself
 * @return the Component that should receive the focus before aComponent,
 *         or null if no suitable Component can be found
 * @throws IllegalArgumentException if aContainer is not a focus cycle
 *         root of aComponent or a focus traversal policy provider, or if either aContainer or
 *         aComponent is null
 */
public Component getComponentBefore(Container aContainer, Component aComponent) {
    if (aContainer == null || aComponent == null) {
        throw new IllegalArgumentException("aContainer and aComponent cannot be null");
    }
    if (!aContainer.isFocusTraversalPolicyProvider() && !aContainer.isFocusCycleRoot()) {
        throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");

    } else if (aContainer.isFocusCycleRoot() && !aComponent.isFocusCycleRoot(aContainer)) {
        throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
    }

    // See if the component is inside of policy provider.
    Container provider = getTopmostProvider(aContainer, aComponent);
    if (provider != null) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Asking FTP " + provider + " for component after " + aComponent);
        }

        // FTP knows how to find component after the given. We don't.
        FocusTraversalPolicy policy = provider.getFocusTraversalPolicy();
        Component beforeComp = policy.getComponentBefore(provider, aComponent);

        // Null result means that we overstepped the limit of the FTP's cycle.
        // In that case we must quit the cycle, otherwise return the component found.
        if (beforeComp != null) {
            if (log.isLoggable(PlatformLogger.Level.FINE)) {
                log.fine("### FTP returned " + beforeComp);
            }
            return beforeComp;
        }
        aComponent = provider;

        // If the provider is traversable it's returned.
        if (accept(aComponent)) {
            return aComponent;
        }
    }

    List<Component> cycle = getFocusTraversalCycle(aContainer);

    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("### Cycle is " + cycle + ", component is " + aComponent);
    }

    int index = getComponentIndex(cycle, aComponent);

    if (index < 0) {
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
            log.fine("### Didn't find component " + aComponent + " in a cycle " + aContainer);
        }
        return getLastComponent(aContainer);
    }

    Component comp;
    Component tryComp;

    for (index--; index>=0; index--) {
        comp = cycle.get(index);
        if (comp != aContainer && (tryComp = getComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null) {
            return tryComp;
        } else if (accept(comp)) {
            return comp;
        }
    }

    if (aContainer.isFocusCycleRoot()) {
        this.cachedRoot = aContainer;
        this.cachedCycle = cycle;

        comp = getLastComponent(aContainer);

        this.cachedRoot = null;
        this.cachedCycle = null;

        return comp;
    }
    return null;
}