Source Code Cross Referenced for DefaultFocusTraversalPolicy.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001        /*
002         * Copyright 2000-2004 Sun Microsystems, Inc.  All Rights Reserved.
003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004         *
005         * This code is free software; you can redistribute it and/or modify it
006         * under the terms of the GNU General Public License version 2 only, as
007         * published by the Free Software Foundation.  Sun designates this
008         * particular file as subject to the "Classpath" exception as provided
009         * by Sun in the LICENSE file that accompanied this code.
010         *
011         * This code is distributed in the hope that it will be useful, but WITHOUT
012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014         * version 2 for more details (a copy is included in the LICENSE file that
015         * accompanied this code).
016         *
017         * You should have received a copy of the GNU General Public License version
018         * 2 along with this work; if not, write to the Free Software Foundation,
019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020         *
021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022         * CA 95054 USA or visit www.sun.com if you need additional information or
023         * have any questions.
024         */
025        package java.awt;
026
027        import java.awt.peer.ComponentPeer;
028
029        /**
030         * A FocusTraversalPolicy that determines traversal order based on the order
031         * of child Components in a Container. From a particular focus cycle root, the
032         * policy makes a pre-order traversal of the Component hierarchy, and traverses
033         * a Container's children according to the ordering of the array returned by
034         * <code>Container.getComponents()</code>. Portions of the hierarchy that are
035         * not visible and displayable will not be searched.
036         * <p>
037         * If client code has explicitly set the focusability of a Component by either
038         * overriding <code>Component.isFocusTraversable()</code> or
039         * <code>Component.isFocusable()</code>, or by calling
040         * <code>Component.setFocusable()</code>, then a DefaultFocusTraversalPolicy
041         * behaves exactly like a ContainerOrderFocusTraversalPolicy. If, however, the
042         * Component is relying on default focusability, then a
043         * DefaultFocusTraversalPolicy will reject all Components with non-focusable
044         * peers. This is the default FocusTraversalPolicy for all AWT Containers.
045         * <p>
046         * The focusability of a peer is implementation-dependent. Sun recommends that
047         * all implementations for a particular native platform construct peers with
048         * the same focusability. The recommendations for Windows and Unix are that
049         * Canvases, Labels, Panels, Scrollbars, ScrollPanes, Windows, and lightweight
050         * Components have non-focusable peers, and all other Components have focusable
051         * peers. These recommendations are used in the Sun AWT implementations. Note
052         * that the focusability of a Component's peer is different from, and does not
053         * impact, the focusability of the Component itself.
054         * <p>
055         * Please see
056         * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
057         * How to Use the Focus Subsystem</a>,
058         * a section in <em>The Java Tutorial</em>, and the
059         * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
060         * for more information.
061         *
062         * @author David Mendenhall
063         * @version 1.13, 05/05/07
064         *
065         * @see Container#getComponents
066         * @see Component#isFocusable
067         * @see Component#setFocusable
068         * @since 1.4
069         */
070        public class DefaultFocusTraversalPolicy extends
071                ContainerOrderFocusTraversalPolicy {
072            /*
073             * serialVersionUID
074             */
075            private static final long serialVersionUID = 8876966522510157497L;
076
077            /**
078             * Determines whether a Component is an acceptable choice as the new
079             * focus owner. The Component must be visible, displayable, and enabled
080             * to be accepted. If client code has explicitly set the focusability
081             * of the Component by either overriding
082             * <code>Component.isFocusTraversable()</code> or
083             * <code>Component.isFocusable()</code>, or by calling
084             * <code>Component.setFocusable()</code>, then the Component will be
085             * accepted if and only if it is focusable. If, however, the Component is
086             * relying on default focusability, then all Canvases, Labels, Panels,
087             * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
088             * rejected.
089             *
090             * @param aComponent the Component whose fitness as a focus owner is to
091             *        be tested
092             * @return <code>true</code> if aComponent meets the above requirements;
093             *         <code>false</code> otherwise
094             */
095            protected boolean accept(Component aComponent) {
096                if (!(aComponent.isVisible() && aComponent.isDisplayable() && aComponent
097                        .isEnabled())) {
098                    return false;
099                }
100
101                // Verify that the Component is recursively enabled. Disabling a
102                // heavyweight Container disables its children, whereas disabling
103                // a lightweight Container does not.
104                if (!(aComponent instanceof  Window)) {
105                    for (Container enableTest = aComponent.getParent(); enableTest != null; enableTest = enableTest
106                            .getParent()) {
107                        if (!(enableTest.isEnabled() || enableTest
108                                .isLightweight())) {
109                            return false;
110                        }
111                        if (enableTest instanceof  Window) {
112                            break;
113                        }
114                    }
115                }
116
117                boolean focusable = aComponent.isFocusable();
118                if (aComponent.isFocusTraversableOverridden()) {
119                    return focusable;
120                }
121
122                ComponentPeer peer = aComponent.getPeer();
123                return (peer != null && peer.isFocusable());
124            }
125        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.