Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/javax/swing/FocusManager.java
41153 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
* @since 1.2
48
*/
49
public abstract class FocusManager extends DefaultKeyboardFocusManager {
50
51
/**
52
* This field is obsolete, and its use is discouraged since its
53
* specification is incompatible with the 1.4 focus APIs.
54
* The current FocusManager is no longer a property of the UI.
55
* Client code must query for the current FocusManager using
56
* <code>KeyboardFocusManager.getCurrentKeyboardFocusManager()</code>.
57
* See the Focus Specification for more information.
58
*
59
* @see java.awt.KeyboardFocusManager#getCurrentKeyboardFocusManager
60
* @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
61
*/
62
public static final String FOCUS_MANAGER_CLASS_PROPERTY =
63
"FocusManagerClassName";
64
65
private static boolean enabled = true;
66
67
/**
68
* Constructor for subclasses to call.
69
*/
70
protected FocusManager() {}
71
72
/**
73
* Returns the current <code>KeyboardFocusManager</code> instance
74
* for the calling thread's context.
75
*
76
* @return this thread's context's <code>KeyboardFocusManager</code>
77
* @see #setCurrentManager
78
*/
79
public static FocusManager getCurrentManager() {
80
KeyboardFocusManager manager =
81
KeyboardFocusManager.getCurrentKeyboardFocusManager();
82
if (manager instanceof FocusManager) {
83
return (FocusManager)manager;
84
} else {
85
return new DelegatingDefaultFocusManager(manager);
86
}
87
}
88
89
/**
90
* Sets the current <code>KeyboardFocusManager</code> instance
91
* for the calling thread's context. If <code>null</code> is
92
* specified, then the current <code>KeyboardFocusManager</code>
93
* is replaced with a new instance of
94
* <code>DefaultKeyboardFocusManager</code>.
95
* <p>
96
* If a <code>SecurityManager</code> is installed,
97
* the calling thread must be granted the <code>AWTPermission</code>
98
* "replaceKeyboardFocusManager" in order to replace the
99
* the current <code>KeyboardFocusManager</code>.
100
* If this permission is not granted,
101
* this method will throw a <code>SecurityException</code>,
102
* and the current <code>KeyboardFocusManager</code> will be unchanged.
103
*
104
* @param aFocusManager the new <code>KeyboardFocusManager</code>
105
* for this thread's context
106
* @see #getCurrentManager
107
* @see java.awt.DefaultKeyboardFocusManager
108
* @throws SecurityException if the calling thread does not have permission
109
* to replace the current <code>KeyboardFocusManager</code>
110
*/
111
public static void setCurrentManager(FocusManager aFocusManager)
112
throws SecurityException
113
{
114
// Note: This method is not backward-compatible with 1.3 and earlier
115
// releases. It now throws a SecurityException in an applet, whereas
116
// in previous releases, it did not. This issue was discussed at
117
// length, and ultimately approved by Hans.
118
KeyboardFocusManager toSet =
119
(aFocusManager instanceof DelegatingDefaultFocusManager)
120
? ((DelegatingDefaultFocusManager)aFocusManager).getDelegate()
121
: aFocusManager;
122
KeyboardFocusManager.setCurrentKeyboardFocusManager(toSet);
123
}
124
125
/**
126
* Changes the current <code>KeyboardFocusManager</code>'s default
127
* <code>FocusTraversalPolicy</code> to
128
* <code>DefaultFocusTraversalPolicy</code>.
129
*
130
* @see java.awt.DefaultFocusTraversalPolicy
131
* @see java.awt.KeyboardFocusManager#setDefaultFocusTraversalPolicy
132
* @deprecated as of 1.4, replaced by
133
* <code>KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy)</code>
134
*/
135
@Deprecated
136
public static void disableSwingFocusManager() {
137
if (enabled) {
138
enabled = false;
139
KeyboardFocusManager.getCurrentKeyboardFocusManager().
140
setDefaultFocusTraversalPolicy(
141
new DefaultFocusTraversalPolicy());
142
}
143
}
144
145
/**
146
* Returns whether the application has invoked
147
* <code>disableSwingFocusManager()</code>.
148
*
149
* @return {@code true} if focus manager is enabled.
150
* @see #disableSwingFocusManager
151
* @deprecated As of 1.4, replaced by
152
* <code>KeyboardFocusManager.getDefaultFocusTraversalPolicy()</code>
153
*/
154
@Deprecated
155
public static boolean isFocusManagerEnabled() {
156
return enabled;
157
}
158
}
159
160