author | prr |
Fri, 23 May 2014 09:05:24 -0700 | |
changeset 24567 | a0ebe5fd56ff |
parent 23697 | e556a715949f |
child 25201 | 4adc75e0c4e5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23697 | 2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.swing; |
|
26 |
||
27 |
import java.awt.Component; |
|
28 |
import java.awt.Container; |
|
29 |
import java.awt.FocusTraversalPolicy; |
|
30 |
import java.util.Comparator; |
|
31 |
||
32 |
||
33 |
/** |
|
34 |
* This class has been obsoleted by the 1.4 focus APIs. While client code may |
|
35 |
* still use this class, developers are strongly encouraged to use |
|
36 |
* <code>java.awt.KeyboardFocusManager</code> and |
|
37 |
* <code>java.awt.DefaultKeyboardFocusManager</code> instead. |
|
38 |
* <p> |
|
39 |
* Please see |
|
20455
f6f9a0c2796b
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents:
5506
diff
changeset
|
40 |
* <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html"> |
2 | 41 |
* How to Use the Focus Subsystem</a>, |
42 |
* a section in <em>The Java Tutorial</em>, and the |
|
43 |
* <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a> |
|
44 |
* for more information. |
|
45 |
* |
|
46 |
* @author Arnaud Weber |
|
47 |
* @author David Mendenhall |
|
48 |
*/ |
|
23697 | 49 |
@SuppressWarnings("serial") // Obsolete class |
2 | 50 |
public class DefaultFocusManager extends FocusManager { |
51 |
||
52 |
final FocusTraversalPolicy gluePolicy = |
|
53 |
new LegacyGlueFocusTraversalPolicy(this); |
|
54 |
private final FocusTraversalPolicy layoutPolicy = |
|
55 |
new LegacyLayoutFocusTraversalPolicy(this); |
|
56 |
private final LayoutComparator comparator = |
|
57 |
new LayoutComparator(); |
|
58 |
||
59 |
public DefaultFocusManager() { |
|
60 |
setDefaultFocusTraversalPolicy(gluePolicy); |
|
61 |
} |
|
62 |
||
63 |
public Component getComponentAfter(Container aContainer, |
|
64 |
Component aComponent) |
|
65 |
{ |
|
66 |
Container root = (aContainer.isFocusCycleRoot()) |
|
67 |
? aContainer |
|
68 |
: aContainer.getFocusCycleRootAncestor(); |
|
69 |
||
70 |
// Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's |
|
71 |
// traversal policy is non-legacy, then honor it. |
|
72 |
if (root != null) { |
|
73 |
FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); |
|
74 |
if (policy != gluePolicy) { |
|
75 |
return policy.getComponentAfter(root, aComponent); |
|
76 |
} |
|
77 |
||
78 |
comparator.setComponentOrientation(root.getComponentOrientation()); |
|
79 |
return layoutPolicy.getComponentAfter(root, aComponent); |
|
80 |
} |
|
81 |
||
82 |
return null; |
|
83 |
} |
|
84 |
||
85 |
public Component getComponentBefore(Container aContainer, |
|
86 |
Component aComponent) |
|
87 |
{ |
|
88 |
Container root = (aContainer.isFocusCycleRoot()) |
|
89 |
? aContainer |
|
90 |
: aContainer.getFocusCycleRootAncestor(); |
|
91 |
||
92 |
// Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's |
|
93 |
// traversal policy is non-legacy, then honor it. |
|
94 |
if (root != null) { |
|
95 |
FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); |
|
96 |
if (policy != gluePolicy) { |
|
97 |
return policy.getComponentBefore(root, aComponent); |
|
98 |
} |
|
99 |
||
100 |
comparator.setComponentOrientation(root.getComponentOrientation()); |
|
101 |
return layoutPolicy.getComponentBefore(root, aComponent); |
|
102 |
} |
|
103 |
||
104 |
return null; |
|
105 |
} |
|
106 |
||
107 |
public Component getFirstComponent(Container aContainer) { |
|
108 |
Container root = (aContainer.isFocusCycleRoot()) |
|
109 |
? aContainer |
|
110 |
: aContainer.getFocusCycleRootAncestor(); |
|
111 |
||
112 |
// Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's |
|
113 |
// traversal policy is non-legacy, then honor it. |
|
114 |
if (root != null) { |
|
115 |
FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); |
|
116 |
if (policy != gluePolicy) { |
|
117 |
return policy.getFirstComponent(root); |
|
118 |
} |
|
119 |
||
120 |
comparator.setComponentOrientation(root.getComponentOrientation()); |
|
121 |
return layoutPolicy.getFirstComponent(root); |
|
122 |
} |
|
123 |
||
124 |
return null; |
|
125 |
} |
|
126 |
||
127 |
public Component getLastComponent(Container aContainer) { |
|
128 |
Container root = (aContainer.isFocusCycleRoot()) |
|
129 |
? aContainer |
|
130 |
: aContainer.getFocusCycleRootAncestor(); |
|
131 |
||
132 |
// Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's |
|
133 |
// traversal policy is non-legacy, then honor it. |
|
134 |
if (root != null) { |
|
135 |
FocusTraversalPolicy policy = root.getFocusTraversalPolicy(); |
|
136 |
if (policy != gluePolicy) { |
|
137 |
return policy.getLastComponent(root); |
|
138 |
} |
|
139 |
||
140 |
comparator.setComponentOrientation(root.getComponentOrientation()); |
|
141 |
return layoutPolicy.getLastComponent(root); |
|
142 |
} |
|
143 |
||
144 |
return null; |
|
145 |
} |
|
146 |
||
147 |
public boolean compareTabOrder(Component a, Component b) { |
|
148 |
return (comparator.compare(a, b) < 0); |
|
149 |
} |
|
150 |
} |
|
151 |
||
23697 | 152 |
@SuppressWarnings("serial") // JDK-implementation class |
2 | 153 |
final class LegacyLayoutFocusTraversalPolicy |
154 |
extends LayoutFocusTraversalPolicy |
|
155 |
{ |
|
156 |
LegacyLayoutFocusTraversalPolicy(DefaultFocusManager defaultFocusManager) { |
|
157 |
super(new CompareTabOrderComparator(defaultFocusManager)); |
|
158 |
} |
|
159 |
} |
|
160 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
161 |
final class CompareTabOrderComparator implements Comparator<Component> { |
2 | 162 |
private final DefaultFocusManager defaultFocusManager; |
163 |
||
164 |
CompareTabOrderComparator(DefaultFocusManager defaultFocusManager) { |
|
165 |
this.defaultFocusManager = defaultFocusManager; |
|
166 |
} |
|
167 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
168 |
public int compare(Component o1, Component o2) { |
2 | 169 |
if (o1 == o2) { |
170 |
return 0; |
|
171 |
} |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
172 |
return (defaultFocusManager.compareTabOrder(o1, o2)) ? -1 : 1; |
2 | 173 |
} |
174 |
} |