java.awt

Class DefaultKeyboardFocusManager

Implemented Interfaces:
KeyEventDispatcher, KeyEventPostProcessor
Known Direct Subclasses:
FocusManager

public class DefaultKeyboardFocusManager
extends KeyboardFocusManager

Field Summary

Fields inherited from class java.awt.KeyboardFocusManager

BACKWARD_TRAVERSAL_KEYS, DOWN_CYCLE_TRAVERSAL_KEYS, FORWARD_TRAVERSAL_KEYS, UP_CYCLE_TRAVERSAL_KEYS

Constructor Summary

DefaultKeyboardFocusManager()
Construct a KeyboardFocusManager.

Method Summary

protected void
dequeueKeyEvents(long after, Component untilFocused)
Removes the key event block specified by the supplied timestamp and component.
protected void
discardKeyEvents(Component comp)
Discards all key event blocks relating to focus requirements for the supplied component, regardless of timestamp.
boolean
dispatchEvent(AWTEvent e)
The AWT event dispatcher uses this method to request that the manager handle a particular event.
boolean
dispatchKeyEvent(KeyEvent e)
Attempts to dispatch key events for which no key event dispatcher has so far succeeded.
void
downFocusCycle(Container cont)
Moves the current focus downwards by one focus cycle.
protected void
enqueueKeyEvents(long after, Component untilFocused)
Delays all key events following the specified timestamp until the supplied component has focus.
void
focusNextComponent(Component comp)
Moves the current focus to the next component following comp, based on the current focus traversal policy.
void
focusPreviousComponent(Component comp)
Moves the current focus to the previous component, prior to comp, based on the current focus traversal policy.
boolean
postProcessKeyEvent(KeyEvent e)
Handles the post processing of key events.
void
processKeyEvent(Component comp, KeyEvent e)
Handles focus traversal operations for key events which represent focus traversal keys in relation to the supplied component.
void
upFocusCycle(Component comp)
Moves the current focus upwards by one focus cycle.

Methods inherited from class java.awt.KeyboardFocusManager

addKeyEventDispatcher, addKeyEventPostProcessor, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, clearGlobalFocusOwner, dequeueKeyEvents, discardKeyEvents, dispatchEvent, dispatchKeyEvent, downFocusCycle, downFocusCycle, enqueueKeyEvents, firePropertyChange, fireVetoableChange, focusNextComponent, focusNextComponent, focusPreviousComponent, focusPreviousComponent, getActiveWindow, getCurrentFocusCycleRoot, getCurrentKeyboardFocusManager, getDefaultFocusTraversalKeys, getDefaultFocusTraversalPolicy, getFocusOwner, getFocusedWindow, getGlobalActiveWindow, getGlobalCurrentFocusCycleRoot, getGlobalFocusOwner, getGlobalFocusedWindow, getGlobalPermanentFocusOwner, getKeyEventDispatchers, getKeyEventPostProcessors, getPermanentFocusOwner, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, postProcessKeyEvent, processKeyEvent, redispatchEvent, removeKeyEventDispatcher, removeKeyEventPostProcessor, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener, setCurrentKeyboardFocusManager, setDefaultFocusTraversalKeys, setDefaultFocusTraversalPolicy, setGlobalActiveWindow, setGlobalCurrentFocusCycleRoot, setGlobalFocusOwner, setGlobalFocusedWindow, setGlobalPermanentFocusOwner, upFocusCycle, upFocusCycle

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

DefaultKeyboardFocusManager

public DefaultKeyboardFocusManager()
Construct a KeyboardFocusManager.

Method Details

dequeueKeyEvents

protected 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.
Overrides:
dequeueKeyEvents in interface KeyboardFocusManager
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 void discardKeyEvents(Component comp)
Discards all key event blocks relating to focus requirements for the supplied component, regardless of timestamp.
Overrides:
discardKeyEvents in interface KeyboardFocusManager
Parameters:
comp - the component of the key event block(s) to be removed.

dispatchEvent

public 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 FocusEvents and KeyEvents, and WindowEvents 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.
Overrides:
dispatchEvent in interface KeyboardFocusManager
Parameters:
e - the event to dispatch.
Returns:
true if the event was dispatched.

dispatchKeyEvent

public 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
Overrides:
dispatchKeyEvent in interface KeyboardFocusManager
Parameters:
e - the key event to dispatch.
Returns:
true if the event was dispatched successfully.

downFocusCycle

public 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.
Overrides:
downFocusCycle in interface KeyboardFocusManager
Parameters:
cont - the container used as part of the focus traversal.

enqueueKeyEvents

protected 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.
Overrides:
enqueueKeyEvents in interface KeyboardFocusManager
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.

focusNextComponent

public 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. Canvases, Panels, Labels, ScrollPanes, Scrollbars, Windows and lightweight components are judged to be unacceptable by default. See the DefaultFocusTraversalPolicy for more details.
Overrides:
focusNextComponent in interface KeyboardFocusManager
Parameters:
comp - the component prior to the one which will become the focus, following execution of this method.

focusPreviousComponent

public 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. Canvases, Panels, Labels, ScrollPanes, Scrollbars, Windows and lightweight components are judged to be unacceptable by default. See the DefaultFocusTraversalPolicy for more details.
Overrides:
focusPreviousComponent in interface KeyboardFocusManager
Parameters:
comp - the component following the one which will become the focus, following execution of this method.

postProcessKeyEvent

public boolean postProcessKeyEvent(KeyEvent e)
Handles the post processing of key events. By default, this method will map unhandled key events to appropriate MenuShortcuts. 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
Overrides:
postProcessKeyEvent in interface KeyboardFocusManager
Parameters:
e - the key event to post process.
Returns:
true by default, as the event was handled.

processKeyEvent

public void processKeyEvent(Component comp,
                            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.
Overrides:
processKeyEvent in interface KeyboardFocusManager
Parameters:
e - the possible focus traversal key event.

upFocusCycle

public 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.
Overrides:
upFocusCycle in interface KeyboardFocusManager
Parameters:
comp - the component used as part of the focus traversal.

DefaultKeyboardFocusManager.java -- Copyright (C) 2002, 2004 Free Software Foundation, Inc. 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.