/// <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); }
/// <summary> /// Returns the Component that should receive the focus after aComponent. /// aContainer must be a focus cycle root of aComponent or a focus traversal policy provider. /// <para> /// By default, ContainerOrderFocusTraversalPolicy implicitly transfers /// focus down-cycle. That is, during normal forward 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. /// </para> /// <para> /// If aContainer is <a href="doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus /// traversal policy provider</a>, the focus is always transferred down-cycle. /// /// </para> /// </summary> /// <param name="aContainer"> a focus cycle root of aComponent or a 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 after 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 GetComponentAfter(Container aContainer, Component aComponent) { if (Log.isLoggable(PlatformLogger.Level.FINE)) { Log.fine("### Searching in " + aContainer + " for component after " + 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); } // Before all the ckecks below we first see if it's an FTP provider or a focus cycle root. // If it's the case just go down cycle (if it's set to "implicit"). Component comp = GetComponentDownCycle(aComponent, FORWARD_TRAVERSAL); if (comp != null) { return(comp); } // 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 afterComp = policy.GetComponentAfter(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 (afterComp != null) { if (Log.isLoggable(PlatformLogger.Level.FINE)) { Log.fine("### FTP returned " + afterComp); } return(afterComp); } aComponent = provider; } 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(GetFirstComponent(aContainer)); } for (index++; index < cycle.Count; index++) { comp = cycle[index]; if (Accept(comp)) { return(comp); } else if ((comp = GetComponentDownCycle(comp, FORWARD_TRAVERSAL)) != null) { return(comp); } } if (aContainer.FocusCycleRoot) { this.CachedRoot = aContainer; this.CachedCycle = cycle; comp = GetFirstComponent(aContainer); this.CachedRoot = null; this.CachedCycle = null; return(comp); } } return(null); }