Methods Summary |
---|
private void | _clearGlobalFocusOwner()
Window activeWindow = markClearGlobalFocusOwner();
peer.clearGlobalFocusOwner(activeWindow);
|
public void | addKeyEventDispatcher(java.awt.KeyEventDispatcher dispatcher)Adds a KeyEventDispatcher to this KeyboardFocusManager's dispatcher
chain. This KeyboardFocusManager will request that each
KeyEventDispatcher dispatch KeyEvents generated by the user before
finally dispatching the KeyEvent itself. KeyEventDispatchers will be
notified in the order in which they were added. Notifications will halt
as soon as one KeyEventDispatcher returns true from its
dispatchKeyEvent method. There is no limit to the total
number of KeyEventDispatchers which can be added, nor to the number of
times which a particular KeyEventDispatcher instance can be added.
If a null dispatcher is specified, no action is taken and no exception
is thrown.
if (dispatcher != null) {
synchronized (this) {
if (keyEventDispatchers == null) {
keyEventDispatchers = new java.util.LinkedList();
}
keyEventDispatchers.add(dispatcher);
}
}
|
public void | addKeyEventPostProcessor(java.awt.KeyEventPostProcessor processor)Adds a KeyEventPostProcessor to this KeyboardFocusManager's post-
processor chain. After a KeyEvent has been dispatched to and handled by
its target, KeyboardFocusManager will request that each
KeyEventPostProcessor perform any necessary post-processing as part
of the KeyEvent's final resolution. KeyEventPostProcessors
will be notified in the order in which they were added; the current
KeyboardFocusManager will be notified last. Notifications will halt
as soon as one KeyEventPostProcessor returns true from its
postProcessKeyEvent method. There is no limit to the the
total number of KeyEventPostProcessors that can be added, nor to the
number of times that a particular KeyEventPostProcessor instance can be
added.
If a null post-processor is specified, no action is taken and no
exception is thrown.
if (processor != null) {
synchronized (this) {
if (keyEventPostProcessors == null) {
keyEventPostProcessors = new java.util.LinkedList();
}
keyEventPostProcessors.add(processor);
}
}
|
public void | addPropertyChangeListener(java.beans.PropertyChangeListener listener)Adds a PropertyChangeListener to the listener list. The listener is
registered for all bound properties of this class, including the
following:
- whether the KeyboardFocusManager is currently managing focus
for this application or applet's browser context
("managingFocus")
- the focus owner ("focusOwner")
- the permanent focus owner ("permanentFocusOwner")
- the focused Window ("focusedWindow")
- the active Window ("activeWindow")
- the default focus traversal policy
("defaultFocusTraversalPolicy")
- the Set of default FORWARD_TRAVERSAL_KEYS
("forwardDefaultFocusTraversalKeys")
- the Set of default BACKWARD_TRAVERSAL_KEYS
("backwardDefaultFocusTraversalKeys")
- the Set of default UP_CYCLE_TRAVERSAL_KEYS
("upCycleDefaultFocusTraversalKeys")
- the Set of default DOWN_CYCLE_TRAVERSAL_KEYS
("downCycleDefaultFocusTraversalKeys")
- the current focus cycle root ("currentFocusCycleRoot")
If listener is null, no exception is thrown and no action is performed.
if (listener != null) {
synchronized (this) {
if (changeSupport == null) {
changeSupport = new PropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(listener);
}
}
|
public void | addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)Adds a PropertyChangeListener to the listener list for a specific
property. The specified property may be user-defined, or one of the
following:
- whether the KeyboardFocusManager is currently managing focus
for this application or applet's browser context
("managingFocus")
- the focus owner ("focusOwner")
- the permanent focus owner ("permanentFocusOwner")
- the focused Window ("focusedWindow")
- the active Window ("activeWindow")
- the default focus traversal policy
("defaultFocusTraversalPolicy")
- the Set of default FORWARD_TRAVERSAL_KEYS
("forwardDefaultFocusTraversalKeys")
- the Set of default BACKWARD_TRAVERSAL_KEYS
("backwardDefaultFocusTraversalKeys")
- the Set of default UP_CYCLE_TRAVERSAL_KEYS
("upCycleDefaultFocusTraversalKeys")
- the Set of default DOWN_CYCLE_TRAVERSAL_KEYS
("downCycleDefaultFocusTraversalKeys")
- the current focus cycle root ("currentFocusCycleRoot")
If listener is null, no exception is thrown and no action is performed.
if (listener != null) {
synchronized (this) {
if (changeSupport == null) {
changeSupport = new PropertyChangeSupport(this);
}
changeSupport.addPropertyChangeListener(propertyName,
listener);
}
}
|
public void | addVetoableChangeListener(java.beans.VetoableChangeListener listener)Adds a VetoableChangeListener to the listener list. The listener is
registered for all vetoable properties of this class, including the
following:
- the focus owner ("focusOwner")
- the permanent focus owner ("permanentFocusOwner")
- the focused Window ("focusedWindow")
- the active Window ("activeWindow")
If listener is null, no exception is thrown and no action is performed.
if (listener != null) {
synchronized (this) {
if (vetoableSupport == null) {
vetoableSupport =
new VetoableChangeSupport(this);
}
vetoableSupport.addVetoableChangeListener(listener);
}
}
|
public void | addVetoableChangeListener(java.lang.String propertyName, java.beans.VetoableChangeListener listener)Adds a VetoableChangeListener to the listener list for a specific
property. The specified property may be user-defined, or one of the
following:
- the focus owner ("focusOwner")
- the permanent focus owner ("permanentFocusOwner")
- the focused Window ("focusedWindow")
- the active Window ("activeWindow")
If listener is null, no exception is thrown and no action is performed.
if (listener != null) {
synchronized (this) {
if (vetoableSupport == null) {
vetoableSupport =
new VetoableChangeSupport(this);
}
vetoableSupport.addVetoableChangeListener(propertyName,
listener);
}
}
|
public void | clearGlobalFocusOwner()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 requestFocus() . This operation
does not change the focused or active Windows.
if (!GraphicsEnvironment.isHeadless()) {
// Toolkit must be fully initialized, otherwise
// _clearGlobalFocusOwner will crash or throw an exception
Toolkit.getDefaultToolkit();
_clearGlobalFocusOwner();
}
|
void | clearMarkers()Clears markers queue
This method is not intended to be overridden by KFM's.
Only DefaultKeyboardFocusManager can implement it.
|
static void | clearMostRecentFocusOwner(java.awt.Component comp)
Container window;
if (comp == null) {
return;
}
synchronized (comp.getTreeLock()) {
window = comp.getParent();
while (window != null && !(window instanceof Window)) {
window = window.getParent();
}
}
synchronized (KeyboardFocusManager.class) {
if ((window != null)
&& (getMostRecentFocusOwner((Window)window) == comp))
{
setMostRecentFocusOwner((Window)window, null);
}
// Also clear temporary lost component stored in Window
if (window != null) {
Window realWindow = (Window)window;
if (realWindow.getTemporaryLostComponent() == comp) {
realWindow.setTemporaryLostComponent(null);
}
}
}
|
protected abstract void | dequeueKeyEvents(long after, java.awt.Component untilFocused)Called by the AWT to notify the KeyboardFocusManager that it should
cancel delayed dispatching of KeyEvents. All KeyEvents which were
enqueued because of a call to enqueueKeyEvents with the
same timestamp and Component should be released for normal dispatching
to the current focus owner. If the given timestamp is less than zero,
the outstanding enqueue request for the given Component with the
oldest timestamp (if any) should be cancelled.
|
protected abstract void | discardKeyEvents(java.awt.Component comp)Called by the AWT to notify the KeyboardFocusManager that it should
cancel delayed dispatching of KeyEvents. All KeyEvents which were
enqueued because of one or more calls to enqueueKeyEvents
with the same Component should be discarded.
|
public abstract boolean | dispatchEvent(java.awt.AWTEvent e)This method is called by the AWT event dispatcher requesting that the
current KeyboardFocusManager dispatch the specified event on its behalf.
It is expected that all KeyboardFocusManagers will dispatch all
FocusEvents, all WindowEvents related to focus, and all KeyEvents.
These events should be dispatched based on the KeyboardFocusManager's
notion of the focus owner and the focused and active Windows, sometimes
overriding the source of the specified AWTEvent. Dispatching must be
done using redispatchEvent to prevent the AWT event
dispatcher from recursively requesting that the KeyboardFocusManager
dispatch the event again. If this method returns false ,
then the AWT event dispatcher will attempt to dispatch the event itself.
|
public abstract boolean | dispatchKeyEvent(java.awt.event.KeyEvent e)Typically this method will be called by dispatchEvent if no
other KeyEventDispatcher in the dispatcher chain dispatched the
KeyEvent, or if no other KeyEventDispatchers are registered. If an
implementation of this method returns false ,
dispatchEvent may try to dispatch the KeyEvent itself, or
may simply return false . If true is returned,
dispatchEvent should return true as well.
|
public abstract void | downFocusCycle(java.awt.Container aContainer)Moves the focus down one focus traversal cycle. Typically, if
aContainer is a focus cycle root, then the focus owner is set to
aContainer's default Component to focus, and the current focus cycle
root is set to aContainer. If aContainer is not a focus cycle root, then
no focus traversal operation occurs.
|
public final void | downFocusCycle()Moves the focus down one focus traversal cycle from the current focus
owner, if and only if the current focus owner is a Container that is a
focus cycle root. Typically, the focus owner is set to the current focus
owner's default Component to focus, and the current focus cycle root is
set to the current focus owner. If the current focus owner is not a
Container that is a focus cycle root, then no focus traversal operation
occurs.
Component focusOwner = getFocusOwner();
if (focusOwner instanceof Container) {
downFocusCycle((Container)focusOwner);
}
|
void | dumpRequests()Dumps the list of focus requests to stderr
System.err.println(">>> Requests dump, time: " + System.currentTimeMillis());
synchronized (heavyweightRequests) {
Iterator iter = heavyweightRequests.iterator();
while (iter.hasNext()) {
HeavyweightFocusRequest req = (HeavyweightFocusRequest)iter.next();
System.err.println(">>> Req: " + req);
}
}
System.err.println("");
|
protected abstract void | enqueueKeyEvents(long after, java.awt.Component untilFocused)Called by the AWT to notify the KeyboardFocusManager that it should
delay dispatching of KeyEvents until the specified Component becomes
the focus owner. If client code requests a focus change, and the AWT
determines that this request might be granted by the native windowing
system, then the AWT will call this method. It is the responsibility of
the KeyboardFocusManager to delay dispatching of KeyEvents with
timestamps later than the specified time stamp until the specified
Component receives a FOCUS_GAINED event, or the AWT cancels the delay
request by invoking dequeueKeyEvents or
discardKeyEvents .
|
protected void | firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)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.
PropertyChangeSupport changeSupport = this.changeSupport;
if (changeSupport != null) {
changeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
|
protected void | fireVetoableChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)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.
VetoableChangeSupport vetoableSupport =
this.vetoableSupport;
if (vetoableSupport != null) {
vetoableSupport.fireVetoableChange(propertyName, oldValue,
newValue);
}
|
public abstract void | focusNextComponent(java.awt.Component aComponent)Focuses the Component after aComponent, typically based on a
FocusTraversalPolicy.
|
public final void | focusNextComponent()Focuses the Component after the current focus owner.
Component focusOwner = getFocusOwner();
if (focusOwner != null) {
focusNextComponent(focusOwner);
}
|
public abstract void | focusPreviousComponent(java.awt.Component aComponent)Focuses the Component before aComponent, typically based on a
FocusTraversalPolicy.
|
public final void | focusPreviousComponent()Focuses the Component before the current focus owner.
Component focusOwner = getFocusOwner();
if (focusOwner != null) {
focusPreviousComponent(focusOwner);
}
|
private static boolean | focusedWindowChanged(java.awt.Component to, java.awt.Component from)
Window wto = Component.getContainingWindow(to);
Window wfrom = Component.getContainingWindow(from);
if (wto == null && wfrom == null) {
return true;
}
if (wto == null) {
return true;
}
if (wfrom == null) {
return true;
}
return (wto != wfrom);
|
public java.awt.Window | getActiveWindow()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.
synchronized (KeyboardFocusManager.class) {
if (activeWindow == null) {
return null;
}
return (activeWindow.appContext == AppContext.getAppContext())
? activeWindow
: null;
}
|
public java.awt.Container | getCurrentFocusCycleRoot()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.
This method is intended to be used only by KeyboardFocusManagers and
focus implementations. It is not for general client use.
synchronized (KeyboardFocusManager.class) {
if (currentFocusCycleRoot == null) {
return null;
}
return (currentFocusCycleRoot.appContext ==
AppContext.getAppContext())
? currentFocusCycleRoot
: null;
}
|
public static java.awt.KeyboardFocusManager | getCurrentKeyboardFocusManager()Returns the current KeyboardFocusManager instance for the calling
thread's context.
return getCurrentKeyboardFocusManager(AppContext.getAppContext());
|
static synchronized java.awt.KeyboardFocusManager | getCurrentKeyboardFocusManager(sun.awt.AppContext appcontext)
KeyboardFocusManager manager = (KeyboardFocusManager)
appcontext.get(KeyboardFocusManager.class);
if (manager == null) {
manager = new DefaultKeyboardFocusManager();
appcontext.put(KeyboardFocusManager.class, manager);
}
return manager;
|
final java.awt.SequencedEvent | getCurrentSequencedEvent()
synchronized (SequencedEvent.class) {
return currentSequencedEvent;
}
|
java.awt.Component | getCurrentWaitingRequest(java.awt.Component parent)
synchronized (heavyweightRequests) {
HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
((heavyweightRequests.size() > 0)
? heavyweightRequests.getFirst() : null);
if (hwFocusRequest != null) {
if (hwFocusRequest.heavyweight == parent) {
LightweightFocusRequest lwFocusRequest =
(LightweightFocusRequest)hwFocusRequest.
lightweightRequests.getFirst();
if (lwFocusRequest != null) {
return lwFocusRequest.component;
}
}
}
}
return null;
|
public java.util.Set | getDefaultFocusTraversalKeys(int id)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
setDefaultFocusTraversalKeys for a full description of each
operation.)
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];
|
public synchronized java.awt.FocusTraversalPolicy | getDefaultFocusTraversalPolicy()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 defaultPolicy;
|
public java.awt.Component | getFocusOwner()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.
synchronized (KeyboardFocusManager.class) {
if (focusOwner == null) {
return null;
}
return (focusOwner.appContext == AppContext.getAppContext())
? focusOwner
: null;
}
|
public java.awt.Window | getFocusedWindow()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.
synchronized (KeyboardFocusManager.class) {
if (focusedWindow == null) {
return null;
}
return (focusedWindow.appContext == AppContext.getAppContext())
? focusedWindow
: null;
}
|
protected java.awt.Window | getGlobalActiveWindow()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.
This method will throw a SecurityException if this KeyboardFocusManager
is not the current KeyboardFocusManager for the calling thread's
context.
synchronized (KeyboardFocusManager.class) {
if (this == getCurrentKeyboardFocusManager()) {
return activeWindow;
} else {
if (focusLog.isLoggable(Level.FINE)) focusLog.fine("This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
throw new SecurityException(notPrivileged);
}
}
|
protected java.awt.Container | getGlobalCurrentFocusCycleRoot()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.
This method will throw a SecurityException if this KeyboardFocusManager
is not the current KeyboardFocusManager for the calling thread's
context.
synchronized (KeyboardFocusManager.class) {
if (this == getCurrentKeyboardFocusManager()) {
return currentFocusCycleRoot;
} else {
if (focusLog.isLoggable(Level.FINE)) focusLog.fine("This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
throw new SecurityException(notPrivileged);
}
}
|
protected java.awt.Component | getGlobalFocusOwner()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.
This method will throw a SecurityException if this KeyboardFocusManager
is not the current KeyboardFocusManager for the calling thread's
context.
synchronized (KeyboardFocusManager.class) {
if (this == getCurrentKeyboardFocusManager()) {
return focusOwner;
} else {
if (focusLog.isLoggable(Level.FINE)) focusLog.fine("This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
throw new SecurityException(notPrivileged);
}
}
|
protected java.awt.Window | getGlobalFocusedWindow()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.
This method will throw a SecurityException if this KeyboardFocusManager
is not the current KeyboardFocusManager for the calling thread's
context.
synchronized (KeyboardFocusManager.class) {
if (this == getCurrentKeyboardFocusManager()) {
return focusedWindow;
} else {
if (focusLog.isLoggable(Level.FINE)) focusLog.fine("This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
throw new SecurityException(notPrivileged);
}
}
|
protected java.awt.Component | getGlobalPermanentFocusOwner()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.
This method will throw a SecurityException if this KeyboardFocusManager
is not the current KeyboardFocusManager for the calling thread's
context.
synchronized (KeyboardFocusManager.class) {
if (this == getCurrentKeyboardFocusManager()) {
return permanentFocusOwner;
} else {
if (focusLog.isLoggable(Level.FINE)) focusLog.fine("This manager is " + this + ", current is " + getCurrentKeyboardFocusManager());
throw new SecurityException(notPrivileged);
}
}
|
static java.awt.Component | getHeavyweight(java.awt.Component comp)
if (comp == null || comp.getPeer() == null) {
return null;
} else if (comp.getPeer() instanceof LightweightPeer) {
return comp.getNativeContainer();
} else {
return comp;
}
|
protected synchronized java.util.List | getKeyEventDispatchers()Returns this KeyboardFocusManager's KeyEventDispatcher chain as a List.
The List will not include this KeyboardFocusManager unless it was
explicitly re-registered via a call to
addKeyEventDispatcher . If no other KeyEventDispatchers are
registered, implementations are free to return null or a List of length
0. Client code should not assume one behavior over another, nor should
it assume that the behavior, once established, will not change.
return (keyEventDispatchers != null)
? (java.util.List)keyEventDispatchers.clone()
: null;
|
protected java.util.List | getKeyEventPostProcessors()Returns this KeyboardFocusManager's KeyEventPostProcessor chain as a
List. The List will not include this KeyboardFocusManager unless it was
explicitly added via a call to addKeyEventPostProcessor . If
no KeyEventPostProcessors are registered, implementations are free to
return null or a List of length 0. Client code should not assume one
behavior over another, nor should it assume that the behavior, once
established, will not change.
return (keyEventPostProcessors != null)
? (java.util.List)keyEventPostProcessors.clone()
: null;
|
static synchronized java.awt.Component | getMostRecentFocusOwner(java.awt.Window window)
WeakReference weakValue =
(WeakReference)mostRecentFocusOwners.get(window);
return weakValue == null ? null : (Component)weakValue.get();
|
java.awt.Component | getNativeFocusOwner()
return peer.getCurrentFocusOwner();
|
java.awt.Window | getNativeFocusedWindow()
return peer.getCurrentFocusedWindow();
|
public java.awt.Component | getPermanentFocusOwner()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.
synchronized (KeyboardFocusManager.class) {
if (permanentFocusOwner == null) {
return null;
}
return (permanentFocusOwner.appContext ==
AppContext.getAppContext())
? permanentFocusOwner
: null;
}
|
public synchronized java.beans.PropertyChangeListener[] | getPropertyChangeListeners()Returns an array of all the property change listeners
registered on this keyboard focus manager.
if (changeSupport == null) {
changeSupport = new PropertyChangeSupport(this);
}
return changeSupport.getPropertyChangeListeners();
|
public synchronized java.beans.PropertyChangeListener[] | getPropertyChangeListeners(java.lang.String propertyName)Returns an array of all the PropertyChangeListener s
associated with the named property.
if (changeSupport == null) {
changeSupport = new PropertyChangeSupport(this);
}
return changeSupport.getPropertyChangeListeners(propertyName);
|
public synchronized java.beans.VetoableChangeListener[] | getVetoableChangeListeners()Returns an array of all the vetoable change listeners
registered on this keyboard focus manager.
if (vetoableSupport == null) {
vetoableSupport = new VetoableChangeSupport(this);
}
return vetoableSupport.getVetoableChangeListeners();
|
public synchronized java.beans.VetoableChangeListener[] | getVetoableChangeListeners(java.lang.String propertyName)Returns an array of all the VetoableChangeListener s
associated with the named property.
if (vetoableSupport == null) {
vetoableSupport = new VetoableChangeSupport(this);
}
return vetoableSupport.getVetoableChangeListeners(propertyName);
|
static void | heavyweightButtonDown(java.awt.Component heavyweight, long time)
heavyweightButtonDown(heavyweight, time, false);
|
static void | heavyweightButtonDown(java.awt.Component heavyweight, long time, boolean acceptDuplicates)
if (dbg.on) {
dbg.assertion(heavyweight != null);
dbg.assertion(time != 0);
}
KeyboardFocusManager manager = getCurrentKeyboardFocusManager(SunToolkit.targetToAppContext(heavyweight));
synchronized (heavyweightRequests) {
HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
((heavyweightRequests.size() > 0)
? heavyweightRequests.getLast() : null);
Component currentNativeFocusOwner = (hwFocusRequest == null)
? manager.getNativeFocusOwner()
: hwFocusRequest.heavyweight;
// Behavior for all use cases:
// 1. Heavyweight leaf Components (e.g., Button, Checkbox, Choice,
// List, TextComponent, Canvas) that respond to button down.
//
// Native platform will generate a FOCUS_GAINED if and only if
// the Component is not the focus owner (or, will not be the
// focus owner when all outstanding focus requests are
// processed).
//
// 2. Panel with no descendants.
//
// Same as (1).
//
// 3. Panel with at least one heavyweight descendant.
//
// This function should NOT be called for this case!
//
// 4. Panel with only lightweight descendants.
//
// Native platform will generate a FOCUS_GAINED if and only if
// neither the Panel, nor any of its recursive, lightweight
// descendants, is the focus owner. However, we want a
// requestFocus() for any lightweight descendant to win out over
// the focus request for the Panel. To accomplish this, we
// differ from the algorithm for shouldNativelyFocusHeavyweight
// as follows:
// a. If the requestFocus() for a lightweight descendant has
// been fully handled by the time this function is invoked,
// then 'hwFocusRequest' will be null and 'heavyweight'
// will be the native focus owner. Do *not* synthesize a
// focus transfer to the Panel.
// b. If the requestFocus() for a lightweight descendant has
// been recorded, but not handled, then 'hwFocusRequest'
// will be non-null and 'hwFocusRequest.heavyweight' will
// equal 'heavyweight'. Do *not* append 'heavyweight' to
// hwFocusRequest.lightweightRequests.
// c. If the requestFocus() for a lightweight descendant is
// yet to be made, then post a new HeavyweightFocusRequest.
// If no lightweight descendant ever requests focus, then
// the Panel will get focus. If some descendant does, then
// the descendant will get focus by either a synthetic
// focus transfer, or a lightweightRequests focus transfer.
if (acceptDuplicates || heavyweight != currentNativeFocusOwner) {
getCurrentKeyboardFocusManager
(SunToolkit.targetToAppContext(heavyweight)).
enqueueKeyEvents(time, heavyweight);
heavyweightRequests.add
(new HeavyweightFocusRequest(heavyweight, heavyweight,
false));
}
}
|
static java.util.Set | initFocusTraversalKeysSet(java.lang.String value, java.util.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);
|
private static native void | initIDs()Initialize JNI field and method IDs
|
private void | initPeer()
if (Toolkit.getDefaultToolkit() instanceof HeadlessToolkit){
peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createKeyboardFocusManagerPeer(this);
}
if (Toolkit.getDefaultToolkit() instanceof SunToolkit){
peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createKeyboardFocusManagerPeer(this);
}
|
static boolean | isProxyActive(java.awt.event.KeyEvent e)
if (!GraphicsEnvironment.isHeadless()) {
return isProxyActiveImpl(e);
} else {
return false;
}
|
private static boolean | isProxyActiveImpl(java.awt.event.KeyEvent e)
if (proxyActive == null) {
proxyActive = (Field) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
Field field = null;
try {
field = KeyEvent.class.getDeclaredField("isProxyActive");
if (field != null) {
field.setAccessible(true);
}
} catch (NoSuchFieldException nsf) {
assert(false);
}
return field;
}
});
}
try {
return proxyActive.getBoolean(e);
} catch (IllegalAccessException iae) {
assert(false);
}
return false;
|
private static boolean | isTemporary(java.awt.Component to, java.awt.Component from)
Window wto = Component.getContainingWindow(to);
Window wfrom = Component.getContainingWindow(from);
if (wto == null && wfrom == null) {
return false;
}
if (wto == null) {
return true;
}
if (wfrom == null) {
return false;
}
return (wto != wfrom);
|
static java.awt.Window | markClearGlobalFocusOwner()Returns the Window which will be active after processing this request,
or null if this is a duplicate request. The active Window is useful
because some native platforms do not support setting the native focus
owner to null. On these platforms, the obvious choice is to set the
focus owner to the focus proxy of the active Window.
synchronized (heavyweightRequests) {
HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
((heavyweightRequests.size() > 0)
? heavyweightRequests.getLast() : null);
if (hwFocusRequest ==
HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
{
// duplicate request
return null;
}
KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
heavyweightRequests.add
(HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER);
Component activeWindow = ((hwFocusRequest != null)
? Component.getContainingWindow(hwFocusRequest.heavyweight)
: manager.getNativeFocusedWindow());
while (activeWindow != null &&
!((activeWindow instanceof Frame) ||
(activeWindow instanceof Dialog)))
{
activeWindow = activeWindow.getParent();
}
return (Window)activeWindow;
}
|
public abstract boolean | postProcessKeyEvent(java.awt.event.KeyEvent e)This method will be called by dispatchKeyEvent .
By default, this method will handle any unconsumed KeyEvents that
map to an AWT MenuShortcut by consuming the event
and activating the shortcut.
|
static void | processCurrentLightweightRequests()
KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
LinkedList localLightweightRequests = null;
synchronized(heavyweightRequests) {
if (currentLightweightRequests != null) {
clearingCurrentLightweightRequests = true;
localLightweightRequests = currentLightweightRequests;
currentLightweightRequests = null;
} else {
// do nothing
return;
}
}
try {
if (localLightweightRequests != null) {
for (Iterator iter = localLightweightRequests.iterator();
iter.hasNext(); )
{
Component currentFocusOwner = manager.
getGlobalFocusOwner();
if (currentFocusOwner == null) {
// If this ever happens, a focus change has been
// rejected. Stop generating more focus changes.
break;
}
LightweightFocusRequest lwFocusRequest =
(LightweightFocusRequest)iter.next();
FocusEvent currentFocusOwnerEvent =
new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
lwFocusRequest.temporary,
lwFocusRequest.component);
FocusEvent newFocusOwnerEvent =
new FocusEvent(lwFocusRequest.component,
FocusEvent.FOCUS_GAINED,
lwFocusRequest.temporary,
currentFocusOwner);
((AWTEvent) currentFocusOwnerEvent).isPosted = true;
currentFocusOwner.dispatchEvent(currentFocusOwnerEvent);
((AWTEvent) newFocusOwnerEvent).isPosted = true;
lwFocusRequest.component.
dispatchEvent(newFocusOwnerEvent);
}
}
} finally {
clearingCurrentLightweightRequests = false;
localLightweightRequests = null;
}
|
public abstract void | processKeyEvent(java.awt.Component focusedComponent, java.awt.event.KeyEvent e)This method initiates a focus traversal operation if and only if the
KeyEvent represents a focus traversal key for the specified
focusedComponent. It is expected that focusedComponent is the current
focus owner, although this need not be the case. If it is not,
focus traversal will nevertheless proceed as if focusedComponent
were the current focus owner.
|
static boolean | processSynchronousLightweightTransfer(java.awt.Component heavyweight, java.awt.Component descendant, boolean temporary, boolean focusedWindowChangeAllowed, long time)
Window parentWindow = Component.getContainingWindow(heavyweight);
if (parentWindow == null || !parentWindow.syncLWRequests) {
return false;
}
if (descendant == null) {
// Focus transfers from a lightweight child back to the
// heavyweight Container should be treated like lightweight
// focus transfers.
descendant = heavyweight;
}
KeyboardFocusManager manager = getCurrentKeyboardFocusManager(SunToolkit.targetToAppContext(descendant));
FocusEvent currentFocusOwnerEvent = null;
FocusEvent newFocusOwnerEvent = null;
Component currentFocusOwner = manager.getGlobalFocusOwner();
synchronized (heavyweightRequests) {
HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
((heavyweightRequests.size() > 0)
? heavyweightRequests.getLast() : null);
if (hwFocusRequest == null &&
heavyweight == manager.getNativeFocusOwner())
{
if (descendant == currentFocusOwner) {
// Redundant request.
return true;
}
// 'heavyweight' owns the native focus and there are no pending
// requests. 'heavyweight' must be a Container and
// 'descendant' must not be the focus owner. Otherwise,
// we would never have gotten this far.
manager.enqueueKeyEvents(time, descendant);
hwFocusRequest =
new HeavyweightFocusRequest(heavyweight, descendant,
temporary);
heavyweightRequests.add(hwFocusRequest);
if (currentFocusOwner != null) {
currentFocusOwnerEvent =
new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
temporary, descendant);
}
newFocusOwnerEvent =
new FocusEvent(descendant, FocusEvent.FOCUS_GAINED,
temporary, currentFocusOwner);
}
}
boolean result = false;
synchronized(Component.LOCK) {
if (currentFocusOwnerEvent != null && currentFocusOwner != null) {
((AWTEvent) currentFocusOwnerEvent).isPosted = true;
currentFocusOwner.dispatchEvent(currentFocusOwnerEvent);
result = true;
}
if (newFocusOwnerEvent != null && descendant != null) {
((AWTEvent) newFocusOwnerEvent).isPosted = true;
descendant.dispatchEvent(newFocusOwnerEvent);
result = true;
}
}
return result;
|
public final void | redispatchEvent(java.awt.Component target, java.awt.AWTEvent e)Redispatches an AWTEvent in such a way that the AWT event dispatcher
will not recursively request that the KeyboardFocusManager, or any
installed KeyEventDispatchers, dispatch the event again. Client
implementations of dispatchEvent and client-defined
KeyEventDispatchers must call redispatchEvent(target, e)
instead of target.dispatchEvent(e) to dispatch an event.
This method is intended to be used only by KeyboardFocusManagers and
KeyEventDispatchers. It is not for general client use.
e.focusManagerIsDispatching = true;
target.dispatchEvent(e);
e.focusManagerIsDispatching = false;
|
static boolean | removeFirstRequest()
KeyboardFocusManager manager =
KeyboardFocusManager.getCurrentKeyboardFocusManager();
synchronized(heavyweightRequests) {
HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
((heavyweightRequests.size() > 0)
? heavyweightRequests.getFirst() : null);
if (hwFocusRequest != null) {
heavyweightRequests.removeFirst();
if (hwFocusRequest.lightweightRequests != null) {
for (Iterator lwIter = hwFocusRequest.lightweightRequests.
iterator();
lwIter.hasNext(); )
{
manager.dequeueKeyEvents
(-1, ((LightweightFocusRequest)lwIter.next()).
component);
}
}
}
// Fix for 4799136 - clear type-ahead markers if requests queue is empty
// We do it here because this method is called only when problems happen
if (heavyweightRequests.size() == 0) {
manager.clearMarkers();
}
return (heavyweightRequests.size() > 0);
}
|
public void | removeKeyEventDispatcher(java.awt.KeyEventDispatcher dispatcher)Removes a KeyEventDispatcher which was previously added to this
KeyboardFocusManager's dispatcher chain. This KeyboardFocusManager
cannot itself be removed, unless it was explicitly re-registered via a
call to addKeyEventDispatcher .
If a null dispatcher is specified, if the specified dispatcher is not
in the dispatcher chain, or if this KeyboardFocusManager is specified
without having been explicitly re-registered, no action is taken and no
exception is thrown.
if (dispatcher != null) {
synchronized (this) {
if (keyEventDispatchers != null) {
keyEventDispatchers.remove(dispatcher);
}
}
}
|
public void | removeKeyEventPostProcessor(java.awt.KeyEventPostProcessor processor)Removes a previously added KeyEventPostProcessor from this
KeyboardFocusManager's post-processor chain. This KeyboardFocusManager
cannot itself be entirely removed from the chain. Only additional
references added via addKeyEventPostProcessor can be
removed.
If a null post-processor is specified, if the specified post-processor
is not in the post-processor chain, or if this KeyboardFocusManager is
specified without having been explicitly added, no action is taken and
no exception is thrown.
if (processor != null) {
synchronized (this) {
if (keyEventPostProcessors != null) {
keyEventPostProcessors.remove(processor);
}
}
}
|
static void | removeLastFocusRequest(java.awt.Component heavyweight)
if (dbg.on) {
dbg.assertion(heavyweight != null);
}
KeyboardFocusManager manager =
KeyboardFocusManager.getCurrentKeyboardFocusManager();
synchronized(heavyweightRequests) {
HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
((heavyweightRequests.size() > 0)
? heavyweightRequests.getLast() : null);
if (hwFocusRequest != null &&
hwFocusRequest.heavyweight == heavyweight) {
heavyweightRequests.removeLast();
}
// Fix for 4799136 - clear type-ahead markers if requests queue is empty
// We do it here because this method is called only when problems happen
if (heavyweightRequests.size() == 0) {
manager.clearMarkers();
}
}
|
public void | removePropertyChangeListener(java.beans.PropertyChangeListener 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.
If listener is null, no exception is thrown and no action is performed.
if (listener != null) {
synchronized (this) {
if (changeSupport != null) {
changeSupport.removePropertyChangeListener(listener);
}
}
}
|
public void | removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener 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.
If listener is null, no exception is thrown and no action is performed.
if (listener != null) {
synchronized (this) {
if (changeSupport != null) {
changeSupport.removePropertyChangeListener(propertyName,
listener);
}
}
}
|
public void | removeVetoableChangeListener(java.beans.VetoableChangeListener 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.
If listener is null, no exception is thrown and no action is performed.
if (listener != null) {
synchronized (this) {
if (vetoableSupport != null) {
vetoableSupport.removeVetoableChangeListener(listener);
}
}
}
|
public void | removeVetoableChangeListener(java.lang.String propertyName, java.beans.VetoableChangeListener 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.
If listener is null, no exception is thrown and no action is performed.
if (listener != null) {
synchronized (this) {
if (vetoableSupport != null) {
vetoableSupport.removeVetoableChangeListener(propertyName,
listener);
}
}
}
|
static java.awt.AWTEvent | retargetFocusEvent(java.awt.AWTEvent event)
if (clearingCurrentLightweightRequests) {
return event;
}
KeyboardFocusManager manager = getCurrentKeyboardFocusManager();
if (focusLog.isLoggable(Level.FINE)) {
if (event instanceof FocusEvent || event instanceof WindowEvent) {
focusLog.log(Level.FINE, ">>> {0}", new Object[] {event});
}
if (focusLog.isLoggable(Level.FINER) && event instanceof KeyEvent) {
focusLog.log(Level.FINER, " focus owner is {0}", new Object[] {manager.getGlobalFocusOwner()});
focusLog.log(Level.FINER, ">>> {0}", new Object[] {event});
}
}
synchronized(heavyweightRequests) {
/*
* This code handles FOCUS_LOST event which is generated by
* DefaultKeyboardFocusManager for FOCUS_GAINED.
*
* This code based on knowledge of DefaultKeyboardFocusManager's
* implementation and might be not applicable for another
* KeyboardFocusManager.
*
* Fix for 4472032
*/
if (newFocusOwner != null &&
event.getID() == FocusEvent.FOCUS_LOST)
{
FocusEvent fe = (FocusEvent)event;
if (manager.getGlobalFocusOwner() == fe.getComponent() &&
fe.getOppositeComponent() == newFocusOwner)
{
newFocusOwner = null;
return event;
}
}
}
processCurrentLightweightRequests();
switch (event.getID()) {
case FocusEvent.FOCUS_GAINED: {
event = retargetFocusGained((FocusEvent)event);
break;
}
case FocusEvent.FOCUS_LOST: {
event = retargetFocusLost((FocusEvent)event);
break;
}
default:
/* do nothing */
}
return event;
|
static java.awt.event.FocusEvent | retargetFocusGained(java.awt.event.FocusEvent fe)
assert (fe.getID() == FocusEvent.FOCUS_GAINED);
Component currentFocusOwner = getCurrentKeyboardFocusManager().
getGlobalFocusOwner();
Component source = fe.getComponent();
Component opposite = fe.getOppositeComponent();
Component nativeSource = getHeavyweight(source);
synchronized (heavyweightRequests) {
HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
((heavyweightRequests.size() > 0)
? heavyweightRequests.getFirst() : null);
if (hwFocusRequest == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
{
return retargetUnexpectedFocusEvent(fe);
}
if (source != null && nativeSource == null && hwFocusRequest != null) {
// if source w/o peer and
// if source is equal to first lightweight
// then we should correct source and nativeSource
if (source == hwFocusRequest.getFirstLightweightRequest().component)
{
source = hwFocusRequest.heavyweight;
nativeSource = source; // source is heavuweight itself
}
}
if (hwFocusRequest != null &&
nativeSource == hwFocusRequest.heavyweight)
{
// Focus change as a result of a known call to requestFocus(),
// or known click on a peer focusable heavyweight Component.
heavyweightRequests.removeFirst();
LightweightFocusRequest lwFocusRequest =
(LightweightFocusRequest)hwFocusRequest.
lightweightRequests.removeFirst();
Component newSource = lwFocusRequest.component;
if (currentFocusOwner != null) {
/*
* Since we receive FOCUS_GAINED when current focus
* owner is not null, correcponding FOCUS_LOST is supposed
* to be lost. And so, we keep new focus owner
* to determine synthetic FOCUS_LOST event which will be
* generated by KeyboardFocusManager for this FOCUS_GAINED.
*
* This code based on knowledge of
* DefaultKeyboardFocusManager's implementation and might
* be not applicable for another KeyboardFocusManager.
*/
newFocusOwner = newSource;
}
boolean temporary = (opposite == null ||
isTemporary(newSource, opposite))
? false
: lwFocusRequest.temporary;
if (hwFocusRequest.lightweightRequests.size() > 0) {
currentLightweightRequests =
hwFocusRequest.lightweightRequests;
EventQueue.invokeLater(new Runnable() {
public void run() {
processCurrentLightweightRequests();
}
});
}
// 'opposite' will be fixed by
// DefaultKeyboardFocusManager.realOppositeComponent
return new FocusEvent(newSource,
FocusEvent.FOCUS_GAINED, temporary,
opposite);
}
if (currentFocusOwner != null
&& currentFocusOwner.getContainingWindow() == source
&& (hwFocusRequest == null || source != hwFocusRequest.heavyweight))
{
// Special case for FOCUS_GAINED in top-levels
// If it arrives as the result of activation we should skip it
// This event will not have appropriate request record and
// on arrival there will be already some focus owner set.
return new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_GAINED, false, null);
}
return retargetUnexpectedFocusEvent(fe);
} // end synchronized(heavyweightRequests)
|
static java.awt.event.FocusEvent | retargetFocusLost(java.awt.event.FocusEvent fe)
assert (fe.getID() == FocusEvent.FOCUS_LOST);
Component currentFocusOwner = getCurrentKeyboardFocusManager().
getGlobalFocusOwner();
Component opposite = fe.getOppositeComponent();
Component nativeOpposite = getHeavyweight(opposite);
synchronized (heavyweightRequests) {
HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
((heavyweightRequests.size() > 0)
? heavyweightRequests.getFirst() : null);
if (hwFocusRequest == HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
{
if (currentFocusOwner != null) {
// Call to KeyboardFocusManager.clearGlobalFocusOwner()
heavyweightRequests.removeFirst();
return new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST, false, null);
}
// Otherwise, fall through to failure case below
} else if (opposite == null)
{
// Focus leaving application
if (currentFocusOwner != null) {
return new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
true, null);
} else {
return fe;
}
} else if (hwFocusRequest != null &&
(nativeOpposite == hwFocusRequest.heavyweight ||
nativeOpposite == null &&
opposite == hwFocusRequest.getFirstLightweightRequest().component))
{
if (currentFocusOwner == null) {
return fe;
}
// Focus change as a result of a known call to requestFocus(),
// or click on a peer focusable heavyweight Component.
// If a focus transfer is made across top-levels, then the
// FOCUS_LOST event is always temporary, and the FOCUS_GAINED
// event is always permanent. Otherwise, the stored temporary
// value is honored.
LightweightFocusRequest lwFocusRequest =
(LightweightFocusRequest)hwFocusRequest.
lightweightRequests.getFirst();
boolean temporary = isTemporary(opposite,
currentFocusOwner)
? true
: lwFocusRequest.temporary;
return new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
temporary, lwFocusRequest.component);
} else if (focusedWindowChanged(opposite, currentFocusOwner)) {
// If top-level changed there might be no focus request in a list
// But we know the opposite, we now it is temporary - dispatch the event.
if (!fe.isTemporary() && currentFocusOwner != null) {
// Create copy of the event with only difference in temporary parameter.
fe = new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,
true, opposite);
}
return fe;
}
return retargetUnexpectedFocusEvent(fe);
} // end synchronized(heavyweightRequests)
|
static java.awt.event.FocusEvent | retargetUnexpectedFocusEvent(java.awt.event.FocusEvent fe)
synchronized (heavyweightRequests) {
// Any other case represents a failure condition which we did
// not expect. We need to clearFocusRequestList() and patch up
// the event as best as possible.
if (removeFirstRequest()) {
return (FocusEvent)retargetFocusEvent(fe);
}
Component source = fe.getComponent();
Component opposite = fe.getOppositeComponent();
boolean temporary = false;
if (fe.getID() == FocusEvent.FOCUS_LOST &&
(opposite == null || isTemporary(opposite, source)))
{
temporary = true;
}
return new FocusEvent(source, fe.getID(), temporary, opposite);
}
|
public static void | setCurrentKeyboardFocusManager(java.awt.KeyboardFocusManager newManager)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.
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.
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (replaceKeyboardFocusManagerPermission == null) {
replaceKeyboardFocusManagerPermission =
new AWTPermission("replaceKeyboardFocusManager");
}
security.
checkPermission(replaceKeyboardFocusManagerPermission);
}
KeyboardFocusManager oldManager = null;
synchronized (KeyboardFocusManager.class) {
AppContext appcontext = AppContext.getAppContext();
if (newManager != null) {
oldManager = getCurrentKeyboardFocusManager(appcontext);
appcontext.put(KeyboardFocusManager.class, newManager);
} else {
oldManager = getCurrentKeyboardFocusManager(appcontext);
appcontext.remove(KeyboardFocusManager.class);
}
}
if (oldManager != null) {
oldManager.firePropertyChange("managingFocus",
Boolean.TRUE,
Boolean.FALSE);
}
if (newManager != null) {
newManager.firePropertyChange("managingFocus",
Boolean.FALSE,
Boolean.TRUE);
}
|
final void | setCurrentSequencedEvent(java.awt.SequencedEvent current)
synchronized (SequencedEvent.class) {
assert(current == null || currentSequencedEvent == null);
currentSequencedEvent = current;
}
|
public void | setDefaultFocusTraversalKeys(int id, java.util.Set keystrokes)Sets the default focus traversal keys for a given traversal operation.
This traversal key Set will be in effect on all
Window s 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.
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.
Identifier |
Meaning |
Default |
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS |
Normal forward keyboard traversal |
TAB on KEY_PRESSED ,
CTRL-TAB on KEY_PRESSED |
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS |
Normal reverse keyboard traversal |
SHIFT-TAB on KEY_PRESSED ,
CTRL-SHIFT-TAB on KEY_PRESSED |
KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS |
Go up one focus traversal cycle |
none |
KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS |
Go down one focus traversal cycle |
none |
To disable a traversal key, use an empty Set ;
Collections.EMPTY_SET is recommended.
Using the AWTKeyStroke API, client code can
specify on which of two
specific KeyEvent s, KEY_PRESSED or
KEY_RELEASED , the focus traversal operation will
occur. Regardless of which KeyEvent is specified,
however, all KeyEvent s related to the focus
traversal key, including the associated KEY_TYPED
event, will be consumed, and will not be dispatched
to any Component . It is a runtime error to
specify a KEY_TYPED event as
mapping to a focus traversal operation, or to map the same event to
multiple default focus traversal operations.
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);
|
public void | setDefaultFocusTraversalPolicy(java.awt.FocusTraversalPolicy 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.
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);
|
protected void | setGlobalActiveWindow(java.awt.Window activeWindow)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.
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 getActiveWindow() . Use
Component.requestFocus() or
Component.requestFocusInWindow() to change the active
Window, subject to platform limitations.
Window oldActiveWindow;
synchronized (KeyboardFocusManager.class) {
oldActiveWindow = getActiveWindow();
if (focusLog.isLoggable(Level.FINER)) {
focusLog.finer("Setting global active window to " + activeWindow + ", old active " + oldActiveWindow);
}
try {
fireVetoableChange("activeWindow", oldActiveWindow,
activeWindow);
} catch (PropertyVetoException e) {
// rejected
return;
}
KeyboardFocusManager.activeWindow = activeWindow;
}
firePropertyChange("activeWindow", oldActiveWindow, activeWindow);
|
public void | setGlobalCurrentFocusCycleRoot(java.awt.Container newFocusCycleRoot)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.
This method is intended to be used only by KeyboardFocusManagers and
focus implementations. It is not for general client use.
Container oldFocusCycleRoot;
synchronized (KeyboardFocusManager.class) {
oldFocusCycleRoot = getCurrentFocusCycleRoot();
currentFocusCycleRoot = newFocusCycleRoot;
}
firePropertyChange("currentFocusCycleRoot", oldFocusCycleRoot,
newFocusCycleRoot);
|
protected void | setGlobalFocusOwner(java.awt.Component focusOwner)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.
This method does not actually set the focus to the specified Component.
It merely stores the value to be subsequently returned by
getFocusOwner() . Use Component.requestFocus()
or Component.requestFocusInWindow() to change the focus
owner, subject to platform limitations.
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);
}
|
protected void | setGlobalFocusedWindow(java.awt.Window focusedWindow)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.
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 getFocusedWindow() . Use
Component.requestFocus() or
Component.requestFocusInWindow() to change the focused
Window, subject to platform limitations.
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);
}
|
protected void | setGlobalPermanentFocusOwner(java.awt.Component permanentFocusOwner)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.
This method does not actually set the focus to the specified Component.
It merely stores the value to be subsequently returned by
getPermanentFocusOwner() . Use
Component.requestFocus() or
Component.requestFocusInWindow() to change the focus owner,
subject to platform limitations.
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);
}
|
static void | setMostRecentFocusOwner(java.awt.Component component)
Component window = component;
while (window != null && !(window instanceof Window)) {
window = window.parent;
}
if (window != null) {
setMostRecentFocusOwner((Window)window, component);
}
|
static synchronized void | setMostRecentFocusOwner(java.awt.Window window, java.awt.Component component)
// ATTN: component has a strong reference to window via chain
// of Component.parent fields. Since WeakHasMap refers to its
// values strongly, we need to break the strong link from the
// value (component) back to its key (window).
WeakReference weakValue = null;
if (component != null) {
weakValue = new WeakReference(component);
}
mostRecentFocusOwners.put(window, weakValue);
|
void | setNativeFocusOwner(java.awt.Component comp)
peer.setCurrentFocusOwner(comp);
|
void | setNativeFocusedWindow(java.awt.Window win)
peer.setCurrentFocusedWindow(win);
|
static int | shouldNativelyFocusHeavyweight(java.awt.Component heavyweight, java.awt.Component descendant, boolean temporary, boolean focusedWindowChangeAllowed, long time)Indicates whether the native implementation should proceed with a
pending, native focus request. Before changing the focus at the native
level, the AWT implementation should always call this function for
permission. This function will reject the request if a duplicate request
preceded it, or if the specified heavyweight Component already owns the
focus and no native focus changes are pending. Otherwise, the request
will be approved and the focus request list will be updated so that,
if necessary, the proper descendant will be focused when the
corresponding FOCUS_GAINED event on the heavyweight is received.
An implementation must ensure that calls to this method and native
focus changes are atomic. If this is not guaranteed, then the ordering
of the focus request list may be incorrect, leading to errors in the
type-ahead mechanism. Typically this is accomplished by only calling
this function from the native event pumping thread, or by holding a
global, native lock during invocation.
if (dbg.on) {
dbg.assertion(heavyweight != null);
dbg.assertion(time != 0);
}
if (descendant == null) {
// Focus transfers from a lightweight child back to the
// heavyweight Container should be treated like lightweight
// focus transfers.
descendant = heavyweight;
}
KeyboardFocusManager manager = getCurrentKeyboardFocusManager(SunToolkit.targetToAppContext(descendant));
KeyboardFocusManager thisManager = getCurrentKeyboardFocusManager();
Component currentFocusOwner = thisManager.getGlobalFocusOwner();
if (focusLog.isLoggable(Level.FINER)) {
focusLog.finer("SNFH for " + descendant + " in " + heavyweight);
}
if (focusLog.isLoggable(Level.FINEST)) {
focusLog.finest("0. Current focus owner " + currentFocusOwner);
focusLog.finest("0. Native focus owner " + thisManager.getNativeFocusOwner());
}
synchronized (heavyweightRequests) {
HeavyweightFocusRequest hwFocusRequest = (HeavyweightFocusRequest)
((heavyweightRequests.size() > 0)
? heavyweightRequests.getLast() : null);
if (focusLog.isLoggable(Level.FINEST)) {
focusLog.finest("Request " + hwFocusRequest);
}
if (hwFocusRequest == null &&
heavyweight == thisManager.getNativeFocusOwner())
{
if (descendant == currentFocusOwner) {
// Redundant request.
if (focusLog.isLoggable(Level.FINEST)) focusLog.finest("1. SNFH_FAILURE for " + descendant);
return SNFH_FAILURE;
}
// 'heavyweight' owns the native focus and there are no pending
// requests. 'heavyweight' must be a Container and
// 'descendant' must not be the focus owner. Otherwise,
// we would never have gotten this far.
manager.enqueueKeyEvents(time, descendant);
hwFocusRequest =
new HeavyweightFocusRequest(heavyweight, descendant,
temporary);
heavyweightRequests.add(hwFocusRequest);
if (currentFocusOwner != null) {
FocusEvent currentFocusOwnerEvent =
new FocusEvent(currentFocusOwner,
FocusEvent.FOCUS_LOST,
temporary, descendant);
SunToolkit.postEvent(currentFocusOwner.appContext,
currentFocusOwnerEvent);
}
FocusEvent newFocusOwnerEvent =
new FocusEvent(descendant, FocusEvent.FOCUS_GAINED,
temporary, currentFocusOwner);
SunToolkit.postEvent(descendant.appContext,
newFocusOwnerEvent);
if (focusLog.isLoggable(Level.FINEST)) focusLog.finest("2. SNFH_HANDLED for " + descendant);
return SNFH_SUCCESS_HANDLED;
} else if (hwFocusRequest != null &&
hwFocusRequest.heavyweight == heavyweight) {
// 'heavyweight' doesn't have the native focus right now, but
// if all pending requests were completed, it would. Add
// descendant to the heavyweight's list of pending
// lightweight focus transfers.
if (hwFocusRequest.addLightweightRequest(descendant,
temporary)) {
manager.enqueueKeyEvents(time, descendant);
}
if (focusLog.isLoggable(Level.FINEST)) focusLog.finest("3. SNFH_HANDLED for lightweight " + descendant + " in " + heavyweight);
return SNFH_SUCCESS_HANDLED;
} else {
if (!focusedWindowChangeAllowed) {
// For purposes of computing oldFocusedWindow, we should
// look at the second to last HeavyweightFocusRequest on
// the queue iff the last HeavyweightFocusRequest is
// CLEAR_GLOBAL_FOCUS_OWNER. If there is no second to last
// HeavyweightFocusRequest, null is an acceptable value.
if (hwFocusRequest ==
HeavyweightFocusRequest.CLEAR_GLOBAL_FOCUS_OWNER)
{
int size = heavyweightRequests.size();
hwFocusRequest = (HeavyweightFocusRequest)((size >= 2)
? heavyweightRequests.get(size - 2)
: null);
}
if (focusedWindowChanged(heavyweight,
(hwFocusRequest != null)
? hwFocusRequest.heavyweight
: thisManager.getNativeFocusedWindow())) {
if (focusLog.isLoggable(Level.FINEST)) focusLog.finest("4. SNFH_FAILURE for " + descendant);
return SNFH_FAILURE;
}
}
manager.enqueueKeyEvents(time, descendant);
heavyweightRequests.add
(new HeavyweightFocusRequest(heavyweight, descendant,
temporary));
if (focusLog.isLoggable(Level.FINEST)) focusLog.finest("5. SNFH_PROCEED for " + descendant);
return SNFH_SUCCESS_PROCEED;
}
}
|
public abstract void | upFocusCycle(java.awt.Component aComponent)Moves the focus up one focus traversal cycle. Typically, the focus owner
is set to aComponent's focus cycle root, and the current focus cycle
root is set to the new focus owner's focus cycle root. If, however,
aComponent's focus cycle root is a Window, then typically the focus
owner is set to the Window's default Component to focus, and the current
focus cycle root is unchanged.
|
public final void | upFocusCycle()Moves the focus up one focus traversal cycle from the current focus
owner. Typically, the new focus owner is set to the current focus
owner's focus cycle root, and the current focus cycle root is set to the
new focus owner's focus cycle root. If, however, the current focus
owner's focus cycle root is a Window, then typically the focus owner is
set to the focus cycle root's default Component to focus, and the
current focus cycle root is unchanged.
Component focusOwner = getFocusOwner();
if (focusOwner != null) {
upFocusCycle(focusOwner);
}
|