45 * By default, methods of this class will return a Component only if it is 46 * visible, displayable, enabled, and focusable. Subclasses can modify this 47 * behavior by overriding the <code>accept</code> method. 48 * <p> 49 * This policy takes into account <a 50 * href="doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus traversal 51 * policy providers</a>. When searching for first/last/next/previous Component, 52 * if a focus traversal policy provider is encountered, its focus traversal 53 * policy is used to perform the search operation. 54 * 55 * @author David Mendenhall 56 * 57 * @see Container#getComponents 58 * @since 1.4 59 */ 60 public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy 61 implements java.io.Serializable 62 { 63 private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.ContainerOrderFocusTraversalPolicy"); 64 65 final private int FORWARD_TRAVERSAL = 0; 66 final private int BACKWARD_TRAVERSAL = 1; 67 68 /* 69 * JDK 1.4 serialVersionUID 70 */ 71 private static final long serialVersionUID = 486933713763926351L; 72 73 private boolean implicitDownCycleTraversal = true; 74 75 /** 76 * Used by getComponentAfter and getComponentBefore for efficiency. In 77 * order to maintain compliance with the specification of 78 * FocusTraversalPolicy, if traversal wraps, we should invoke 79 * getFirstComponent or getLastComponent. These methods may be overriden in 80 * subclasses to behave in a non-generic way. However, in the generic case, 81 * these methods will simply return the first or last Components of the 82 * sorted list, respectively. Since getComponentAfter and 83 * getComponentBefore have already built the list before determining 84 * that they need to invoke getFirstComponent or getLastComponent, the 85 * list should be reused if possible. 86 */ 87 transient private Container cachedRoot; 88 transient private List<Component> cachedCycle; 89 90 /* 91 * We suppose to use getFocusTraversalCycle & getComponentIndex methods in order 92 * to divide the policy into two parts: 93 * 1) Making the focus traversal cycle. 94 * 2) Traversing the cycle. 95 * The 1st point assumes producing a list of components representing the focus 96 * traversal cycle. The two methods mentioned above should implement this logic. 97 * The 2nd point assumes implementing the common concepts of operating on the 98 * cycle: traversing back and forth, retrieving the initial/default/first/last 99 * component. These concepts are described in the AWT Focus Spec and they are 100 * applied to the FocusTraversalPolicy in general. 101 * Thus, a descendant of this policy may wish to not reimplement the logic of 102 * the 2nd point but just override the implementation of the 1st one. 103 * A striking example of such a descendant is the javax.swing.SortingFocusTraversalPolicy. 104 */ 105 /*protected*/ private List<Component> getFocusTraversalCycle(Container aContainer) { 106 List<Component> cycle = new ArrayList<Component>(); 107 enumerateCycle(aContainer, cycle); 108 return cycle; | 45 * By default, methods of this class will return a Component only if it is 46 * visible, displayable, enabled, and focusable. Subclasses can modify this 47 * behavior by overriding the <code>accept</code> method. 48 * <p> 49 * This policy takes into account <a 50 * href="doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus traversal 51 * policy providers</a>. When searching for first/last/next/previous Component, 52 * if a focus traversal policy provider is encountered, its focus traversal 53 * policy is used to perform the search operation. 54 * 55 * @author David Mendenhall 56 * 57 * @see Container#getComponents 58 * @since 1.4 59 */ 60 public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy 61 implements java.io.Serializable 62 { 63 private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.ContainerOrderFocusTraversalPolicy"); 64 65 private final int FORWARD_TRAVERSAL = 0; 66 private final int BACKWARD_TRAVERSAL = 1; 67 68 /* 69 * JDK 1.4 serialVersionUID 70 */ 71 private static final long serialVersionUID = 486933713763926351L; 72 73 private boolean implicitDownCycleTraversal = true; 74 75 /** 76 * Used by getComponentAfter and getComponentBefore for efficiency. In 77 * order to maintain compliance with the specification of 78 * FocusTraversalPolicy, if traversal wraps, we should invoke 79 * getFirstComponent or getLastComponent. These methods may be overriden in 80 * subclasses to behave in a non-generic way. However, in the generic case, 81 * these methods will simply return the first or last Components of the 82 * sorted list, respectively. Since getComponentAfter and 83 * getComponentBefore have already built the list before determining 84 * that they need to invoke getFirstComponent or getLastComponent, the 85 * list should be reused if possible. 86 */ 87 private transient Container cachedRoot; 88 private transient List<Component> cachedCycle; 89 90 /* 91 * We suppose to use getFocusTraversalCycle & getComponentIndex methods in order 92 * to divide the policy into two parts: 93 * 1) Making the focus traversal cycle. 94 * 2) Traversing the cycle. 95 * The 1st point assumes producing a list of components representing the focus 96 * traversal cycle. The two methods mentioned above should implement this logic. 97 * The 2nd point assumes implementing the common concepts of operating on the 98 * cycle: traversing back and forth, retrieving the initial/default/first/last 99 * component. These concepts are described in the AWT Focus Spec and they are 100 * applied to the FocusTraversalPolicy in general. 101 * Thus, a descendant of this policy may wish to not reimplement the logic of 102 * the 2nd point but just override the implementation of the 1st one. 103 * A striking example of such a descendant is the javax.swing.SortingFocusTraversalPolicy. 104 */ 105 /*protected*/ private List<Component> getFocusTraversalCycle(Container aContainer) { 106 List<Component> cycle = new ArrayList<Component>(); 107 enumerateCycle(aContainer, cycle); 108 return cycle; |