001 /*
002 * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package javax.swing;
026
027 import java.awt.*;
028
029 /**
030 * This class has been obsoleted by the 1.4 focus APIs. While client code may
031 * still use this class, developers are strongly encouraged to use
032 * <code>java.awt.KeyboardFocusManager</code> and
033 * <code>java.awt.DefaultKeyboardFocusManager</code> instead.
034 * <p>
035 * Please see
036 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
037 * How to Use the Focus Subsystem</a>,
038 * a section in <em>The Java Tutorial</em>, and the
039 * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
040 * for more information.
041 *
042 * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
043 *
044 * @version 1.35, 05/05/07
045 * @author Arnaud Weber
046 * @author David Mendenhall
047 */
048 public abstract class FocusManager extends DefaultKeyboardFocusManager {
049
050 /**
051 * This field is obsolete, and its use is discouraged since its
052 * specification is incompatible with the 1.4 focus APIs.
053 * The current FocusManager is no longer a property of the UI.
054 * Client code must query for the current FocusManager using
055 * <code>KeyboardFocusManager.getCurrentKeyboardFocusManager()</code>.
056 * See the Focus Specification for more information.
057 *
058 * @see java.awt.KeyboardFocusManager#getCurrentKeyboardFocusManager
059 * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
060 */
061 public static final String FOCUS_MANAGER_CLASS_PROPERTY = "FocusManagerClassName";
062
063 private static boolean enabled = true;
064
065 /**
066 * Returns the current <code>KeyboardFocusManager</code> instance
067 * for the calling thread's context.
068 *
069 * @return this thread's context's <code>KeyboardFocusManager</code>
070 * @see #setCurrentManager
071 */
072 public static FocusManager getCurrentManager() {
073 KeyboardFocusManager manager = KeyboardFocusManager
074 .getCurrentKeyboardFocusManager();
075 if (manager instanceof FocusManager) {
076 return (FocusManager) manager;
077 } else {
078 return new DelegatingDefaultFocusManager(manager);
079 }
080 }
081
082 /**
083 * Sets the current <code>KeyboardFocusManager</code> instance
084 * for the calling thread's context. If <code>null</code> is
085 * specified, then the current <code>KeyboardFocusManager</code>
086 * is replaced with a new instance of
087 * <code>DefaultKeyboardFocusManager</code>.
088 * <p>
089 * If a <code>SecurityManager</code> is installed,
090 * the calling thread must be granted the <code>AWTPermission</code>
091 * "replaceKeyboardFocusManager" in order to replace the
092 * the current <code>KeyboardFocusManager</code>.
093 * If this permission is not granted,
094 * this method will throw a <code>SecurityException</code>,
095 * and the current <code>KeyboardFocusManager</code> will be unchanged.
096 *
097 * @param aFocusManager the new <code>KeyboardFocusManager</code>
098 * for this thread's context
099 * @see #getCurrentManager
100 * @see java.awt.DefaultKeyboardFocusManager
101 * @throws SecurityException if the calling thread does not have permission
102 * to replace the current <code>KeyboardFocusManager</code>
103 */
104 public static void setCurrentManager(FocusManager aFocusManager)
105 throws SecurityException {
106 // Note: This method is not backward-compatible with 1.3 and earlier
107 // releases. It now throws a SecurityException in an applet, whereas
108 // in previous releases, it did not. This issue was discussed at
109 // length, and ultimately approved by Hans.
110 KeyboardFocusManager toSet = (aFocusManager instanceof DelegatingDefaultFocusManager) ? ((DelegatingDefaultFocusManager) aFocusManager)
111 .getDelegate()
112 : aFocusManager;
113 KeyboardFocusManager.setCurrentKeyboardFocusManager(toSet);
114 }
115
116 /**
117 * Changes the current <code>KeyboardFocusManager</code>'s default
118 * <code>FocusTraversalPolicy</code> to
119 * <code>DefaultFocusTraversalPolicy</code>.
120 *
121 * @see java.awt.DefaultFocusTraversalPolicy
122 * @see java.awt.KeyboardFocusManager#setDefaultFocusTraversalPolicy
123 * @deprecated as of 1.4, replaced by
124 * <code>KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy)</code>
125 */
126 @Deprecated
127 public static void disableSwingFocusManager() {
128 if (enabled) {
129 enabled = false;
130 KeyboardFocusManager.getCurrentKeyboardFocusManager()
131 .setDefaultFocusTraversalPolicy(
132 new DefaultFocusTraversalPolicy());
133 }
134 }
135
136 /**
137 * Returns whether the application has invoked
138 * <code>disableSwingFocusManager()</code>.
139 *
140 * @see #disableSwingFocusManager
141 * @deprecated As of 1.4, replaced by
142 * <code>KeyboardFocusManager.getDefaultFocusTraversalPolicy()</code>
143 */
144 @Deprecated
145 public static boolean isFocusManagerEnabled() {
146 return enabled;
147 }
148 }
|