Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/swing/FocusManager.java
38829 views
1
/*
2
* Copyright (c) 1997, 2013, 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
23
* questions.
24
*/
25
package javax.swing;
26
27
import java.awt.*;
28
29
30
/**
31
* This class has been obsoleted by the 1.4 focus APIs. While client code may
32
* still use this class, developers are strongly encouraged to use
33
* <code>java.awt.KeyboardFocusManager</code> and
34
* <code>java.awt.DefaultKeyboardFocusManager</code> instead.
35
* <p>
36
* Please see
37
* <a href="https://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
38
* How to Use the Focus Subsystem</a>,
39
* a section in <em>The Java Tutorial</em>, and the
40
* <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
41
* for more information.
42
*
43
* @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
44
*
45
* @author Arnaud Weber
46
* @author David Mendenhall
47
*/
48
public abstract class FocusManager extends DefaultKeyboardFocusManager {
49
50
/**
51
* This field is obsolete, and its use is discouraged since its
52
* specification is incompatible with the 1.4 focus APIs.
53
* The current FocusManager is no longer a property of the UI.
54
* Client code must query for the current FocusManager using
55
* <code>KeyboardFocusManager.getCurrentKeyboardFocusManager()</code>.
56
* See the Focus Specification for more information.
57
*
58
* @see java.awt.KeyboardFocusManager#getCurrentKeyboardFocusManager
59
* @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
60
*/
61
public static final String FOCUS_MANAGER_CLASS_PROPERTY =
62
"FocusManagerClassName";
63
64
private static boolean enabled = true;
65
66
/**
67
* Returns the current <code>KeyboardFocusManager</code> instance
68
* for the calling thread's context.
69
*
70
* @return this thread's context's <code>KeyboardFocusManager</code>
71
* @see #setCurrentManager
72
*/
73
public static FocusManager getCurrentManager() {
74
KeyboardFocusManager manager =
75
KeyboardFocusManager.getCurrentKeyboardFocusManager();
76
if (manager instanceof FocusManager) {
77
return (FocusManager)manager;
78
} else {
79
return new DelegatingDefaultFocusManager(manager);
80
}
81
}
82
83
/**
84
* Sets the current <code>KeyboardFocusManager</code> instance
85
* for the calling thread's context. If <code>null</code> is
86
* specified, then the current <code>KeyboardFocusManager</code>
87
* is replaced with a new instance of
88
* <code>DefaultKeyboardFocusManager</code>.
89
* <p>
90
* If a <code>SecurityManager</code> is installed,
91
* the calling thread must be granted the <code>AWTPermission</code>
92
* "replaceKeyboardFocusManager" in order to replace the
93
* the current <code>KeyboardFocusManager</code>.
94
* If this permission is not granted,
95
* this method will throw a <code>SecurityException</code>,
96
* and the current <code>KeyboardFocusManager</code> will be unchanged.
97
*
98
* @param aFocusManager the new <code>KeyboardFocusManager</code>
99
* for this thread's context
100
* @see #getCurrentManager
101
* @see java.awt.DefaultKeyboardFocusManager
102
* @throws SecurityException if the calling thread does not have permission
103
* to replace the current <code>KeyboardFocusManager</code>
104
*/
105
public static void setCurrentManager(FocusManager aFocusManager)
106
throws SecurityException
107
{
108
// Note: This method is not backward-compatible with 1.3 and earlier
109
// releases. It now throws a SecurityException in an applet, whereas
110
// in previous releases, it did not. This issue was discussed at
111
// length, and ultimately approved by Hans.
112
KeyboardFocusManager toSet =
113
(aFocusManager instanceof DelegatingDefaultFocusManager)
114
? ((DelegatingDefaultFocusManager)aFocusManager).getDelegate()
115
: aFocusManager;
116
KeyboardFocusManager.setCurrentKeyboardFocusManager(toSet);
117
}
118
119
/**
120
* Changes the current <code>KeyboardFocusManager</code>'s default
121
* <code>FocusTraversalPolicy</code> to
122
* <code>DefaultFocusTraversalPolicy</code>.
123
*
124
* @see java.awt.DefaultFocusTraversalPolicy
125
* @see java.awt.KeyboardFocusManager#setDefaultFocusTraversalPolicy
126
* @deprecated as of 1.4, replaced by
127
* <code>KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy)</code>
128
*/
129
@Deprecated
130
public static void disableSwingFocusManager() {
131
if (enabled) {
132
enabled = false;
133
KeyboardFocusManager.getCurrentKeyboardFocusManager().
134
setDefaultFocusTraversalPolicy(
135
new DefaultFocusTraversalPolicy());
136
}
137
}
138
139
/**
140
* Returns whether the application has invoked
141
* <code>disableSwingFocusManager()</code>.
142
*
143
* @see #disableSwingFocusManager
144
* @deprecated As of 1.4, replaced by
145
* <code>KeyboardFocusManager.getDefaultFocusTraversalPolicy()</code>
146
*/
147
@Deprecated
148
public static boolean isFocusManagerEnabled() {
149
return enabled;
150
}
151
}
152
153