KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > FocusManager


1 /*
2  * @(#)FocusManager.java 1.28 04/05/18
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing;
8
9 import java.awt.*;
10
11
12 /**
13  * This class has been obsoleted by the 1.4 focus APIs. While client code may
14  * still use this class, developers are strongly encouraged to use
15  * <code>java.awt.KeyboardFocusManager</code> and
16  * <code>java.awt.DefaultKeyboardFocusManager</code> instead.
17  * <p>
18  * Please see
19  * <a HREF="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
20  * How to Use the Focus Subsystem</a>,
21  * a section in <em>The Java Tutorial</em>, and the
22  * <a HREF="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
23  * for more information.
24  *
25  * @see <a HREF="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
26  *
27  * @version 1.28, 05/18/04
28  * @author Arnaud Weber
29  * @author David Mendenhall
30  */

31 public abstract class FocusManager extends DefaultKeyboardFocusManager {
32
33     /**
34      * This field is obsolete, and its use is discouraged since its
35      * specification is incompatible with the 1.4 focus APIs.
36      * The current FocusManager is no longer a property of the UI.
37      * Client code must query for the current FocusManager using
38      * <code>KeyboardFocusManager.getCurrentKeyboardFocusManager()</code>.
39      * See the Focus Specification for more information.
40      *
41      * @see java.awt.KeyboardFocusManager#getCurrentKeyboardFocusManager
42      * @see <a HREF="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
43      */

44     public static final String JavaDoc FOCUS_MANAGER_CLASS_PROPERTY =
45         "FocusManagerClassName";
46
47     private static boolean enabled = true;
48
49     /**
50      * Returns the current <code>KeyboardFocusManager</code> instance
51      * for the calling thread's context.
52      *
53      * @return this thread's context's <code>KeyboardFocusManager</code>
54      * @see #setCurrentManager
55      */

56     public static FocusManager JavaDoc getCurrentManager() {
57     KeyboardFocusManager manager =
58         KeyboardFocusManager.getCurrentKeyboardFocusManager();
59     if (manager instanceof FocusManager JavaDoc) {
60         return (FocusManager JavaDoc)manager;
61     } else {
62         return new DelegatingDefaultFocusManager JavaDoc(manager);
63     }
64     }
65
66     /**
67      * Sets the current <code>KeyboardFocusManager</code> instance
68      * for the calling thread's context. If <code>null</code> is
69      * specified, then the current <code>KeyboardFocusManager</code>
70      * is replaced with a new instance of
71      * <code>DefaultKeyboardFocusManager</code>.
72      * <p>
73      * If a <code>SecurityManager</code> is installed,
74      * the calling thread must be granted the <code>AWTPermission</code>
75      * "replaceKeyboardFocusManager" in order to replace the
76      * the current <code>KeyboardFocusManager</code>.
77      * If this permission is not granted,
78      * this method will throw a <code>SecurityException</code>,
79      * and the current <code>KeyboardFocusManager</code> will be unchanged.
80      *
81      * @param aFocusManager the new <code>KeyboardFocusManager</code>
82      * for this thread's context
83      * @see #getCurrentManager
84      * @see java.awt.DefaultKeyboardFocusManager
85      * @throws SecurityException if the calling thread does not have permission
86      * to replace the current <code>KeyboardFocusManager</code>
87      */

88     public static void setCurrentManager(FocusManager JavaDoc aFocusManager)
89         throws SecurityException JavaDoc
90     {
91     // Note: This method is not backward-compatible with 1.3 and earlier
92
// releases. It now throws a SecurityException in an applet, whereas
93
// in previous releases, it did not. This issue was discussed at
94
// length, and ultimately approved by Hans.
95
KeyboardFocusManager toSet =
96             (aFocusManager instanceof DelegatingDefaultFocusManager JavaDoc)
97                 ? ((DelegatingDefaultFocusManager JavaDoc)aFocusManager).getDelegate()
98                 : aFocusManager;
99         KeyboardFocusManager.setCurrentKeyboardFocusManager(toSet);
100     }
101
102     /**
103      * Changes the current <code>KeyboardFocusManager</code>'s default
104      * <code>FocusTraversalPolicy</code> to
105      * <code>DefaultFocusTraversalPolicy</code>.
106      *
107      * @see java.awt.DefaultFocusTraversalPolicy
108      * @see java.awt.KeyboardFocusManager#setDefaultFocusTraversalPolicy
109      * @deprecated as of 1.4, replaced by
110      * <code>KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy)</code>
111      */

112     @Deprecated JavaDoc
113     public static void disableSwingFocusManager() {
114     if (enabled) {
115         enabled = false;
116         KeyboardFocusManager.getCurrentKeyboardFocusManager().
117         setDefaultFocusTraversalPolicy(
118                     new DefaultFocusTraversalPolicy());
119     }
120     }
121
122     /**
123      * Returns whether the application has invoked
124      * <code>disableSwingFocusManager()</code>.
125      *
126      * @see #disableSwingFocusManager
127      * @deprecated As of 1.4, replaced by
128      * <code>KeyboardFocusManager.getDefaultFocusTraversalPolicy()</code>
129      */

130     @Deprecated JavaDoc
131     public static boolean isFocusManagerEnabled() {
132     return enabled;
133     }
134 }
135
136
Popular Tags