0N/A/*
2362N/A * Copyright (c) 2000, 2004, 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/Aimport java.awt.peer.ComponentPeer;
0N/A
0N/A
0N/A/**
0N/A * A FocusTraversalPolicy that determines traversal order based on the order
0N/A * of child Components in a Container. From a particular focus cycle root, the
0N/A * policy makes a pre-order traversal of the Component hierarchy, and traverses
0N/A * a Container's children according to the ordering of the array returned by
0N/A * <code>Container.getComponents()</code>. Portions of the hierarchy that are
0N/A * not visible and displayable will not be searched.
0N/A * <p>
0N/A * If client code has explicitly set the focusability of a Component by either
0N/A * overriding <code>Component.isFocusTraversable()</code> or
0N/A * <code>Component.isFocusable()</code>, or by calling
0N/A * <code>Component.setFocusable()</code>, then a DefaultFocusTraversalPolicy
0N/A * behaves exactly like a ContainerOrderFocusTraversalPolicy. If, however, the
0N/A * Component is relying on default focusability, then a
0N/A * DefaultFocusTraversalPolicy will reject all Components with non-focusable
0N/A * peers. This is the default FocusTraversalPolicy for all AWT Containers.
0N/A * <p>
0N/A * The focusability of a peer is implementation-dependent. Sun recommends that
0N/A * all implementations for a particular native platform construct peers with
0N/A * the same focusability. The recommendations for Windows and Unix are that
0N/A * Canvases, Labels, Panels, Scrollbars, ScrollPanes, Windows, and lightweight
0N/A * Components have non-focusable peers, and all other Components have focusable
0N/A * peers. These recommendations are used in the Sun AWT implementations. Note
0N/A * that the focusability of a Component's peer is different from, and does not
0N/A * impact, the focusability of the Component itself.
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#getComponents
0N/A * @see Component#isFocusable
0N/A * @see Component#setFocusable
0N/A * @since 1.4
0N/A */
0N/Apublic class DefaultFocusTraversalPolicy
0N/A extends ContainerOrderFocusTraversalPolicy
0N/A{
0N/A /*
0N/A * serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = 8876966522510157497L;
0N/A
0N/A /**
0N/A * Determines whether a Component is an acceptable choice as the new
0N/A * focus owner. The Component must be visible, displayable, and enabled
0N/A * to be accepted. If client code has explicitly set the focusability
0N/A * of the Component by either overriding
0N/A * <code>Component.isFocusTraversable()</code> or
0N/A * <code>Component.isFocusable()</code>, or by calling
0N/A * <code>Component.setFocusable()</code>, then the Component will be
0N/A * accepted if and only if it is focusable. If, however, the Component is
0N/A * relying on default focusability, then all Canvases, Labels, Panels,
0N/A * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
0N/A * rejected.
0N/A *
0N/A * @param aComponent the Component whose fitness as a focus owner is to
0N/A * be tested
0N/A * @return <code>true</code> if aComponent meets the above requirements;
0N/A * <code>false</code> otherwise
0N/A */
0N/A protected boolean accept(Component aComponent) {
0N/A if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
0N/A aComponent.isEnabled()))
0N/A {
0N/A return false;
0N/A }
0N/A
0N/A // Verify that the Component is recursively enabled. Disabling a
0N/A // heavyweight Container disables its children, whereas disabling
0N/A // a lightweight Container does not.
0N/A if (!(aComponent instanceof Window)) {
0N/A for (Container enableTest = aComponent.getParent();
0N/A enableTest != null;
0N/A enableTest = enableTest.getParent())
0N/A {
0N/A if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
0N/A return false;
0N/A }
0N/A if (enableTest instanceof Window) {
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A
0N/A boolean focusable = aComponent.isFocusable();
0N/A if (aComponent.isFocusTraversableOverridden()) {
0N/A return focusable;
0N/A }
0N/A
0N/A ComponentPeer peer = aComponent.getPeer();
0N/A return (peer != null && peer.isFocusable());
0N/A }
0N/A}