Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/swing/FocusManager.java
38829 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package javax.swing;2526import java.awt.*;272829/**30* This class has been obsoleted by the 1.4 focus APIs. While client code may31* still use this class, developers are strongly encouraged to use32* <code>java.awt.KeyboardFocusManager</code> and33* <code>java.awt.DefaultKeyboardFocusManager</code> instead.34* <p>35* Please see36* <a href="https://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">37* How to Use the Focus Subsystem</a>,38* a section in <em>The Java Tutorial</em>, and the39* <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>40* for more information.41*42* @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>43*44* @author Arnaud Weber45* @author David Mendenhall46*/47public abstract class FocusManager extends DefaultKeyboardFocusManager {4849/**50* This field is obsolete, and its use is discouraged since its51* specification is incompatible with the 1.4 focus APIs.52* The current FocusManager is no longer a property of the UI.53* Client code must query for the current FocusManager using54* <code>KeyboardFocusManager.getCurrentKeyboardFocusManager()</code>.55* See the Focus Specification for more information.56*57* @see java.awt.KeyboardFocusManager#getCurrentKeyboardFocusManager58* @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>59*/60public static final String FOCUS_MANAGER_CLASS_PROPERTY =61"FocusManagerClassName";6263private static boolean enabled = true;6465/**66* Returns the current <code>KeyboardFocusManager</code> instance67* for the calling thread's context.68*69* @return this thread's context's <code>KeyboardFocusManager</code>70* @see #setCurrentManager71*/72public static FocusManager getCurrentManager() {73KeyboardFocusManager manager =74KeyboardFocusManager.getCurrentKeyboardFocusManager();75if (manager instanceof FocusManager) {76return (FocusManager)manager;77} else {78return new DelegatingDefaultFocusManager(manager);79}80}8182/**83* Sets the current <code>KeyboardFocusManager</code> instance84* for the calling thread's context. If <code>null</code> is85* specified, then the current <code>KeyboardFocusManager</code>86* is replaced with a new instance of87* <code>DefaultKeyboardFocusManager</code>.88* <p>89* If a <code>SecurityManager</code> is installed,90* the calling thread must be granted the <code>AWTPermission</code>91* "replaceKeyboardFocusManager" in order to replace the92* the current <code>KeyboardFocusManager</code>.93* If this permission is not granted,94* this method will throw a <code>SecurityException</code>,95* and the current <code>KeyboardFocusManager</code> will be unchanged.96*97* @param aFocusManager the new <code>KeyboardFocusManager</code>98* for this thread's context99* @see #getCurrentManager100* @see java.awt.DefaultKeyboardFocusManager101* @throws SecurityException if the calling thread does not have permission102* to replace the current <code>KeyboardFocusManager</code>103*/104public static void setCurrentManager(FocusManager aFocusManager)105throws SecurityException106{107// Note: This method is not backward-compatible with 1.3 and earlier108// releases. It now throws a SecurityException in an applet, whereas109// in previous releases, it did not. This issue was discussed at110// length, and ultimately approved by Hans.111KeyboardFocusManager toSet =112(aFocusManager instanceof DelegatingDefaultFocusManager)113? ((DelegatingDefaultFocusManager)aFocusManager).getDelegate()114: aFocusManager;115KeyboardFocusManager.setCurrentKeyboardFocusManager(toSet);116}117118/**119* Changes the current <code>KeyboardFocusManager</code>'s default120* <code>FocusTraversalPolicy</code> to121* <code>DefaultFocusTraversalPolicy</code>.122*123* @see java.awt.DefaultFocusTraversalPolicy124* @see java.awt.KeyboardFocusManager#setDefaultFocusTraversalPolicy125* @deprecated as of 1.4, replaced by126* <code>KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy)</code>127*/128@Deprecated129public static void disableSwingFocusManager() {130if (enabled) {131enabled = false;132KeyboardFocusManager.getCurrentKeyboardFocusManager().133setDefaultFocusTraversalPolicy(134new DefaultFocusTraversalPolicy());135}136}137138/**139* Returns whether the application has invoked140* <code>disableSwingFocusManager()</code>.141*142* @see #disableSwingFocusManager143* @deprecated As of 1.4, replaced by144* <code>KeyboardFocusManager.getDefaultFocusTraversalPolicy()</code>145*/146@Deprecated147public static boolean isFocusManagerEnabled() {148return enabled;149}150}151152153