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. import java.awt.*;
  9. /**
  10. * This class has been obsoleted by the 1.4 focus APIs. While client code may
  11. * still use this class, developers are strongly encouraged to use
  12. * <code>java.awt.KeyboardFocusManager</code> and
  13. * <code>java.awt.DefaultKeyboardFocusManager</code> instead.
  14. * <p>
  15. * Please see
  16. * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html">
  17. * How to Use the Focus Subsystem</a>,
  18. * a section in <em>The Java Tutorial</em>, and the
  19. * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
  20. * for more information.
  21. *
  22. * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
  23. *
  24. * @version 1.28, 05/18/04
  25. * @author Arnaud Weber
  26. * @author David Mendenhall
  27. */
  28. public abstract class FocusManager extends DefaultKeyboardFocusManager {
  29. /**
  30. * This field is obsolete, and its use is discouraged since its
  31. * specification is incompatible with the 1.4 focus APIs.
  32. * The current FocusManager is no longer a property of the UI.
  33. * Client code must query for the current FocusManager using
  34. * <code>KeyboardFocusManager.getCurrentKeyboardFocusManager()</code>.
  35. * See the Focus Specification for more information.
  36. *
  37. * @see java.awt.KeyboardFocusManager#getCurrentKeyboardFocusManager
  38. * @see <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a>
  39. */
  40. public static final String FOCUS_MANAGER_CLASS_PROPERTY =
  41. "FocusManagerClassName";
  42. private static boolean enabled = true;
  43. /**
  44. * Returns the current <code>KeyboardFocusManager</code> instance
  45. * for the calling thread's context.
  46. *
  47. * @return this thread's context's <code>KeyboardFocusManager</code>
  48. * @see #setCurrentManager
  49. */
  50. public static FocusManager getCurrentManager() {
  51. KeyboardFocusManager manager =
  52. KeyboardFocusManager.getCurrentKeyboardFocusManager();
  53. if (manager instanceof FocusManager) {
  54. return (FocusManager)manager;
  55. } else {
  56. return new DelegatingDefaultFocusManager(manager);
  57. }
  58. }
  59. /**
  60. * Sets the current <code>KeyboardFocusManager</code> instance
  61. * for the calling thread's context. If <code>null</code> is
  62. * specified, then the current <code>KeyboardFocusManager</code>
  63. * is replaced with a new instance of
  64. * <code>DefaultKeyboardFocusManager</code>.
  65. * <p>
  66. * If a <code>SecurityManager</code> is installed,
  67. * the calling thread must be granted the <code>AWTPermission</code>
  68. * "replaceKeyboardFocusManager" in order to replace the
  69. * the current <code>KeyboardFocusManager</code>.
  70. * If this permission is not granted,
  71. * this method will throw a <code>SecurityException</code>,
  72. * and the current <code>KeyboardFocusManager</code> will be unchanged.
  73. *
  74. * @param aFocusManager the new <code>KeyboardFocusManager</code>
  75. * for this thread's context
  76. * @see #getCurrentManager
  77. * @see java.awt.DefaultKeyboardFocusManager
  78. * @throws SecurityException if the calling thread does not have permission
  79. * to replace the current <code>KeyboardFocusManager</code>
  80. */
  81. public static void setCurrentManager(FocusManager aFocusManager)
  82. throws SecurityException
  83. {
  84. // Note: This method is not backward-compatible with 1.3 and earlier
  85. // releases. It now throws a SecurityException in an applet, whereas
  86. // in previous releases, it did not. This issue was discussed at
  87. // length, and ultimately approved by Hans.
  88. KeyboardFocusManager toSet =
  89. (aFocusManager instanceof DelegatingDefaultFocusManager)
  90. ? ((DelegatingDefaultFocusManager)aFocusManager).getDelegate()
  91. : aFocusManager;
  92. KeyboardFocusManager.setCurrentKeyboardFocusManager(toSet);
  93. }
  94. /**
  95. * Changes the current <code>KeyboardFocusManager</code>'s default
  96. * <code>FocusTraversalPolicy</code> to
  97. * <code>DefaultFocusTraversalPolicy</code>.
  98. *
  99. * @see java.awt.DefaultFocusTraversalPolicy
  100. * @see java.awt.KeyboardFocusManager#setDefaultFocusTraversalPolicy
  101. * @deprecated as of 1.4, replaced by
  102. * <code>KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy)</code>
  103. */
  104. @Deprecated
  105. public static void disableSwingFocusManager() {
  106. if (enabled) {
  107. enabled = false;
  108. KeyboardFocusManager.getCurrentKeyboardFocusManager().
  109. setDefaultFocusTraversalPolicy(
  110. new DefaultFocusTraversalPolicy());
  111. }
  112. }
  113. /**
  114. * Returns whether the application has invoked
  115. * <code>disableSwingFocusManager()</code>.
  116. *
  117. * @see #disableSwingFocusManager
  118. * @deprecated As of 1.4, replaced by
  119. * <code>KeyboardFocusManager.getDefaultFocusTraversalPolicy()</code>
  120. */
  121. @Deprecated
  122. public static boolean isFocusManagerEnabled() {
  123. return enabled;
  124. }
  125. }