jdk/src/share/classes/javax/swing/FocusManager.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 20455 f6f9a0c2796b
child 24982 37fe99dfd9e9
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20455
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This class has been obsoleted by the 1.4 focus APIs. While client code may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * still use this class, developers are strongly encouraged to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <code>java.awt.KeyboardFocusManager</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <code>java.awt.DefaultKeyboardFocusManager</code> instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Please see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 5506
diff changeset
    37
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * How to Use the Focus Subsystem</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * a section in <em>The Java Tutorial</em>, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Arnaud Weber
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author David Mendenhall
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public abstract class FocusManager extends DefaultKeyboardFocusManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * This field is obsolete, and its use is discouraged since its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * specification is incompatible with the 1.4 focus APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * The current FocusManager is no longer a property of the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Client code must query for the current FocusManager using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * <code>KeyboardFocusManager.getCurrentKeyboardFocusManager()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * See the Focus Specification for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @see java.awt.KeyboardFocusManager#getCurrentKeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static final String FOCUS_MANAGER_CLASS_PROPERTY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        "FocusManagerClassName";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static boolean enabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Returns the current <code>KeyboardFocusManager</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * for the calling thread's context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @return this thread's context's <code>KeyboardFocusManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @see #setCurrentManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static FocusManager getCurrentManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        KeyboardFocusManager manager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            KeyboardFocusManager.getCurrentKeyboardFocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (manager instanceof FocusManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            return (FocusManager)manager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            return new DelegatingDefaultFocusManager(manager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Sets the current <code>KeyboardFocusManager</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * for the calling thread's context. If <code>null</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * specified, then the current <code>KeyboardFocusManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * is replaced with a new instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * <code>DefaultKeyboardFocusManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * If a <code>SecurityManager</code> is installed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * the calling thread must be granted the <code>AWTPermission</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * "replaceKeyboardFocusManager" in order to replace the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * the current <code>KeyboardFocusManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * If this permission is not granted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * this method will throw a <code>SecurityException</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * and the current <code>KeyboardFocusManager</code> will be unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param aFocusManager the new <code>KeyboardFocusManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *     for this thread's context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #getCurrentManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see java.awt.DefaultKeyboardFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @throws SecurityException if the calling thread does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *         to replace the current <code>KeyboardFocusManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static void setCurrentManager(FocusManager aFocusManager)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        throws SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // Note: This method is not backward-compatible with 1.3 and earlier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // releases. It now throws a SecurityException in an applet, whereas
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // in previous releases, it did not. This issue was discussed at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        // length, and ultimately approved by Hans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        KeyboardFocusManager toSet =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            (aFocusManager instanceof DelegatingDefaultFocusManager)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                ? ((DelegatingDefaultFocusManager)aFocusManager).getDelegate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                : aFocusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        KeyboardFocusManager.setCurrentKeyboardFocusManager(toSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Changes the current <code>KeyboardFocusManager</code>'s default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <code>FocusTraversalPolicy</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <code>DefaultFocusTraversalPolicy</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see java.awt.DefaultFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see java.awt.KeyboardFocusManager#setDefaultFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @deprecated as of 1.4, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <code>KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public static void disableSwingFocusManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            enabled = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                setDefaultFocusTraversalPolicy(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    new DefaultFocusTraversalPolicy());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Returns whether the application has invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <code>disableSwingFocusManager()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @see #disableSwingFocusManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @deprecated As of 1.4, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *   <code>KeyboardFocusManager.getDefaultFocusTraversalPolicy()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public static boolean isFocusManagerEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return enabled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
}