0N/A/*
2362N/A * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/Aimport java.awt.*;
0N/A
0N/A
0N/A/**
0N/A * This class has been obsoleted by the 1.4 focus APIs. While client code may
0N/A * still use this class, developers are strongly encouraged to use
0N/A * <code>java.awt.KeyboardFocusManager</code> and
0N/A * <code>java.awt.DefaultKeyboardFocusManager</code> instead.
0N/A * <p>
0N/A * Please see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
0N/A * How to Use the Focus Subsystem</a>,
0N/A * a section in <em>The Java Tutorial</em>, and the
0N/A * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
0N/A * for more information.
0N/A *
0N/A * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
0N/A *
0N/A * @author Arnaud Weber
0N/A * @author David Mendenhall
0N/A */
0N/Apublic abstract class FocusManager extends DefaultKeyboardFocusManager {
0N/A
0N/A /**
0N/A * This field is obsolete, and its use is discouraged since its
0N/A * specification is incompatible with the 1.4 focus APIs.
0N/A * The current FocusManager is no longer a property of the UI.
0N/A * Client code must query for the current FocusManager using
0N/A * <code>KeyboardFocusManager.getCurrentKeyboardFocusManager()</code>.
0N/A * See the Focus Specification for more information.
0N/A *
0N/A * @see java.awt.KeyboardFocusManager#getCurrentKeyboardFocusManager
0N/A * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
0N/A */
0N/A public static final String FOCUS_MANAGER_CLASS_PROPERTY =
0N/A "FocusManagerClassName";
0N/A
0N/A private static boolean enabled = true;
0N/A
0N/A /**
0N/A * Returns the current <code>KeyboardFocusManager</code> instance
0N/A * for the calling thread's context.
0N/A *
0N/A * @return this thread's context's <code>KeyboardFocusManager</code>
0N/A * @see #setCurrentManager
0N/A */
0N/A public static FocusManager getCurrentManager() {
0N/A KeyboardFocusManager manager =
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager();
0N/A if (manager instanceof FocusManager) {
0N/A return (FocusManager)manager;
0N/A } else {
0N/A return new DelegatingDefaultFocusManager(manager);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the current <code>KeyboardFocusManager</code> instance
0N/A * for the calling thread's context. If <code>null</code> is
0N/A * specified, then the current <code>KeyboardFocusManager</code>
0N/A * is replaced with a new instance of
0N/A * <code>DefaultKeyboardFocusManager</code>.
0N/A * <p>
0N/A * If a <code>SecurityManager</code> is installed,
0N/A * the calling thread must be granted the <code>AWTPermission</code>
0N/A * "replaceKeyboardFocusManager" in order to replace the
0N/A * the current <code>KeyboardFocusManager</code>.
0N/A * If this permission is not granted,
0N/A * this method will throw a <code>SecurityException</code>,
0N/A * and the current <code>KeyboardFocusManager</code> will be unchanged.
0N/A *
0N/A * @param aFocusManager the new <code>KeyboardFocusManager</code>
0N/A * for this thread's context
0N/A * @see #getCurrentManager
0N/A * @see java.awt.DefaultKeyboardFocusManager
0N/A * @throws SecurityException if the calling thread does not have permission
0N/A * to replace the current <code>KeyboardFocusManager</code>
0N/A */
0N/A public static void setCurrentManager(FocusManager aFocusManager)
0N/A throws SecurityException
0N/A {
0N/A // Note: This method is not backward-compatible with 1.3 and earlier
0N/A // releases. It now throws a SecurityException in an applet, whereas
0N/A // in previous releases, it did not. This issue was discussed at
0N/A // length, and ultimately approved by Hans.
0N/A KeyboardFocusManager toSet =
0N/A (aFocusManager instanceof DelegatingDefaultFocusManager)
0N/A ? ((DelegatingDefaultFocusManager)aFocusManager).getDelegate()
0N/A : aFocusManager;
0N/A KeyboardFocusManager.setCurrentKeyboardFocusManager(toSet);
0N/A }
0N/A
0N/A /**
0N/A * Changes the current <code>KeyboardFocusManager</code>'s default
0N/A * <code>FocusTraversalPolicy</code> to
0N/A * <code>DefaultFocusTraversalPolicy</code>.
0N/A *
0N/A * @see java.awt.DefaultFocusTraversalPolicy
0N/A * @see java.awt.KeyboardFocusManager#setDefaultFocusTraversalPolicy
0N/A * @deprecated as of 1.4, replaced by
0N/A * <code>KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy)</code>
0N/A */
0N/A @Deprecated
0N/A public static void disableSwingFocusManager() {
0N/A if (enabled) {
0N/A enabled = false;
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A setDefaultFocusTraversalPolicy(
0N/A new DefaultFocusTraversalPolicy());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the application has invoked
0N/A * <code>disableSwingFocusManager()</code>.
0N/A *
0N/A * @see #disableSwingFocusManager
0N/A * @deprecated As of 1.4, replaced by
0N/A * <code>KeyboardFocusManager.getDefaultFocusTraversalPolicy()</code>
0N/A */
0N/A @Deprecated
0N/A public static boolean isFocusManagerEnabled() {
0N/A return enabled;
0N/A }
0N/A}