- /*
- * @(#)KeyboardFocusManager.java 1.40 03/01/23
- *
- * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
- * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
- */
- package java.awt;
- import java.awt.event.FocusEvent;
- import java.awt.event.InputEvent;
- import java.awt.event.KeyEvent;
- import java.awt.event.WindowEvent;
- import java.awt.peer.LightweightPeer;
- import java.beans.*;
- import java.util.Set;
- import java.util.HashSet;
- import java.util.Collections;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.ListIterator;
- import java.util.StringTokenizer;
- import java.util.WeakHashMap;
- import java.lang.ref.WeakReference;
- import sun.awt.AppContext;
- import sun.awt.DebugHelper;
- import sun.awt.SunToolkit;
- /**
- * The KeyboardFocusManager is responsible for managing the active and focused
- * Windows, and the current focus owner. The focus owner is defined as the
- * Component in an application that will typically receive all KeyEvents
- * generated by the user. The focused Window is the Window that is, or
- * contains, the focus owner. Only a Frame or a Dialog can be the active
- * Window. The native windowing system may denote the active Window or its
- * children with special decorations, such as a highlighted title bar. The
- * active Window is always either the focused Window, or the first Frame or
- * Dialog that is an owner of the focused Window.
- * <p>
- * The KeyboardFocusManager is both a centralized location for client code to
- * query for the focus owner and initiate focus changes, and an event
- * dispatcher for all FocusEvents, WindowEvents related to focus, and
- * KeyEvents.
- * <p>
- * Some browsers partition applets in different code bases into separate
- * contexts, and establish walls between these contexts. In such a scenario,
- * there will be one KeyboardFocusManager per context. Other browsers place all
- * applets into the same context, implying that there will be only a single,
- * global KeyboardFocusManager for all applets. This behavior is
- * implementation-dependent. Consult your browser's documentation for more
- * information. No matter how many contexts there may be, however, there can
- * never be more than one focus owner, focused Window, or active Window, per
- * ClassLoader.
- *
- * @author David Mendenhall
- * @version 1.40, 01/23/03
- *
- * @see Window
- * @see Frame
- * @see Dialog
- * @see java.awt.event.FocusEvent
- * @see java.awt.event.WindowEvent
- * @see java.awt.event.KeyEvent
- * @since 1.4
- */
- public abstract class KeyboardFocusManager
- implements KeyEventDispatcher, KeyEventPostProcessor
- {
- static {
- /* ensure that the necessary native libraries are loaded */
- Toolkit.loadLibraries();
- if (!GraphicsEnvironment.isHeadless()) {
- initIDs();
- }
- }
- /**
- * Initialize JNI field and method IDs
- */
- private static native void initIDs();
- private static final DebugHelper dbg =
- DebugHelper.create(KeyboardFocusManager.class);
- /**
- * The identifier for the Forward focus traversal keys.
- *
- * @see #setDefaultFocusTraversalKeys
- * @see #getDefaultFocusTraversalKeys
- * @see Component#setFocusTraversalKeys
- * @see Component#getFocusTraversalKeys
- */
- public static final int FORWARD_TRAVERSAL_KEYS = 0;
- /**
- * The identifier for the Backward focus traversal keys.
- *
- * @see #setDefaultFocusTraversalKeys
- * @see #getDefaultFocusTraversalKeys
- * @see Component#setFocusTraversalKeys
- * @see Component#getFocusTraversalKeys
- */
- public static final int BACKWARD_TRAVERSAL_KEYS = 1;
- /**
- * The identifier for the Up Cycle focus traversal keys.
- *
- * @see #setDefaultFocusTraversalKeys
- * @see #getDefaultFocusTraversalKeys
- * @see Component#setFocusTraversalKeys
- * @see Component#getFocusTraversalKeys
- */
- public static final int UP_CYCLE_TRAVERSAL_KEYS = 2;
- /**
- * The identifier for the Down Cycle focus traversal keys.
- *
- * @see #setDefaultFocusTraversalKeys
- * @see #getDefaultFocusTraversalKeys
- * @see Component#setFocusTraversalKeys
- * @see Component#getFocusTraversalKeys
- */
- public static final int DOWN_CYCLE_TRAVERSAL_KEYS = 3;
- static final int TRAVERSAL_KEY_LENGTH = DOWN_CYCLE_TRAVERSAL_KEYS + 1;
- /**
- * Returns the current KeyboardFocusManager instance for the calling
- * thread's context.
- *
- * @return this thread's context's KeyboardFocusManager
- * @see #setCurrentKeyboardFocusManager
- */
- public static KeyboardFocusManager getCurrentKeyboardFocusManager() {
- return getCurrentKeyboardFocusManager(AppContext.getAppContext());
- }
- synchronized static KeyboardFocusManager
- getCurrentKeyboardFocusManager(AppContext appcontext)
- {
- KeyboardFocusManager manager = (KeyboardFocusManager)
- appcontext.get(KeyboardFocusManager.class);
- if (manager == null) {
- manager = new DefaultKeyboardFocusManager();
- appcontext.put(KeyboardFocusManager.class, manager);
- }
- return manager;
- }
- /**
- * Sets the current KeyboardFocusManager instance for the calling thread's
- * context. If null is specified, then the current KeyboardFocusManager
- * is replaced with a new instance of DefaultKeyboardFocusManager.
- * <p>
- * If a SecurityManager is installed, the calling thread must be granted
- * the AWTPermission "replaceKeyboardFocusManager" in order to replace the
- * the current KeyboardFocusManager. If this permission is not granted,
- * this method will throw a SecurityException, and the current
- * KeyboardFocusManager will be unchanged.
- *
- * @param newManager the new KeyboardFocusManager for this thread's context
- * @see #getCurrentKeyboardFocusManager
- * @see DefaultKeyboardFocusManager
- * @throws SecurityException if the calling thread does not have permission
- * to replace the current KeyboardFocusManager
- */
- public synchronized static void setCurrentKeyboardFocusManager(
- KeyboardFocusManager newManager) throws SecurityException
- {
- AppContext appcontext = AppContext.getAppContext();
- if (newManager != null) {
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- if (replaceKeyboardFocusManagerPermission == null) {
- replaceKeyboardFocusManagerPermission =
- new AWTPermission("replaceKeyboardFocusManager");
- }
- security.
- checkPermission(replaceKeyboardFocusManagerPermission);
- }
- appcontext.put(KeyboardFocusManager.class, newManager);
- } else {
- appcontext.remove(KeyboardFocusManager.class);
- }
- }
- /**
- * The Component in an application that will typically receive all
- * KeyEvents generated by the user.
- */
- private static Component focusOwner;
- /**
- * The Component in an application that will regain focus when an
- * outstanding temporary focus transfer has completed, or the focus owner,
- * if no outstanding temporary transfer exists.
- */
- private static Component permanentFocusOwner;
- /**
- * The Window which is, or contains, the focus owner.
- */
- private static Window focusedWindow;
- /**
- * Only a Frame or a Dialog can be the active Window. The native windowing
- * system may denote the active Window with a special decoration, such as a
- * highlighted title bar. The active Window is always either the focused
- * Window, or the first Frame or Dialog which is an owner of the focused
- * Window.
- */
- private static Window activeWindow;
- /**
- * The default FocusTraversalPolicy for all Windows that have no policy of
- * their own set. If those Windows have focus-cycle-root children that have
- * no keyboard-traversal policy of their own, then those children will also
- * inherit this policy (as will, recursively, their focus-cycle-root
- * children).
- */
- private FocusTraversalPolicy defaultPolicy =
- new DefaultFocusTraversalPolicy();
- /**
- * The bound property names of each focus traversal key.
- */
- private static final String[] defaultFocusTraversalKeyPropertyNames = {
- "forwardDefaultFocusTraversalKeys",
- "backwardDefaultFocusTraversalKeys",
- "upCycleDefaultFocusTraversalKeys",
- "downCycleDefaultFocusTraversalKeys"
- };
- /**
- * The default Strings for initializing the default focus traversal keys.
- * Only used if default traversal keys are not set using Preferences API.
- */
- private static final String[] defaultFocusTraversalKeyStrings = {
- "TAB,ctrl TAB", "shift TAB,ctrl shift TAB", "", ""
- };
- /**
- * The default focus traversal keys. Each array of traversal keys will be
- * in effect on all Windows that have no such array of their own explicitly
- * set. Each array will also be inherited, recursively, by any child
- * Component of those Windows that has no such array of its own explicitly
- * set.
- */
- private Set[] defaultFocusTraversalKeys = new Set[4];
- /**
- * The current focus cycle root. If the focus owner is itself a focus cycle
- * root, then it may be ambiguous as to which Components represent the next
- * and previous Components to focus during normal focus traversal. In that
- * case, the current focus cycle root is used to differentiate among the
- * possibilities.
- */
- private static Container currentFocusCycleRoot;
- /**
- * A description of any VetoableChangeListeners which have been registered.
- */
- private VetoableChangeSupport vetoableSupport;
- /**
- * A description of any PropertyChangeListeners which have been registered.
- */
- private PropertyChangeSupport changeSupport;
- /**
- * This KeyboardFocusManager's KeyEventDispatcher chain. The List does not
- * include this KeyboardFocusManager unless it was explicitly re-registered
- * via a call to <code>addKeyEventDispatcher</code>. If no other
- * KeyEventDispatchers are registered, this field may be null or refer to
- * a List of length 0.
- */
- private java.util.LinkedList keyEventDispatchers;
- /**
- * This KeyboardFocusManager's KeyEventPostProcessor chain. The List does
- * not include this KeyboardFocusManager unless it was explicitly
- * re-registered via a call to <code>addKeyEventPostProcessor</code>.
- * If no other KeyEventPostProcessors are registered, this field may be
- * null or refer to a List of length 0.
- */
- private java.util.LinkedList keyEventPostProcessors;
- /**
- * Maps Windows to those Windows' most recent focus owners.
- */
- private static java.util.Map mostRecentFocusOwners = new WeakHashMap();
- /**
- * Error String for initializing SecurityExceptions.
- */
- private static final String notPrivileged = "this KeyboardFocusManager is not installed in the current thread's context";
- /**
- * We cache the permission used to verify that the calling thread is
- * permitted to access the global focus state.
- */
- private static AWTPermission replaceKeyboardFocusManagerPermission;
- /*
- * SequencedEvent which is currently dispatched in AppContext.
- */
- transient SequencedEvent currentSequencedEvent = null;
- final void setCurrentSequencedEvent(SequencedEvent current) {
- synchronized (SequencedEvent.class) {
- assert(current == null || currentSequencedEvent == null);
- currentSequencedEvent = current;
- }
- }
- final SequencedEvent getCurrentSequencedEvent() {
- synchronized (SequencedEvent.class) {
- return currentSequencedEvent;
- }
- }
- static Set initFocusTraversalKeysSet(String value, Set targetSet) {
- StringTokenizer tokens = new StringTokenizer(value, ",");
- while (tokens.hasMoreTokens()) {
- targetSet.add(AWTKeyStroke.getAWTKeyStroke(tokens.nextToken()));
- }
- return (targetSet.isEmpty())
- ? Collections.EMPTY_SET
- : Collections.unmodifiableSet(targetSet);
- }
- /**
- * Initializes a KeyboardFocusManager.
- */
- public KeyboardFocusManager() {
- for (int i = 0; i < TRAVERSAL_KEY_LENGTH; i++) {
- defaultFocusTraversalKeys[i] = initFocusTraversalKeysSet(
- defaultFocusTraversalKeyStrings[i], new HashSet());
- }
- }
- /**
- * Returns the focus owner, if the focus owner is in the same context as
- * the calling thread. The focus owner is defined as the Component in an
- * application that will typically receive all KeyEvents generated by the
- * user. KeyEvents which map to the focus owner's focus traversal keys will
- * not be delivered if focus traversal keys are enabled for the focus
- * owner. In addition, KeyEventDispatchers may retarget or consume
- * KeyEvents before they reach the focus owner.
- *
- * @return the focus owner, or null if the focus owner is not a member of
- * the calling thread's context
- * @see #getGlobalFocusOwner
- * @see #setGlobalFocusOwner
- */
- public Component getFocusOwner() {
- synchronized (KeyboardFocusManager.class) {
- if (focusOwner == null) {
- return null;
- }
- return (focusOwner.appContext == AppContext.getAppContext())
- ? focusOwner
- : null;
- }
- }
- /**
- * Returns the focus owner, even if the calling thread is in a different
- * context than the focus owner. The focus owner is defined as the
- * Component in an application that will typically receive all KeyEvents
- * generated by the user. KeyEvents which map to the focus owner's focus
- * traversal keys will not be delivered if focus traversal keys are enabled
- * for the focus owner. In addition, KeyEventDispatchers may retarget or
- * consume KeyEvents before they reach the focus owner.
- * <p>
- * This method will throw a SecurityException if this KeyboardFocusManager
- * is not the current KeyboardFocusManager for the calling thread's
- * context.
- *
- * @return the focus owner
- * @see #getFocusOwner
- * @see #setGlobalFocusOwner
- * @throws SecurityException if this KeyboardFocusManager is not the
- * current KeyboardFocusManager for the calling thread's context
- */
- protected Component getGlobalFocusOwner() throws SecurityException {
- synchronized (KeyboardFocusManager.class) {
- if (this == getCurrentKeyboardFocusManager()) {
- return focusOwner;
- } else {
- throw new SecurityException(notPrivileged);
- }
- }
- }
- /**
- * Sets the focus owner. The operation will be cancelled if the Component
- * is not focusable. The focus owner is defined as the Component in an
- * application that will typically receive all KeyEvents generated by the
- * user. KeyEvents which map to the focus owner's focus traversal keys will
- * not be delivered if focus traversal keys are enabled for the focus
- * owner. In addition, KeyEventDispatchers may retarget or consume
- * KeyEvents before they reach the focus owner.
- * <p>
- * This method does not actually set the focus to the specified Component.
- * It merely stores the value to be subsequently returned by
- * <code>getFocusOwner()</code>. Use <code>Component.requestFocus()</code>
- * or <code>Component.requestFocusInWindow()</code> to change the focus
- * owner, subject to platform limitations.
- *
- * @param focusOwner the focus owner
- * @see #getFocusOwner
- * @see #getGlobalFocusOwner
- * @see Component#requestFocus()
- * @see Component#requestFocusInWindow()
- * @see Component#isFocusable
- * @beaninfo
- * bound: true
- */
- protected void setGlobalFocusOwner(Component focusOwner) {
- Component oldFocusOwner = null;
- boolean shouldFire = false;
- if (focusOwner == null || focusOwner.isFocusable()) {
- synchronized (KeyboardFocusManager.class) {
- oldFocusOwner = getFocusOwner();
- try {
- fireVetoableChange("focusOwner", oldFocusOwner,
- focusOwner);
- } catch (PropertyVetoException e) {
- // rejected
- return;
- }
- KeyboardFocusManager.focusOwner = focusOwner;
- if (focusOwner != null &&
- (getCurrentFocusCycleRoot() == null ||
- !focusOwner.isFocusCycleRoot(getCurrentFocusCycleRoot())))
- {
- Container rootAncestor =
- focusOwner.getFocusCycleRootAncestor();
- if (rootAncestor == null && (focusOwner instanceof Window))
- {
- rootAncestor = (Container)focusOwner;
- }
- if (rootAncestor != null) {
- setGlobalCurrentFocusCycleRoot(rootAncestor);
- }
- }
- shouldFire = true;
- }
- }
- if (shouldFire) {
- firePropertyChange("focusOwner", oldFocusOwner, focusOwner);
- }
- }
- /**
- * Clears the global focus owner at both the Java and native levels. If
- * there exists a focus owner, that Component will receive a permanent
- * FOCUS_LOST event. After this operation completes, the native windowing
- * system will discard all user-generated KeyEvents until the user selects
- * a new Component to receive focus, or a Component is given focus
- * explicitly via a call to <code>requestFocus()</code>. This operation
- * does not change the focused or active Windows.
- *
- * @see Component#requestFocus()
- * @see java.awt.event.FocusEvent#FOCUS_LOST
- */
- public void clearGlobalFocusOwner() {
- if (!GraphicsEnvironment.isHeadless()) {
- // Toolkit must be fully initialized, otherwise
- // _clearGlobalFocusOwner will crash or throw an exception
- Toolkit.getDefaultToolkit();
- _clearGlobalFocusOwner();
- }
- }
- private native void _clearGlobalFocusOwner();
- static native Component getNativeFocusOwner();
- static native Window getNativeFocusedWindow();
- /**
- * Returns the permanent focus owner, if the permanent focus owner is in
- * the same context as the calling thread. The permanent focus owner is
- * defined as the last Component in an application to receive a permanent
- * FOCUS_GAINED event. The focus owner and permanent focus owner are
- * equivalent unless a temporary focus change is currently in effect. In
- * such a situation, the permanent focus owner will again be the focus
- * owner when the temporary focus change ends.
- *
- * @return the permanent focus owner, or null if the permanent focus owner
- * is not a member of the calling thread's context
- * @see #getGlobalPermanentFocusOwner
- * @see #setGlobalPermanentFocusOwner
- */
- public Component getPermanentFocusOwner() {
- synchronized (KeyboardFocusManager.class) {
- if (permanentFocusOwner == null) {
- return null;
- }
- return (permanentFocusOwner.appContext ==
- AppContext.getAppContext())
- ? permanentFocusOwner
- : null;
- }
- }
- /**
- * Returns the permanent focus owner, even if the calling thread is in a
- * different context than the permanent focus owner. The permanent focus
- * owner is defined as the last Component in an application to receive a
- * permanent FOCUS_GAINED event. The focus owner and permanent focus owner
- * are equivalent unless a temporary focus change is currently in effect.
- * In such a situation, the permanent focus owner will again be the focus
- * owner when the temporary focus change ends.
- * <p>
- * This method will throw a SecurityException if this KeyboardFocusManager
- * is not the current KeyboardFocusManager for the calling thread's
- * context.
- *
- * @return the permanent focus owner
- * @see #getPermanentFocusOwner
- * @see #setGlobalPermanentFocusOwner
- * @throws SecurityException if this KeyboardFocusManager is not the
- * current KeyboardFocusManager for the calling thread's context
- */
- protected Component getGlobalPermanentFocusOwner()
- throws SecurityException
- {
- synchronized (KeyboardFocusManager.class) {
- if (this == getCurrentKeyboardFocusManager()) {
- return permanentFocusOwner;
- } else {
- throw new SecurityException(notPrivileged);
- }
- }
- }
- /**
- * Sets the permanent focus owner. The operation will be cancelled if the
- * Component is not focusable. The permanent focus owner is defined as the
- * last Component in an application to receive a permanent FOCUS_GAINED
- * event. The focus owner and permanent focus owner are equivalent unless
- * a temporary focus change is currently in effect. In such a situation,
- * the permanent focus owner will again be the focus owner when the
- * temporary focus change ends.
- * <p>
- * This method does not actually set the focus to the specified Component.
- * It merely stores the value to be subsequently returned by
- * <code>getPermanentFocusOwner()</code>. Use
- * <code>Component.requestFocus()</code> or
- * <code>Component.requestFocusInWindow()</code> to change the focus owner,
- * subject to platform limitations.
- *
- * @param permanentFocusOwner the permanent focus owner
- * @see #getPermanentFocusOwner
- * @see #getGlobalPermanentFocusOwner
- * @see Component#requestFocus()
- * @see Component#requestFocusInWindow()
- * @see Component#isFocusable
- * @beaninfo
- * bound: true
- */
- protected void setGlobalPermanentFocusOwner(Component permanentFocusOwner)
- {
- Component oldPermanentFocusOwner = null;
- boolean shouldFire = false;
- if (permanentFocusOwner == null || permanentFocusOwner.isFocusable()) {
- synchronized (KeyboardFocusManager.class) {
- oldPermanentFocusOwner = getPermanentFocusOwner();
- try {
- fireVetoableChange("permanentFocusOwner",
- oldPermanentFocusOwner,
- permanentFocusOwner);
- } catch (PropertyVetoException e) {
- // rejected
- return;
- }
- KeyboardFocusManager.permanentFocusOwner = permanentFocusOwner;
- KeyboardFocusManager.
- setMostRecentFocusOwner(permanentFocusOwner);
- shouldFire = true;
- }
- }
- if (shouldFire) {
- firePropertyChange("permanentFocusOwner", oldPermanentFocusOwner,
- permanentFocusOwner);
- }
- }
- /**
- * Returns the focused Window, if the focused Window is in the same context
- * as the calling thread. The focused Window is the Window that is or
- * contains the focus owner.
- *
- * @return the focused Window, or null if the focused Window is not a
- * member of the calling thread's context
- * @see #getGlobalFocusedWindow
- * @see #setGlobalFocusedWindow
- */
- public Window getFocusedWindow() {
- synchronized (KeyboardFocusManager.class) {
- if (focusedWindow == null) {
- return null;
- }
- return (focusedWindow.appContext == AppContext.getAppContext())
- ? focusedWindow
- : null;
- }
- }
- /**
- * Returns the focused Window, even if the calling thread is in a different
- * context than the focused Window. The focused Window is the Window that
- * is or contains the focus owner.
- * <p>
- * This method will throw a SecurityException if this KeyboardFocusManager
- * is not the current KeyboardFocusManager for the calling thread's
- * context.
- *
- * @return the focused Window
- * @see #getFocusedWindow
- * @see #setGlobalFocusedWindow
- * @throws SecurityException if this KeyboardFocusManager is not the
- * current KeyboardFocusManager for the calling thread's context
- */
- protected Window getGlobalFocusedWindow() throws SecurityException {
- synchronized (KeyboardFocusManager.class) {
- if (this == getCurrentKeyboardFocusManager()) {
- return focusedWindow;
- } else {
- throw new SecurityException(notPrivileged);
- }
- }
- }
- /**
- * Sets the focused Window. The focused Window is the Window that is or
- * contains the focus owner. The operation will be cancelled if the
- * specified Window to focus is not a focusable Window.
- * <p>
- * This method does not actually change the focused Window as far as the
- * native windowing system is concerned. It merely stores the value to be
- * subsequently returned by <code>getFocusedWindow()</code>. Use
- * <code>Component.requestFocus()</code> or
- * <code>Component.requestFocusInWindow()</code> to change the focused
- * Window, subject to platform limitations.
- *
- * @param focusedWindow the focused Window
- * @see #getFocusedWindow
- * @see #getGlobalFocusedWindow
- * @see Component#requestFocus()
- * @see Component#requestFocusInWindow()
- * @see Window#isFocusableWindow
- * @beaninfo
- * bound: true
- */
- protected void setGlobalFocusedWindow(Window focusedWindow) {
- Window oldFocusedWindow = null;
- boolean shouldFire = false;
- if (focusedWindow == null || focusedWindow.isFocusableWindow()) {
- synchronized (KeyboardFocusManager.class) {
- oldFocusedWindow = getFocusedWindow();
- try {
- fireVetoableChange("focusedWindow", oldFocusedWindow,
- focusedWindow);
- } catch (PropertyVetoException e) {
- // rejected
- return;
- }
- KeyboardFocusManager.focusedWindow = focusedWindow;
- shouldFire = true;
- }
- }
- if (shouldFire) {
- firePropertyChange("focusedWindow", oldFocusedWindow,
- focusedWindow);
- }
- }
- /**
- * Returns the active Window, if the active Window is in the same context
- * as the calling thread. Only a Frame or a Dialog can be the active
- * Window. The native windowing system may denote the active Window or its
- * children with special decorations, such as a highlighted title bar.
- * The active Window is always either the focused Window, or the first
- * Frame or Dialog that is an owner of the focused Window.
- *
- * @return the active Window, or null if the active Window is not a member
- * of the calling thread's context
- * @see #getGlobalActiveWindow
- * @see #setGlobalActiveWindow
- */
- public Window getActiveWindow() {
- synchronized (KeyboardFocusManager.class) {
- if (activeWindow == null) {
- return null;
- }
- return (activeWindow.appContext == AppContext.getAppContext())
- ? activeWindow
- : null;
- }
- }
- /**
- * Returns the active Window, even if the calling thread is in a different
- * context than the active Window. Only a Frame or a Dialog can be the
- * active Window. The native windowing system may denote the active Window
- * or its children with special decorations, such as a highlighted title
- * bar. The active Window is always either the focused Window, or the first
- * Frame or Dialog that is an owner of the focused Window.
- * <p>
- * This method will throw a SecurityException if this KeyboardFocusManager
- * is not the current KeyboardFocusManager for the calling thread's
- * context.
- *
- * @return the active Window
- * @see #getActiveWindow
- * @see #setGlobalActiveWindow
- * @throws SecurityException if this KeyboardFocusManager is not the
- * current KeyboardFocusManager for the calling thread's context
- */
- protected Window getGlobalActiveWindow() throws SecurityException {
- synchronized (KeyboardFocusManager.class) {
- if (this == getCurrentKeyboardFocusManager()) {
- return activeWindow;
- } else {
- throw new SecurityException(notPrivileged);
- }
- }
- }
- /**
- * Sets the active Window. Only a Frame or a Dialog can be the active
- * Window. The native windowing system may denote the active Window or its
- * children with special decorations, such as a highlighted title bar. The
- * active Window is always either the focused Window, or the first Frame or
- * Dialog that is an owner of the focused Window.
- * <p>
- * This method does not actually change the active Window as far as the
- * native windowing system is concerned. It merely stores the value to be
- * subsequently returned by <code>getActiveWindow()</code>. Use
- * <code>Component.requestFocus()</code> or
- * <code>Component.requestFocusInWindow()</code>to change the active
- * Window, subject to platform limitations.
- *
- * @param activeWindow the active Window
- * @see #getActiveWindow
- * @see #getGlobalActiveWindow
- * @see Component#requestFocus()
- * @see Component#requestFocusInWindow()
- * @beaninfo
- * bound: true
- */
- protected void setGlobalActiveWindow(Window activeWindow) {
- Window oldActiveWindow;
- synchronized (KeyboardFocusManager.class) {
- oldActiveWindow = getActiveWindow();
- try {
- fireVetoableChange("activeWindow", oldActiveWindow,
- activeWindow);
- } catch (PropertyVetoException e) {
- // rejected
- return;
- }
- KeyboardFocusManager.activeWindow = activeWindow;
- }
- firePropertyChange("activeWindow", oldActiveWindow, activeWindow);
- }
- /**
- * Returns the default FocusTraversalPolicy. Top-level components
- * use this value on their creation to initialize their own focus traversal
- * policy by explicit call to Container.setFocusTraversalPolicy.
- *
- * @return the default FocusTraversalPolicy. null will never be returned.
- * @see #setDefaultFocusTraversalPolicy
- * @see Container#setFocusTraversalPolicy
- * @see Container#getFocusTraversalPolicy
- */
- public synchronized FocusTraversalPolicy getDefaultFocusTraversalPolicy() {
- return defaultPolicy;
- }
- /**
- * Sets the default FocusTraversalPolicy. Top-level components
- * use this value on their creation to initialize their own focus traversal
- * policy by explicit call to Container.setFocusTraversalPolicy.
- * Note: this call doesn't affect already created components as they have
- * their policy initialized. Only new components will use this policy as
- * their default policy.
- *
- * @param defaultPolicy the new, default FocusTraversalPolicy
- * @see #getDefaultFocusTraversalPolicy
- * @see Container#setFocusTraversalPolicy
- * @see Container#getFocusTraversalPolicy
- * @throws IllegalArgumentException if defaultPolicy is null
- * @beaninfo
- * bound: true
- */
- public void setDefaultFocusTraversalPolicy(FocusTraversalPolicy
- defaultPolicy) {
- if (defaultPolicy == null) {
- throw new IllegalArgumentException("default focus traversal policy cannot be null");
- }
- FocusTraversalPolicy oldPolicy;
- synchronized (this) {
- oldPolicy = this.defaultPolicy;
- this.defaultPolicy = defaultPolicy;
- }
- firePropertyChange("defaultFocusTraversalPolicy", oldPolicy,
- defaultPolicy);
- }
- /**
- * Sets the default focus traversal keys for a given traversal operation.
- * This traversal key <code>Set</code> will be in effect on all
- * <code>Window</code>s that have no such <code>Set</code> of
- * their own explicitly defined. This <code>Set</code> will also be
- * inherited, recursively, by any child <code>Component</code> of
- * those <code>Windows</code> that has
- * no such <code>Set</code> of its own explicitly defined.
- * <p>
- * The default values for the default focus traversal keys are
- * implementation-dependent. Sun recommends that all implementations for a
- * particular native platform use the same default values. The
- * recommendations for Windows and Unix are listed below. These
- * recommendations are used in the Sun AWT implementations.
- *
- * <table border=1 summary="Recommended default values for focus traversal keys">
- * <tr>
- * <th>Identifier</th>
- * <th>Meaning</th>
- * <th>Default</th>
- * </tr>
- * <tr>
- * <td><code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code></td>
- * <td>Normal forward keyboard traversal</td>
- * <td><code>TAB</code> on <code>KEY_PRESSED</code>,
- * <code>CTRL-TAB</code> on <code>KEY_PRESSED</code></td>
- * </tr>
- * <tr>
- * <td><code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code></td>
- * <td>Normal reverse keyboard traversal</td>
- * <td><code>SHIFT-TAB</code> on <code>KEY_PRESSED</code>,
- * <code>CTRL-SHIFT-TAB</code> on <code>KEY_PRESSED</code></td>
- * </tr>
- * <tr>
- * <td><code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code></td>
- * <td>Go up one focus traversal cycle</td>
- * <td>none</td>
- * </tr>
- * <tr>
- * <td><code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code></td>
- * <td>Go down one focus traversal cycle</td>
- * <td>none</td>
- * </tr>
- * </table>
- *
- * To disable a traversal key, use an empty <code>Set</code>
- * <code>Collections.EMPTY_SET</code> is recommended.
- * <p>
- * Using the <code>AWTKeyStroke</code> API, client code can
- * specify on which of two
- * specific <code>KeyEvent</code>s, <code>KEY_PRESSED</code> or
- * <code>KEY_RELEASED</code>, the focus traversal operation will
- * occur. Regardless of which <code>KeyEvent</code> is specified,
- * however, all <code>KeyEvent</code>s related to the focus
- * traversal key, including the associated <code>KEY_TYPED</code>
- * event, will be consumed, and will not be dispatched
- * to any <code>Component</code>. It is a runtime error to
- * specify a <code>KEY_TYPED</code> event as
- * mapping to a focus traversal operation, or to map the same event to
- * multiple default focus traversal operations.
- *
- * @param id one of
- * <code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code>,
- * <code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code>,
- * <code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code>, or
- * <code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code>
- * @param keystrokes the Set of <code>AWTKeyStroke</code>s for the
- * specified operation
- * @see #getDefaultFocusTraversalKeys
- * @see Component#setFocusTraversalKeys
- * @see Component#getFocusTraversalKeys
- * @throws IllegalArgumentException if id is not one of
- * <code>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</code>,
- * <code>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</code>,
- * <code>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</code>, or
- * <code>KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS</code>,
- * or if keystrokes is <code>null</code>,
- * or if keystrokes contains <code>null</code>,
- * or if any <code>Object</code> in
- * keystrokes is not an <code>AWTKeyStroke</code>,
- * or if any keystroke
- * represents a <code>KEY_TYPED</code> event,
- * or if any keystroke already maps
- * to another default focus traversal operation
- * @beaninfo
- * bound: true
- */
- public void setDefaultFocusTraversalKeys(int id, Set keystrokes)
- {
- if (id < 0 || id >= TRAVERSAL_KEY_LENGTH) {
- throw new IllegalArgumentException("invalid focus traversal key identifier");
- }
- if (keystrokes == null) {
- throw new IllegalArgumentException("cannot set null Set of default focus traversal keys");
- }
- Set oldKeys;
- synchronized (this) {
- for (Iterator iter = keystrokes.iterator(); iter.hasNext(); ) {
- Object obj = iter.next();
- if (obj == null) {
- throw new IllegalArgumentException("cannot set null focus traversal key");
- }
- // Generates a ClassCastException if the element is not an
- // AWTKeyStroke. This is desirable.
- AWTKeyStroke keystroke = (AWTKeyStroke)obj;
- if (keystroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
- throw new IllegalArgumentException("focus traversal keys cannot map to KEY_TYPED events");
- }
- // Check to see if key already maps to another traversal
- // operation
- for (int i = 0; i < TRAVERSAL_KEY_LENGTH; i++) {
- if (i == id) {
- continue;
- }
- if (defaultFocusTraversalKeys[i].contains(keystroke)) {
- throw new IllegalArgumentException("focus traversal keys must be unique for a Component");
- }
- }
- }
- oldKeys = defaultFocusTraversalKeys[id];
- defaultFocusTraversalKeys[id] =
- Collections.unmodifiableSet(new HashSet(keystrokes));
- }
- firePropertyChange(defaultFocusTraversalKeyPropertyNames[id],
- oldKeys, keystrokes);
- }
- /**
- * Returns a Set of default focus traversal keys for a given traversal
- * operation. This traversal key Set will be in effect on all Windows that
- * have no such Set of their own explicitly defined. This Set will also be
- * inherited, recursively, by any child Component of those Windows that has
- * no such Set of its own explicitly defined. (See
- * <code>setDefaultFocusTraversalKeys</code> for a full description of each
- * operation.)
- *
- * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
- * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
- * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
- * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
- * @return the <code>Set</code> of <code>AWTKeyStroke</code>s
- * for the specified operation; the <code>Set</code>
- * will be unmodifiable, and may be empty; <code>null</code>
- * will never be returned
- * @see #setDefaultFocusTraversalKeys
- * @see Component#setFocusTraversalKeys
- * @see Component#getFocusTraversalKeys
- * @throws IllegalArgumentException if id is not one of
- * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
- * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
- * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
- * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
- */
- public Set getDefaultFocusTraversalKeys(int id) {
- if (id < 0 || id >= TRAVERSAL_KEY_LENGTH) {
- throw new IllegalArgumentException("invalid focus traversal key identifier");
- }
- // Okay to return Set directly because it is an unmodifiable view
- return defaultFocusTraversalKeys[id];
- }
- /**
- * Returns the current focus cycle root, if the current focus cycle root is
- * in the same context as the calling thread. If the focus owner is itself
- * a focus cycle root, then it may be ambiguous as to which Components
- * represent the next and previous Components to focus during normal focus
- * traversal. In that case, the current focus cycle root is used to
- * differentiate among the possibilities.
- * <p>
- * This method is intended to be used only by KeyboardFocusManagers and
- * focus implementations. It is not for general client use.
- *
- * @return the current focus cycle root, or null if the current focus cycle
- * root is not a member of the calling thread's context
- * @see #getGlobalCurrentFocusCycleRoot
- * @see #setGlobalCurrentFocusCycleRoot
- */
- public Container getCurrentFocusCycleRoot() {
- synchronized (KeyboardFocusManager.class) {
- if (currentFocusCycleRoot == null) {
- return null;
- }
- return (currentFocusCycleRoot.appContext ==
- AppContext.getAppContext())
- ? currentFocusCycleRoot
- : null;
- }
- }
- /**
- * Returns the current focus cycle root, even if the calling thread is in a
- * different context than the current focus cycle root. If the focus owner
- * is itself a focus cycle root, then it may be ambiguous as to which
- * Components represent the next and previous Components to focus during
- * normal focus traversal. In that case, the current focus cycle root is
- * used to differentiate among the possibilities.
- * <p>
- * This method will throw a SecurityException if this KeyboardFocusManager
- * is not the current KeyboardFocusManager for the calling thread's
- * context.
- *
- * @return the current focus cycle root, or null if the current focus cycle
- * root is not a member of the calling thread's context
- * @see #getCurrentFocusCycleRoot
- * @see #setGlobalCurrentFocusCycleRoot
- * @throws SecurityException if this KeyboardFocusManager is not the
- * current KeyboardFocusManager for the calling thread's context
- */
- protected Container getGlobalCurrentFocusCycleRoot()
- throws SecurityException
- {
- synchronized (KeyboardFocusManager.class) {
- if (this == getCurrentKeyboardFocusManager()) {
- return currentFocusCycleRoot;
- } else {
- throw new SecurityException(notPrivileged);
- }
- }
- }
- /**
- * Sets the current focus cycle root. If the focus owner is itself a focus
- * cycle root, then it may be ambiguous as to which Components represent
- * the next and previous Components to focus during normal focus traversal.
- * In that case, the current focus cycle root is used to differentiate
- * among the possibilities.
- * <p>
- * This method is intended to be used only by KeyboardFocusManagers and
- * focus implementations. It is not for general client use.
- *
- * @param newFocusCycleRoot the new focus cycle root
- * @see #getCurrentFocusCycleRoot
- * @see #getGlobalCurrentFocusCycleRoot
- * @beaninfo
- * bound: true
- */
- public void setGlobalCurrentFocusCycleRoot(Container newFocusCycleRoot) {
- Container oldFocusCycleRoot;
- synchronized (KeyboardFocusManager.class) {
- oldFocusCycleRoot = getCurrentFocusCycleRoot();
- currentFocusCycleRoot = newFocusCycleRoot;
- }
- firePropertyChange("currentFocusCycleRoot", oldFocusCycleRoot,
- newFocusCycleRoot);
- }
- /**
- * Adds a PropertyChangeListener to the listener list. The listener is
- * registered for all bound properties of this class, including the
- * following:
- * <ul>
- * <li>the focus owner ("focusOwner")</li>
- * <li>the permanent focus owner ("permanentFocusOwner")</li>
- * <li>the focused Window ("focusedWindow")</li>
- * <li>the active Window ("activeWindow")</li>
- * <li>the default focus traversal policy
- * ("defaultFocusTraversalPolicy")</li>
- * <li>the Set of default FORWARD_TRAVERSAL_KEYS
- * ("forwardDefaultFocusTraversalKeys")</li>
- * <li>the Set of default BACKWARD_TRAVERSAL_KEYS
- * ("backwardDefaultFocusTraversalKeys")</li>
- * <li>the Set of default UP_CYCLE_TRAVERSAL_KEYS
- * ("upCycleDefaultFocusTraversalKeys")</li>
- * <li>the Set of default DOWN_CYCLE_TRAVERSAL_KEYS
- * ("downCycleDefaultFocusTraversalKeys")</li>
- * <li>the current focus cycle root ("currentFocusCycleRoot")</li>
- * </ul>
- * If listener is null, no exception is thrown and no action is performed.
- *
- * @param listener the PropertyChangeListener to be added
- * @see #removePropertyChangeListener
- * @see #getPropertyChangeListeners
- * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
- */
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- if (listener != null) {
- synchronized (this) {
- if (changeSupport == null) {
- changeSupport = new PropertyChangeSupport(this);
- }
- changeSupport.addPropertyChangeListener(listener);
- }
- }
- }
- /**
- * Removes a PropertyChangeListener from the listener list. This method
- * should be used to remove the PropertyChangeListeners that were
- * registered for all bound properties of this class.
- * <p>
- * If listener is null, no exception is thrown and no action is performed.
- *
- * @param listener the PropertyChangeListener to be removed
- * @see #addPropertyChangeListener
- * @see #getPropertyChangeListeners
- * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
- */
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- if (listener != null) {
- synchronized (this) {
- if (changeSupport != null) {
- changeSupport.removePropertyChangeListener(listener);
- }
- }
- }
- }
- /**
- * Returns an array of all the property change listeners
- * registered on this keyboard focus manager.
- *
- * @return all of this keyboard focus manager's
- * <code>PropertyChangeListener</code>s
- * or an empty array if no property change
- * listeners are currently registered
- *
- * @see #addPropertyChangeListener
- * @see #removePropertyChangeListener
- * @see #getPropertyChangeListeners(java.lang.String)
- * @since 1.4
- */
- public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
- if (changeSupport == null) {
- changeSupport = new PropertyChangeSupport(this);
- }
- return changeSupport.getPropertyChangeListeners();
- }
- /**
- * Adds a PropertyChangeListener to the listener list for a specific
- * property. The specified property may be user-defined, or one of the
- * following:
- * <ul>
- * <li>the focus owner ("focusOwner")</li>
- * <li>the permanent focus owner ("permanentFocusOwner")</li>
- * <li>the focused Window ("focusedWindow")</li>
- * <li>the active Window ("activeWindow")</li>
- * <li>the default focus traversal policy
- * ("defaultFocusTraversalPolicy")</li>
- * <li>the Set of default FORWARD_TRAVERSAL_KEYS
- * ("forwardDefaultFocusTraversalKeys")</li>
- * <li>the Set of default BACKWARD_TRAVERSAL_KEYS
- * ("backwardDefaultFocusTraversalKeys")</li>
- * <li>the Set of default UP_CYCLE_TRAVERSAL_KEYS
- * ("upCycleDefaultFocusTraversalKeys")</li>
- * <li>the Set of default DOWN_CYCLE_TRAVERSAL_KEYS
- * ("downCycleDefaultFocusTraversalKeys")</li>
- * <li>the current focus cycle root ("currentFocusCycleRoot")</li>
- * </ul>
- * If listener is null, no exception is thrown and no action is performed.
- *
- * @param propertyName one of the property names listed above
- * @param listener the PropertyChangeListener to be added
- * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)
- * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
- * @see #getPropertyChangeListeners(java.lang.String)
- */
- public void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- if (listener != null) {
- synchronized (this) {
- if (changeSupport == null) {
- changeSupport = new PropertyChangeSupport(this);
- }
- changeSupport.addPropertyChangeListener(propertyName,
- listener);
- }
- }
- }
- /**
- * Removes a PropertyChangeListener from the listener list for a specific
- * property. This method should be used to remove PropertyChangeListeners
- * that were registered for a specific bound property.
- * <p>
- * If listener is null, no exception is thrown and no action is performed.
- *
- * @param propertyName a valid property name
- * @param listener the PropertyChangeListener to be removed
- * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
- * @see #getPropertyChangeListeners(java.lang.String)
- * @see #removePropertyChangeListener(java.beans.PropertyChangeListener)
- */
- public void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- if (listener != null) {
- synchronized (this) {
- if (changeSupport != null) {
- changeSupport.removePropertyChangeListener(propertyName,
- listener);
- }
- }
- }
- }
- /**
- * Returns an array of all the <code>PropertyChangeListener</code>s
- * associated with the named property.
- *
- * @return all of the <code>PropertyChangeListener</code>s associated with
- * the named property or an empty array if no such listeners have
- * been added.
- *
- * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
- * @see #removePropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
- * @since 1.4
- */
- public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
- if (changeSupport == null) {
- changeSupport = new PropertyChangeSupport(this);
- }
- return changeSupport.getPropertyChangeListeners(propertyName);
- }
- /**
- * Fires a PropertyChangeEvent in response to a change in a bound property.
- * The event will be delivered to all registered PropertyChangeListeners.
- * No event will be delivered if oldValue and newValue are the same.
- *
- * @param propertyName the name of the property that has changed
- * @param oldValue the property's previous value
- * @param newValue the property's new value
- */
- protected void firePropertyChange(String propertyName, Object oldValue,
- Object newValue) {
- PropertyChangeSupport changeSupport = this.changeSupport;
- if (changeSupport != null) {
- changeSupport.firePropertyChange(propertyName, oldValue, newValue);
- }
- }
- /**
- * Adds a VetoableChangeListener to the listener list. The listener is
- * registered for all vetoable properties of this class, including the
- * following:
- * <ul>
- * <li>the focus owner ("focusOwner")</li>
- * <li>the permanent focus owner ("permanentFocusOwner")</li>
- * <li>the focused Window ("focusedWindow")</li>
- * <li>the active Window ("activeWindow")</li>
- * </ul>
- * If listener is null, no exception is thrown and no action is performed.
- *
- * @param listener the VetoableChangeListener to be added
- * @see #removeVetoableChangeListener
- * @see #getVetoableChangeListeners
- * @see #addVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
- */
- public void addVetoableChangeListener(VetoableChangeListener listener) {
- if (listener != null) {
- synchronized (this) {
- if (vetoableSupport == null) {
- vetoableSupport =
- new VetoableChangeSupport(this);
- }
- vetoableSupport.addVetoableChangeListener(listener);
- }
- }
- }
- /**
- * Removes a VetoableChangeListener from the listener list. This method
- * should be used to remove the VetoableChangeListeners that were
- * registered for all vetoable properties of this class.
- * <p>
- * If listener is null, no exception is thrown and no action is performed.
- *
- * @param listener the VetoableChangeListener to be removed
- * @see #addVetoableChangeListener
- * @see #getVetoableChangeListeners
- * @see #removeVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
- */
- public void removeVetoableChangeListener(VetoableChangeListener listener) {
- if (listener != null) {
- synchronized (this) {
- if (vetoableSupport != null) {
- vetoableSupport.removeVetoableChangeListener(listener);
- }
- }
- }
- }
- /**
- * Returns an array of all the vetoable change listeners
- * registered on this keyboard focus manager.
- *
- * @return all of this keyboard focus manager's
- * <code>VetoableChangeListener</code>s
- * or an empty array if no vetoable change
- * listeners are currently registered
- *
- * @see #addVetoableChangeListener
- * @see #removeVetoableChangeListener
- * @see #getVetoableChangeListeners(java.lang.String)
- * @since 1.4
- */
- public synchronized VetoableChangeListener[] getVetoableChangeListeners() {
- if (vetoableSupport == null) {
- vetoableSupport = new VetoableChangeSupport(this);
- }
- return vetoableSupport.getVetoableChangeListeners();
- }
- /**
- * Adds a VetoableChangeListener to the listener list for a specific
- * property. The specified property may be user-defined, or one of the
- * following:
- * <ul>
- * <li>the focus owner ("focusOwner")</li>
- * <li>the permanent focus owner ("permanentFocusOwner")</li>
- * <li>the focused Window ("focusedWindow")</li>
- * <li>the active Window ("activeWindow")</li>
- * </ul>
- * If listener is null, no exception is thrown and no action is performed.
- *
- * @param propertyName one of the property names listed above
- * @param listener the VetoableChangeListener to be added
- * @see #addVetoableChangeListener(java.beans.VetoableChangeListener)
- * @see #removeVetoableChangeListener
- * @see #getVetoableChangeListeners
- */
- public void addVetoableChangeListener(String propertyName,
- VetoableChangeListener listener) {
- if (listener != null) {
- synchronized (this) {
- if (vetoableSupport == null) {
- vetoableSupport =
- new VetoableChangeSupport(this);
- }
- vetoableSupport.addVetoableChangeListener(propertyName,
- listener);
- }
- }
- }
- /**
- * Removes a VetoableChangeListener from the listener list for a specific
- * property. This method should be used to remove VetoableChangeListeners
- * that were registered for a specific bound property.
- * <p>
- * If listener is null, no exception is thrown and no action is performed.
- *
- * @param propertyName a valid property name
- * @param listener the VetoableChangeListener to be removed
- * @see #addVetoableChangeListener
- * @see #getVetoableChangeListeners
- * @see #removeVetoableChangeListener(java.beans.VetoableChangeListener)
- */
- public void removeVetoableChangeListener(String propertyName,
- VetoableChangeListener listener) {
- if (listener != null) {
- synchronized (this) {
- if (vetoableSupport != null) {
- vetoableSupport.removeVetoableChangeListener(propertyName,
- listener);
- }
- }
- }
- }
- /**
- * Returns an array of all the <code>VetoableChangeListener</code>s
- * associated with the named property.
- *
- * @return all of the <code>VetoableChangeListener</code>s associated with
- * the named property or an empty array if no such listeners have
- * been added.
- *
- * @see #addVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
- * @see #removeVetoableChangeListener(java.lang.String,java.beans.VetoableChangeListener)
- * @see #getVetoableChangeListeners
- * @since 1.4
- */
- public synchronized VetoableChangeListener[] getVetoableChangeListeners(String propertyName) {
- if (vetoableSupport == null) {
- vetoableSupport = new VetoableChangeSupport(this);
- }
- return vetoableSupport.getVetoableChangeListeners(propertyName);
- }
- /**
- * Fires a PropertyChangeEvent in response to a change in a vetoable
- * property. The event will be delivered to all registered
- * VetoableChangeListeners. If a VetoableChangeListener throws a
- * PropertyVetoException, a new event is fired reverting all
- * VetoableChangeListeners to the old value and the exception is then
- * rethrown. No event will be delivered if oldValue and newValue are the
- * same.
- *
- * @param propertyName the name of the property that has changed
- * @param oldValue the property's previous value
- * @param newValue the property's new value
- * @throws java.beans.PropertyVetoException if a
- * <code>VetoableChangeListener</code> threw
- * <code>PropertyVetoException</code>
- */
- protected void fireVetoableChange(String propertyName, Object oldValue,
- Object newValue)
- throws PropertyVetoException
- {
- VetoableChangeSupport vetoableSupport =
- this.vetoableSupport;
- if (vetoableSupport != null) {
- vetoableSupport.fireVetoableChange(propertyName, oldValue,
- newValue);
- }
- }
- /**
- * Adds a KeyEventDispatcher to this KeyboardFocusManager's dispatcher
- * chain. This KeyboardFocusManager will request that each
- * KeyEventDispatcher dispatch KeyEvents gene