addKeyEventDispatcher
public void addKeyEventDispatcher(KeyEventDispatcher dispatcher)
Adds a key event dispatcher to the list of registered dispatchers.
When a key event is fired, each dispatcher's dispatchKeyEvent
method is called in the order that they were added, prior to the manager
dispatching the event itself. Notifications halt when one of the
dispatchers returns true.
The same dispatcher can exist multiple times within the list
of registered dispatchers, and there is no limit on the length
of this list. A null dispatcher is simply ignored.
- Parameters:
dispatcher
- The dispatcher to register.
addKeyEventPostProcessor
public void addKeyEventPostProcessor(KeyEventPostProcessor postProcessor)
Adds a key event post processor to the list of registered post processors.
Post processors work in the same way as key event dispatchers, except
that they are invoked after the manager has dispatched the key event,
and not prior to this. Each post processor's postProcessKeyEvent
method is called to see if any post processing needs to be performed. THe
processors are called in the order in which they were added to the list,
and notifications continue until one returns true. As with key event
dispatchers, the manager is implicitly called following this process,
regardless of whether or not it is present within the list.
The same post processor can exist multiple times within the list
of registered post processors, and there is no limit on the length
of this list. A null post processor is simply ignored.
- Parameters:
postProcessor
- the post processor to register.
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener l)
Registers the supplied property change listener for receiving
events caused by the following property changes:
- the current focus owner ("focusOwner")
- the permanent focus owner ("permanentFocusOwner")
- the focused window ("focusedWindow")
- the active window ("activeWindow")
- the default focus traversal policy ("defaultFocusTraversalPolicy")
- the default set of forward traversal keys ("forwardDefaultFocusTraversalKeys")
- the default set of backward traversal keys ("backwardDefaultFocusTraversalKeys")
- the default set of up cycle traversal keys ("upCycleDefaultFocusTraversalKeys")
- the default set of down cycle traversal keys ("downCycleDefaultFocusTraversalKeys")
- the current focus cycle root ("currentFocusCycleRoot")
If the supplied listener is null, nothing occurs.
- Parameters:
l
- the new listener to register.
addPropertyChangeListener
public void addPropertyChangeListener(String name,
PropertyChangeListener l)
Registers a property change listener for receiving events relating
to a change to a specified property. The supplied property name can be
either user-defined or one from the following list of properties
relevant to this class:
- the current focus owner ("focusOwner")
- the permanent focus owner ("permanentFocusOwner")
- the focused window ("focusedWindow")
- the active window ("activeWindow")
- the default focus traversal policy ("defaultFocusTraversalPolicy")
- the default set of forward traversal keys ("forwardDefaultFocusTraversalKeys")
- the default set of backward traversal keys ("backwardDefaultFocusTraversalKeys")
- the default set of up cycle traversal keys ("upCycleDefaultFocusTraversalKeys")
- the default set of down cycle traversal keys ("downCycleDefaultFocusTraversalKeys")
- the current focus cycle root ("currentFocusCycleRoot")
Nothing occurs if a null listener is supplied. null is regarded as a valid property name.
- Parameters:
name
- the name of the property to handle change events for.l
- the listener to register for changes to the specified property.
addVetoableChangeListener
public void addVetoableChangeListener(VetoableChangeListener l)
Registers a vetoable property change listener for receiving events
relating to the following properties:
- the current focus owner ("focusOwner")
- the permanent focus owner ("permanentFocusOwner")
- the focused window ("focusedWindow")
- the active window ("activeWindow")
Nothing occurs if a null listener is supplied.
- Parameters:
l
- the listener to register.
addVetoableChangeListener
public void addVetoableChangeListener(String name,
VetoableChangeListener l)
Registers a vetoable property change listener for receiving events relating
to a vetoable change to a specified property. The supplied property name can be
either user-defined or one from the following list of properties
relevant to this class:
- the current focus owner ("focusOwner")
- the permanent focus owner ("permanentFocusOwner")
- the focused window ("focusedWindow")
- the active window ("activeWindow")
Nothing occurs if a null listener is supplied. null is regarded as a valid property name.
- Parameters:
name
- the name of the property to handle change events for.l
- the listener to register for changes to the specified property.
clearGlobalFocusOwner
public void clearGlobalFocusOwner()
Clear the global focus owner and deliver a FOCUS_LOST event to
the previously-focused
Component
. Until another
Component
becomes the keyboard focus owner, key events will be
discarded by top-level windows.
dequeueKeyEvents
protected abstract void dequeueKeyEvents(long after,
Component untilFocused)
Removes the key event block specified by the supplied timestamp and component.
All delayed key events are released for normal dispatching following its
removal and subsequent key events that would have been blocked are now
immediately dispatched. If the specified timestamp is below 0, then
the request with the oldest timestamp is removed.
- Parameters:
after
- the timestamp of the key event block to be removed, or a
value smaller than 0 if the oldest is to be removed.untilFocused
- the component of the key event block to be removed.
discardKeyEvents
protected abstract void discardKeyEvents(Component comp)
Discards all key event blocks relating to focus requirements for
the supplied component, regardless of timestamp.
- Parameters:
comp
- the component of the key event block(s) to be removed.
dispatchEvent
public abstract boolean dispatchEvent(AWTEvent e)
The AWT event dispatcher uses this method to request that the manager
handle a particular event. If the manager fails or refuses to
dispatch the supplied event (this method returns false), the
AWT event dispatcher will try to dispatch the event itself.
The manager is expected to handle all FocusEvent
s
and KeyEvent
s, and WindowEvent
s
relating to the focus. Dispatch is done with regard to the
the focus owner and the currently focused and active windows.
In handling the event, the source of the event may be overridden.
The actual dispatching is performed by calling
redispatchEvent()
. This avoids the infinite recursion
of dispatch requests which may occur if this method is called on
the target component.
- Parameters:
e
- the event to dispatch.
- Returns:
- true if the event was dispatched.
dispatchKeyEvent
public abstract boolean dispatchKeyEvent(KeyEvent e)
Attempts to dispatch key events for which no key event dispatcher
has so far succeeded. This method is usually called by
dispatchEvent()
following the sending of the key
event to any registered key event dispatchers. If the key
event reaches this stage, none of the dispatchers returned
true. This is, of course, always the case if there are no
registered dispatchers.
If this method also fails to handle the key event, then
false is returned to the caller. In the case of
dispatchEvent()
, the calling method may try
to handle the event itself or simply forward on the
false result to its caller. When the event is dispatched
by this method, a true result is propogated through the
calling methods.
- Specified by:
- dispatchKeyEvent in interface KeyEventDispatcher
- Parameters:
e
- the key event to dispatch.
- Returns:
- true if the event was dispatched successfully.
downFocusCycle
public final void downFocusCycle()
Moves the current focus downwards by one focus cycle,
iff the current focus cycle root is a Container
.
Usually, the new focus owner is set to the default component
of the container and the current focus cycle root is set
to the current focus owner. Nothing occurs if the current
focus cycle root is not a container.
downFocusCycle
public abstract void downFocusCycle(Container cont)
Moves the current focus downwards by one focus cycle.
If the supplied container is a focus cycle root, then this
becomes the current focus cycle root and the focus goes
to the default component of the specified container.
Nothing happens for non-focus cycle root containers.
- Parameters:
cont
- the container used as part of the focus traversal.
enqueueKeyEvents
protected abstract void enqueueKeyEvents(long after,
Component untilFocused)
Delays all key events following the specified timestamp until the
supplied component has focus. The AWT calls this method when it is
determined that a focus change may occur within the native windowing
system. Any key events which occur following the time specified by
after are delayed until a FOCUS_GAINED
event is received
for the untilFocused component. The manager is responsible for ensuring
this takes place.
- Parameters:
after
- the timestamp beyond which all key events are delayed until
the supplied component gains focus.untilFocused
- the component to wait on gaining focus.
firePropertyChange
protected void firePropertyChange(String name,
Object o,
Object n)
Fires a property change event as a response to a change to
to the specified property. The event is only fired if a
change has actually occurred (i.e. o and n are different).
- Parameters:
name
- The name of the property to which a change occurred.o
- The old value of the property.n
- The new value of the property.
fireVetoableChange
protected void fireVetoableChange(String name,
Object o,
Object n)
throws PropertyVetoException
Fires a property change event as a response to a vetoable change to
to the specified property. The event is only fired if a
change has actually occurred (i.e. o and n are different).
In the event that the property change is vetoed, the following
occurs:
-
This method throws a
PropertyVetoException
to
the proposed change.
-
A new event is fired to reverse the previous change.
-
This method again throws a
PropertyVetoException
in response to the reversion.
- Parameters:
name
- The name of the property to which a change occurred.o
- The old value of the property.n
- The new value of the property.
focusNextComponent
public final void focusNextComponent()
Moves the current focus to the next component, based on the
current focus traversal policy. By default, only visible,
displayable, accepted component can receive focus.
Canvas
es, Panel
s,
Label
s, ScrollPane
s, Scrollbar
s,
Window
s and lightweight components are judged
to be unacceptable by default. See the
DefaultFocusTraversalPolicy
for more details.
focusNextComponent
public abstract void focusNextComponent(Component comp)
Moves the current focus to the next component following
comp, based on the current focus traversal policy. By
default, only visible, displayable, accepted components
can receive focus. Canvas
es, Panel
s,
Label
s, ScrollPane
s, Scrollbar
s,
Window
s and lightweight components are judged
to be unacceptable by default. See the
DefaultFocusTraversalPolicy
for more details.
- Parameters:
comp
- the component prior to the one which will
become the focus, following execution of this method.
focusPreviousComponent
public final void focusPreviousComponent()
Moves the current focus to the previous component, based on the
current focus traversal policy. By default, only visible,
displayable, accepted component can receive focus.
Canvas
es, Panel
s,
Label
s, ScrollPane
s, Scrollbar
s,
Window
s and lightweight components are judged
to be unacceptable by default. See the
DefaultFocusTraversalPolicy
for more details.
focusPreviousComponent
public abstract void focusPreviousComponent(Component comp)
Moves the current focus to the previous component, prior to
comp, based on the current focus traversal policy. By
default, only visible, displayable, accepted components
can receive focus. Canvas
es, Panel
s,
Label
s, ScrollPane
s, Scrollbar
s,
Window
s and lightweight components are judged
to be unacceptable by default. See the
DefaultFocusTraversalPolicy
for more details.
- Parameters:
comp
- the component following the one which will
become the focus, following execution of this method.
getCurrentFocusCycleRoot
public Container getCurrentFocusCycleRoot()
Retrieve the current focus cycle root, or null if the focus owner
was not set by a thread in the current
ThreadGroup
.
- Returns:
- the current focus cycle root or null
getDefaultFocusTraversalKeys
public Set getDefaultFocusTraversalKeys(int id)
Retrieve the default
Set
of focus traversal
keys for one of the focus traversal directions.
- Parameters:
id
- focus traversal direction identifier
- Returns:
- the default set of AWTKeyStrokes
getFocusOwner
public Component getFocusOwner()
Retrieve the
Component
that has the keyboard focus, or
null if the focus owner was not set by a thread in the current
ThreadGroup
.
- Returns:
- the keyboard focus owner or null
getFocusedWindow
public Window getFocusedWindow()
Retrieve the
Window
that is or contains the keyboard
focus owner, or null if the focused window was not set by a
thread in the current
ThreadGroup
.
- Returns:
- the focused window or null
getKeyEventDispatchers
protected List getKeyEventDispatchers()
Returns the currently registered key event dispatchers in List
form. At present, this only includes dispatchers explicitly registered
via the addKeyEventDispatcher()
method, but this behaviour
is subject to change and should not be depended on. The manager itself
may be a member of the list, but only if explicitly registered. If no
dispatchers have been registered, the list will be empty.
- Returns:
- A list of explicitly registered key event dispatchers.
getKeyEventPostProcessors
protected List getKeyEventPostProcessors()
Returns the currently registered key event post processors in List
form. At present, this only includes post processors explicitly registered
via the addKeyEventPostProcessor()
method, but this behaviour
is subject to change and should not be depended on. The manager itself
may be a member of the list, but only if explicitly registered. If no
post processors have been registered, the list will be empty.
- Returns:
- A list of explicitly registered key event post processors.
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners()
Returns the currently registered property change listeners
in array form. The returned array is empty if no listeners are
currently registered.
- Returns:
- an array of registered property change listeners.
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners(String name)
Returns the currently registered property change listeners
in array form, which listen for changes to the supplied property.
The returned array is empty, if no listeners are currently registered
for events pertaining to the supplied property.
- Parameters:
name
- The property the returned listeners monitor for changes.
- Returns:
- an array of registered property change listeners which
listen for changes to the supplied property.
getVetoableChangeListeners
public VetoableChangeListener[] getVetoableChangeListeners()
Returns the currently registered vetoable property change listeners
in array form. The returned array is empty if no listeners are
currently registered.
- Returns:
- an array of registered vetoable property change listeners.
getVetoableChangeListeners
public VetoableChangeListener[] getVetoableChangeListeners(String name)
Returns the currently registered vetoable property change listeners
in array form, which listen for changes to the supplied property.
The returned array is empty, if no listeners are currently registered
for events pertaining to the supplied property.
- Parameters:
name
- The property the returned listeners monitor for changes.
- Returns:
- an array of registered property change listeners which
listen for changes to the supplied property.
postProcessKeyEvent
public abstract boolean postProcessKeyEvent(KeyEvent e)
Handles the post processing of key events. By default,
this method will map unhandled key events to appropriate
MenuShortcut
s. The event is consumed
in the process and the shortcut is activated. This
method is usually called by dispatchKeyEvent
.
- Specified by:
- postProcessKeyEvent in interface KeyEventPostProcessor
- Parameters:
e
- the key event to post process.
- Returns:
- true by default, as the event was handled.
processKeyEvent
public abstract void processKeyEvent(Component focused,
KeyEvent e)
Handles focus traversal operations for key events which
represent focus traversal keys in relation to the supplied
component. The supplied component is assumed to have the
focus, whether it does so or not, and the operation is
carried out as appropriate, with this in mind.
- Parameters:
focused
- the component on which to perform focus traversal,
on the assumption that this component has the focus.e
- the possible focus traversal key event.
redispatchEvent
public final void redispatchEvent(Component target,
AWTEvent e)
Handles redispatching of an event so that recursion of
dispatch requests does not occur. Event dispatch methods
within this manager (dispatchEvent()
) and
the key event dispatchers should use this method to handle
dispatching rather than the dispatch method of the target
component.
This method is not intended for general consumption, and is
only for the use of the aforementioned classes.
- Parameters:
target
- the target component to which the event is
dispatched.e
- the event to dispatch.
removeKeyEventDispatcher
public void removeKeyEventDispatcher(KeyEventDispatcher dispatcher)
Removes the specified key event dispatcher from the list of
registered dispatchers. The manager always dispatches events,
regardless of its existence within the list. The manager
can be added and removed from the list, as with any other
dispatcher, but this does not affect its ability to dispatch
key events. Non-existent and null dispatchers are simply ignored
by this method.
- Parameters:
dispatcher
- The dispatcher to remove.
removeKeyEventPostProcessor
public void removeKeyEventPostProcessor(KeyEventPostProcessor postProcessor)
Removes the specified key event post processor from the list of
registered post processors. The manager always post processes events,
regardless of its existence within the list. The manager
can be added and removed from the list, as with any other
post processor, but this does not affect its ability to post process
key events. Non-existent and null post processors are simply ignored
by this method.
- Parameters:
postProcessor
- the post processor to remove.
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener l)
Removes the supplied property change listener from the list
of registered listeners. If the supplied listener is null,
nothing occurs.
- Parameters:
l
- the listener to remove.
removePropertyChangeListener
public void removePropertyChangeListener(String name,
PropertyChangeListener l)
Removes the supplied property change listener registered for the
specified property from the list of registered listeners. If the
supplied listener is null, nothing occurs.
- Parameters:
name
- the name of the property the listener is
monitoring changes to.l
- the listener to remove.
removeVetoableChangeListener
public void removeVetoableChangeListener(VetoableChangeListener l)
Removes the supplied vetoable property change listener from
the list of registered listeners. If the supplied listener
is null, nothing occurs.
- Parameters:
l
- the listener to remove.
removeVetoableChangeListener
public void removeVetoableChangeListener(String name,
VetoableChangeListener l)
Removes the supplied vetoable property change listener registered
for the specified property from the list of registered listeners.
If the supplied listener is null, nothing occurs.
- Parameters:
name
- the name of the vetoable property the listener is
monitoring changes to.l
- the listener to remove.
setDefaultFocusTraversalKeys
public void setDefaultFocusTraversalKeys(int id,
AWTKeyStroke> keystrokes)
Set the default
Set
of focus traversal keys for
one of the focus traversal directions.
- Parameters:
id
- focus traversal direction identifierkeystrokes
- set of AWTKeyStrokes
setGlobalActiveWindow
protected void setGlobalActiveWindow(Window window)
- Parameters:
window
- the Window to return from getActiveWindow and
getGlobalActiveWindow
setGlobalCurrentFocusCycleRoot
public void setGlobalCurrentFocusCycleRoot(Container cycleRoot)
- Parameters:
cycleRoot
- the focus cycle root to return from
getCurrentFocusCycleRoot and getGlobalCurrentFocusCycleRoot
setGlobalFocusOwner
protected void setGlobalFocusOwner(Component owner)
- Parameters:
owner
- the Component to return from getFocusOwner and
getGlobalFocusOwner
setGlobalFocusedWindow
protected void setGlobalFocusedWindow(Window window)
- Parameters:
window
- the Window to return from getFocusedWindow and
getGlobalFocusedWindow
setGlobalPermanentFocusOwner
protected void setGlobalPermanentFocusOwner(Component focusOwner)
- Parameters:
focusOwner
- the Component to return from
getPermanentFocusOwner and getGlobalPermanentFocusOwner
upFocusCycle
public final void upFocusCycle()
Moves the current focus upwards by one focus cycle,
so that the new focus owner is the focus cycle root
of the current owner. The current focus cycle root then
becomes the focus cycle root of the new focus owner.
However, in the case of the focus cycle root of the
current focus owner being a Window
, the default
component of this window becomes the focus owner and the
focus cycle root is not changed.
upFocusCycle
public abstract void upFocusCycle(Component comp)
Moves the current focus upwards by one focus cycle.
Both the current focus owner and current focus cycle root
become the focus cycle root of the supplied component.
However, in the case of a Window
, the default
focus component becomes the focus owner and the focus cycle
root is not changed.
- Parameters:
comp
- the component used as part of the focus traversal.
KeyboardFocusManager.java -- manage component focusing via the keyboard
Copyright (C) 2002, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.