0N/A/*
2362N/A * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage java.awt;
0N/A
0N/A/**
0N/A * A FocusTraversalPolicy defines the order in which Components with a
0N/A * particular focus cycle root are traversed. Instances can apply the policy to
0N/A * arbitrary focus cycle roots, allowing themselves to be shared across
0N/A * Containers. They do not need to be reinitialized when the focus cycle roots
0N/A * of a Component hierarchy change.
0N/A * <p>
0N/A * The core responsibility of a FocusTraversalPolicy is to provide algorithms
0N/A * determining the next and previous Components to focus when traversing
0N/A * forward or backward in a UI. Each FocusTraversalPolicy must also provide
0N/A * algorithms for determining the first, last, and default Components in a
0N/A * traversal cycle. First and last Components are used when normal forward and
0N/A * backward traversal, respectively, wraps. The default Component is the first
0N/A * to receive focus when traversing down into a new focus traversal cycle.
0N/A * A FocusTraversalPolicy can optionally provide an algorithm for determining
0N/A * a Window's initial Component. The initial Component is the first to receive
0N/A * focus when a Window is first made visible.
0N/A * <p>
0N/A * FocusTraversalPolicy takes into account <a
0N/A * href="doc-files/FocusSpec.html#FocusTraversalPolicyProviders">focus traversal
0N/A * policy providers</a>. When searching for first/last/next/previous Component,
0N/A * if a focus traversal policy provider is encountered, its focus traversal
0N/A * policy is used to perform the search operation.
0N/A * <p>
0N/A * Please see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>, and the
0N/A * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
0N/A * for more information.
0N/A *
0N/A * @author David Mendenhall
0N/A *
0N/A * @see Container#setFocusTraversalPolicy
0N/A * @see Container#getFocusTraversalPolicy
0N/A * @see Container#setFocusCycleRoot
0N/A * @see Container#isFocusCycleRoot
0N/A * @see Container#setFocusTraversalPolicyProvider
0N/A * @see Container#isFocusTraversalPolicyProvider
0N/A * @see KeyboardFocusManager#setDefaultFocusTraversalPolicy
0N/A * @see KeyboardFocusManager#getDefaultFocusTraversalPolicy
0N/A * @since 1.4
0N/A */
0N/Apublic abstract class FocusTraversalPolicy {
0N/A
0N/A /**
0N/A * Returns the Component that should receive the focus after aComponent.
0N/A * aContainer must be a focus cycle root of aComponent or a focus traversal
0N/A * policy provider.
0N/A *
0N/A * @param aContainer a focus cycle root of aComponent or focus traversal
0N/A * policy provider
0N/A * @param aComponent a (possibly indirect) child of aContainer, or
0N/A * aContainer itself
0N/A * @return the Component that should receive the focus after aComponent, or
0N/A * null if no suitable Component can be found
0N/A * @throws IllegalArgumentException if aContainer is not a focus cycle
0N/A * root of aComponent or a focus traversal policy provider, or if
0N/A * either aContainer or aComponent is null
0N/A */
0N/A public abstract Component getComponentAfter(Container aContainer,
0N/A Component aComponent);
0N/A
0N/A /**
0N/A * Returns the Component that should receive the focus before aComponent.
0N/A * aContainer must be a focus cycle root of aComponent or a focus traversal
0N/A * policy provider.
0N/A *
0N/A * @param aContainer a focus cycle root of aComponent or focus traversal
0N/A * policy provider
0N/A * @param aComponent a (possibly indirect) child of aContainer, or
0N/A * aContainer itself
0N/A * @return the Component that should receive the focus before aComponent,
0N/A * or null if no suitable Component can be found
0N/A * @throws IllegalArgumentException if aContainer is not a focus cycle
0N/A * root of aComponent or a focus traversal policy provider, or if
0N/A * either aContainer or aComponent is null
0N/A */
0N/A public abstract Component getComponentBefore(Container aContainer,
0N/A Component aComponent);
0N/A
0N/A /**
0N/A * Returns the first Component in the traversal cycle. This method is used
0N/A * to determine the next Component to focus when traversal wraps in the
0N/A * forward direction.
0N/A *
0N/A * @param aContainer the focus cycle root or focus traversal policy provider
0N/A * whose first Component is to be returned
0N/A * @return the first Component in the traversal cycle of aContainer,
0N/A * or null if no suitable Component can be found
0N/A * @throws IllegalArgumentException if aContainer is null
0N/A */
0N/A public abstract Component getFirstComponent(Container aContainer);
0N/A
0N/A /**
0N/A * Returns the last Component in the traversal cycle. This method is used
0N/A * to determine the next Component to focus when traversal wraps in the
0N/A * reverse direction.
0N/A *
0N/A * @param aContainer the focus cycle root or focus traversal policy
0N/A * provider whose last Component is to be returned
0N/A * @return the last Component in the traversal cycle of aContainer,
0N/A * or null if no suitable Component can be found
0N/A * @throws IllegalArgumentException if aContainer is null
0N/A */
0N/A public abstract Component getLastComponent(Container aContainer);
0N/A
0N/A /**
0N/A * Returns the default Component to focus. This Component will be the first
0N/A * to receive focus when traversing down into a new focus traversal cycle
0N/A * rooted at aContainer.
0N/A *
0N/A * @param aContainer the focus cycle root or focus traversal policy
0N/A * provider whose default Component is to be returned
0N/A * @return the default Component in the traversal cycle of aContainer,
0N/A * or null if no suitable Component can be found
0N/A * @throws IllegalArgumentException if aContainer is null
0N/A */
0N/A public abstract Component getDefaultComponent(Container aContainer);
0N/A
0N/A /**
0N/A * Returns the Component that should receive the focus when a Window is
0N/A * made visible for the first time. Once the Window has been made visible
0N/A * by a call to <code>show()</code> or <code>setVisible(true)</code>, the
0N/A * initial Component will not be used again. Instead, if the Window loses
0N/A * and subsequently regains focus, or is made invisible or undisplayable
0N/A * and subsequently made visible and displayable, the Window's most
0N/A * recently focused Component will become the focus owner. The default
0N/A * implementation of this method returns the default Component.
0N/A *
0N/A * @param window the Window whose initial Component is to be returned
0N/A * @return the Component that should receive the focus when window is made
0N/A * visible for the first time, or null if no suitable Component can
0N/A * be found
0N/A * @see #getDefaultComponent
0N/A * @see Window#getMostRecentFocusOwner
0N/A * @throws IllegalArgumentException if window is null
0N/A */
0N/A public Component getInitialComponent(Window window) {
0N/A if ( window == null ){
0N/A throw new IllegalArgumentException("window cannot be equal to null.");
0N/A }
0N/A Component def = getDefaultComponent(window);
0N/A if (def == null && window.isFocusableWindow()) {
0N/A def = window;
0N/A }
0N/A return def;
0N/A }
0N/A}