1 /*
2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
76 private static final long serialVersionUID = 8876966522510157497L;
77
78 /**
79 * Determines whether a Component is an acceptable choice as the new
80 * focus owner. The Component must be visible, displayable, and enabled
81 * to be accepted. If client code has explicitly set the focusability
82 * of the Component by either overriding
83 * <code>Component.isFocusTraversable()</code> or
84 * <code>Component.isFocusable()</code>, or by calling
85 * <code>Component.setFocusable()</code>, then the Component will be
86 * accepted if and only if it is focusable. If, however, the Component is
87 * relying on default focusability, then all Canvases, Labels, Panels,
88 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
89 * rejected.
90 *
91 * @param aComponent the Component whose fitness as a focus owner is to
92 * be tested
93 * @return <code>true</code> if aComponent meets the above requirements;
94 * <code>false</code> otherwise
95 */
96 @SuppressWarnings("deprecation")
97 protected boolean accept(Component aComponent) {
98 if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
99 aComponent.isEnabled()))
100 {
101 return false;
102 }
103
104 // Verify that the Component is recursively enabled. Disabling a
105 // heavyweight Container disables its children, whereas disabling
106 // a lightweight Container does not.
107 if (!(aComponent instanceof Window)) {
108 for (Container enableTest = aComponent.getParent();
109 enableTest != null;
110 enableTest = enableTest.getParent())
111 {
112 if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
113 return false;
114 }
115 if (enableTest instanceof Window) {
116 break;
117 }
118 }
119 }
120
121 boolean focusable = aComponent.isFocusable();
122 if (aComponent.isFocusTraversableOverridden()) {
123 return focusable;
124 }
125
126 ComponentPeer peer = aComponent.getPeer();
127 return (peer != null && peer.isFocusable());
128 }
129 }
|
1 /*
2 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
76 private static final long serialVersionUID = 8876966522510157497L;
77
78 /**
79 * Determines whether a Component is an acceptable choice as the new
80 * focus owner. The Component must be visible, displayable, and enabled
81 * to be accepted. If client code has explicitly set the focusability
82 * of the Component by either overriding
83 * <code>Component.isFocusTraversable()</code> or
84 * <code>Component.isFocusable()</code>, or by calling
85 * <code>Component.setFocusable()</code>, then the Component will be
86 * accepted if and only if it is focusable. If, however, the Component is
87 * relying on default focusability, then all Canvases, Labels, Panels,
88 * Scrollbars, ScrollPanes, Windows, and lightweight Components will be
89 * rejected.
90 *
91 * @param aComponent the Component whose fitness as a focus owner is to
92 * be tested
93 * @return <code>true</code> if aComponent meets the above requirements;
94 * <code>false</code> otherwise
95 */
96 protected boolean accept(Component aComponent) {
97 if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
98 aComponent.isEnabled()))
99 {
100 return false;
101 }
102
103 // Verify that the Component is recursively enabled. Disabling a
104 // heavyweight Container disables its children, whereas disabling
105 // a lightweight Container does not.
106 if (!(aComponent instanceof Window)) {
107 for (Container enableTest = aComponent.getParent();
108 enableTest != null;
109 enableTest = enableTest.getParent())
110 {
111 if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
112 return false;
113 }
114 if (enableTest instanceof Window) {
115 break;
116 }
117 }
118 }
119
120 boolean focusable = aComponent.isFocusable();
121 if (aComponent.isFocusTraversableOverridden()) {
122 return focusable;
123 }
124
125 ComponentPeer peer = aComponent.peer;
126 return (peer != null && peer.isFocusable());
127 }
128 }
|