/// <summary>
        /// Returns the Component that should receive the focus before aComponent.
        /// aContainer must be a focus cycle root of aComponent or a <a
        /// href="doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus traversal policy
        /// provider</a>.
        /// </summary>
        /// <param name="aContainer"> a focus cycle root of aComponent or focus traversal policy provider </param>
        /// <param name="aComponent"> a (possibly indirect) child of aContainer, or
        ///        aContainer itself </param>
        /// <returns> the Component that should receive the focus before aComponent,
        ///         or null if no suitable Component can be found </returns>
        /// <exception cref="IllegalArgumentException"> if aContainer is not a focus cycle
        ///         root of aComponent or focus traversal policy provider, or if either aContainer or
        ///         aComponent is null </exception>
        public override Component GetComponentBefore(Container aContainer, Component aComponent)
        {
            if (aContainer == null || aComponent == null)
            {
                throw new IllegalArgumentException("aContainer and aComponent cannot be null");
            }
            if (!aContainer.FocusTraversalPolicyProvider && !aContainer.FocusCycleRoot)
            {
                throw new IllegalArgumentException("aContainer should be focus cycle root or focus traversal policy provider");
            }
            else if (aContainer.FocusCycleRoot && !aComponent.IsFocusCycleRoot(aContainer))
            {
                throw new IllegalArgumentException("aContainer is not a focus cycle root of aComponent");
            }

            lock (aContainer.TreeLock)
            {
                if (!(aContainer.Visible && aContainer.Displayable))
                {
                    return(null);
                }

                // 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.FocusTraversalPolicy;
                    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);
                    }
                }

                IList <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    = null;
                Component tryComp = null;

                for (index--; index >= 0; index--)
                {
                    comp = cycle[index];
                    if (comp != aContainer && (tryComp = GetComponentDownCycle(comp, BACKWARD_TRAVERSAL)) != null)
                    {
                        return(tryComp);
                    }
                    else if (Accept(comp))
                    {
                        return(comp);
                    }
                }

                if (aContainer.FocusCycleRoot)
                {
                    this.CachedRoot  = aContainer;
                    this.CachedCycle = cycle;

                    comp = GetLastComponent(aContainer);

                    this.CachedRoot  = null;
                    this.CachedCycle = null;

                    return(comp);
                }
            }
            return(null);
        }