ContainerOrderFocusTraversalPolicy.java revision 1336
2976N/A * Copyright 2000-2003 Sun Microsystems, Inc. All Rights Reserved. 2976N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2976N/A * This code is free software; you can redistribute it and/or modify it 2976N/A * under the terms of the GNU General Public License version 2 only, as 2976N/A * published by the Free Software Foundation. Sun designates this 2976N/A * particular file as subject to the "Classpath" exception as provided 2976N/A * by Sun in the LICENSE file that accompanied this code. 2976N/A * This code is distributed in the hope that it will be useful, but WITHOUT 2976N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2976N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2976N/A * version 2 for more details (a copy is included in the LICENSE file that 2976N/A * You should have received a copy of the GNU General Public License version 2976N/A * 2 along with this work; if not, write to the Free Software Foundation, 2976N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2976N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2976N/A * CA 95054 USA or visit www.sun.com if you need additional information or 3824N/A * A FocusTraversalPolicy that determines traversal order based on the order 2976N/A * of child Components in a Container. From a particular focus cycle root, the 2976N/A * policy makes a pre-order traversal of the Component hierarchy, and traverses 2976N/A * a Container's children according to the ordering of the array returned by 2976N/A * <code>Container.getComponents()</code>. Portions of the hierarchy that are 2976N/A * not visible and displayable will not be searched. 2976N/A * By default, ContainerOrderFocusTraversalPolicy implicitly transfers focus 2976N/A * down-cycle. That is, during normal forward focus traversal, the Component 6238N/A * traversed after a focus cycle root will be the focus-cycle-root's default 2976N/A * Component to focus. This behavior can be disabled using the 2976N/A * <code>setImplicitDownCycleTraversal</code> method. 2976N/A * By default, methods of this class with return a Component only if it is 3824N/A * visible, displayable, enabled, and focusable. Subclasses can modify this 3824N/A * behavior by overriding the <code>accept</code> method. 3824N/A * This policy takes into account <a 3842N/A * if a focus traversal policy provider is encountered, its focus traversal 3842N/A * policy is used to perform the search operation. 2976N/A * @see Container#getComponents 2976N/A * Used by getComponentAfter and getComponentBefore for efficiency. In 2976N/A * order to maintain compliance with the specification of 2976N/A * FocusTraversalPolicy, if traversal wraps, we should invoke 2976N/A * getFirstComponent or getLastComponent. These methods may be overriden in 2976N/A * subclasses to behave in a non-generic way. However, in the generic case, 2976N/A * these methods will simply return the first or last Components of the 2976N/A * sorted list, respectively. Since getComponentAfter and 2976N/A * getComponentBefore have already built the list before determining 6238N/A * that they need to invoke getFirstComponent or getLastComponent, the 5022N/A * list should be reused if possible. 2976N/A * We suppose to use getFocusTraversalCycle & getComponentIndex methods in order 5022N/A * to divide the policy into two parts: 5636N/A * 1) Making the focus traversal cycle. 5636N/A * The 1st point assumes producing a list of components representing the focus 5636N/A * traversal cycle. The two methods mentioned above should implement this logic. 5636N/A * The 2nd point assumes implementing the common concepts of operating on the 5636N/A * component. These concepts are described in the AWT Focus Spec and they are 5636N/A * applied to the FocusTraversalPolicy in general. 2976N/A * Thus, a descendant of this policy may wish to not reimplement the logic of 2976N/A * the 2nd point but just override the implementation of the 1st one. 5636N/A * A striking example of such a descendant is the javax.swing.SortingFocusTraversalPolicy. 3007N/A * Checks if a new focus cycle takes place and returns a Component to traverse focus to. 2976N/A * @param comp a possible focus cycle root or policy provider 2976N/A * @param traversalDirection the direction of the traversal 2976N/A * @return a Component to traverse focus to if {@code comp} is a root or provider 2976N/A * and implicit down-cycle is set, otherwise {@code null} 2976N/A * Returns the Component that should receive the focus after aComponent. 3449N/A * aContainer must be a focus cycle root of aComponent or a focus traversal policy provider. 3449N/A * By default, ContainerOrderFocusTraversalPolicy implicitly transfers 5636N/A * focus down-cycle. That is, during normal forward focus traversal, the 3449N/A * Component traversed after a focus cycle root will be the focus-cycle- 3449N/A * root's default Component to focus. This behavior can be disabled using 3449N/A * the <code>setImplicitDownCycleTraversal</code> method. 5636N/A * traversal policy provider</a>, the focus is always transferred down-cycle. 5636N/A * @param aContainer a focus cycle root of aComponent or a focus traversal policy provider 5224N/A * @param aComponent a (possibly indirect) child of aContainer, or 2976N/A * @return the Component that should receive the focus after aComponent, or 5636N/A * null if no suitable Component can be found 5218N/A * @throws IllegalArgumentException if aContainer is not a focus cycle 4261N/A * root of aComponent or focus traversal policy provider, or if either aContainer or // 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"). // See if the component is inside of policy provider. // FTP knows how to find component after the given. We don't. // 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. * Returns the Component that should receive the focus before aComponent. * aContainer must be a focus cycle root of aComponent or a <a * @param aContainer a focus cycle root of aComponent or focus traversal policy provider * @param aComponent a (possibly indirect) child of aContainer, or * @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 focus traversal policy provider, or if either aContainer or // See if the component is inside of policy provider. // FTP knows how to find component after the given. We don't. // 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 the provider is traversable it's returned. * Returns the first Component in the traversal cycle. This method is used * to determine the next Component to focus when traversal wraps in the * @param aContainer the focus cycle root or focus traversal policy provider whose first * Component is to be returned * @return the first Component in the traversal cycle of aContainer, * or null if no suitable Component can be found * @throws IllegalArgumentException if aContainer is null * Returns the last Component in the traversal cycle. This method is used * to determine the next Component to focus when traversal wraps in the * @param aContainer the focus cycle root or focus traversal policy provider whose last * Component is to be returned * @return the last Component in the traversal cycle of aContainer, * or null if no suitable Component can be found * @throws IllegalArgumentException if aContainer is null * Returns the default Component to focus. This Component will be the first * to receive focus when traversing down into a new focus traversal cycle * rooted at aContainer. The default implementation of this method * returns the same Component as <code>getFirstComponent</code>. * @param aContainer the focus cycle root or focus traversal policy provider whose default * Component is to be returned * @return the default Component in the traversal cycle of aContainer, * or null if no suitable Component can be found * @see #getFirstComponent * @throws IllegalArgumentException if aContainer is null * Sets whether this ContainerOrderFocusTraversalPolicy transfers focus * down-cycle implicitly. If <code>true</code>, during normal forward focus * traversal, the Component traversed after a focus cycle root will be the * focus-cycle-root's default Component to focus. If <code>false</code>, * the next Component in the focus traversal cycle rooted at the specified * focus cycle root will be traversed instead. The default value for this * property is <code>true</code>. * @param implicitDownCycleTraversal whether this * ContainerOrderFocusTraversalPolicy transfers focus down-cycle * @see #getImplicitDownCycleTraversal * @see #getFirstComponent * Returns whether this ContainerOrderFocusTraversalPolicy transfers focus * down-cycle implicitly. If <code>true</code>, during normal forward focus * traversal, the Component traversed after a focus cycle root will be the * focus-cycle-root's default Component to focus. If <code>false</code>, * the next Component in the focus traversal cycle rooted at the specified * focus cycle root will be traversed instead. * @return whether this ContainerOrderFocusTraversalPolicy transfers focus * @see #setImplicitDownCycleTraversal * @see #getFirstComponent * Determines whether a Component is an acceptable choice as the new * focus owner. By default, this method will accept a Component if and * only if it is visible, displayable, enabled, and focusable. * @param aComponent the Component whose fitness as a focus owner is to * @return <code>true</code> if aComponent is visible, displayable, * enabled, and focusable; <code>false</code> otherwise // Verify that the Component is recursively enabled. Disabling a // heavyweight Container disables its children, whereas disabling // a lightweight Container does not.