javax.swing
Class KeyboardManager

java.lang.Object
  extended byjavax.swing.KeyboardManager

class KeyboardManager
extends Object

The KeyboardManager class is used to help dispatch keyboard actions for the WHEN_IN_FOCUSED_WINDOW style actions. Actions with other conditions are handled directly in JComponent. Here's a description of the symantics of how keyboard dispatching should work atleast as I understand it. KeyEvents are dispatched to the focused component. The focus manager gets first crack at processing this event. If the focus manager doesn't want it, then the JComponent calls super.processKeyEvent() this allows listeners a chance to process the event. If none of the listeners "consumes" the event then the keybindings get a shot. This is where things start to get interesting. First, KeyStokes defined with the WHEN_FOCUSED condition get a chance. If none of these want the event, then the component walks though it's parents looked for actions of type WHEN_ANCESTOR_OF_FOCUSED_COMPONENT. If no one has taken it yet, then it winds up here. We then look for components registered for WHEN_IN_FOCUSED_WINDOW events and fire to them. Note that if none of those are found then we pass the event to the menubars and let them have a crack at it. They're handled differently. Lastly, we check if we're looking at an internal frame. If we are and no one wanted the event then we move up to the InternalFrame's creator and see if anyone wants the event (and so on and so on).

See Also:
InputMap

Nested Class Summary
(package private)  class KeyboardManager.ComponentKeyStrokePair
          This class is used to create keys for a hashtable which looks up topContainers based on component, keystroke pairs This is used to make unregistering KeyStrokes fast
 
Field Summary
(package private)  Hashtable componentKeyStrokeMap
          Maps component/keystroke pairs to a topLevel container This is mainly used for fast unregister operations
(package private)  Hashtable containerMap
          maps top-level containers to a sub-hashtable full of keystrokes
(package private) static KeyboardManager currentManager
           
 
Constructor Summary
(package private) KeyboardManager()
           
 
Method Summary
(package private)  void fireBinding(JComponent c, KeyStroke ks, KeyEvent e, boolean pressed)
           
 boolean fireKeyboardAction(KeyEvent e, boolean pressed, Container topAncestor)
          This method is called when the focused component (and none of its ancestors) want the key event.
static KeyboardManager getCurrentManager()
           
private static Container getTopAncestor(JComponent c)
          find the top Window or Applet
 void registerKeyStroke(KeyStroke k, JComponent c)
          register keystrokes here which are for the WHEN_IN_FOCUSED_WINDOW case.
 void registerMenuBar(JMenuBar mb)
           
protected  Hashtable registerNewTopContainer(Container topContainer)
           
static void setCurrentManager(KeyboardManager km)
           
 void unregisterKeyStroke(KeyStroke ks, JComponent c)
           
 void unregisterMenuBar(JMenuBar mb)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentManager

static KeyboardManager currentManager

containerMap

Hashtable containerMap
maps top-level containers to a sub-hashtable full of keystrokes


componentKeyStrokeMap

Hashtable componentKeyStrokeMap
Maps component/keystroke pairs to a topLevel container This is mainly used for fast unregister operations

Constructor Detail

KeyboardManager

KeyboardManager()
Method Detail

getCurrentManager

public static KeyboardManager getCurrentManager()

setCurrentManager

public static void setCurrentManager(KeyboardManager km)

registerKeyStroke

public void registerKeyStroke(KeyStroke k,
                              JComponent c)
register keystrokes here which are for the WHEN_IN_FOCUSED_WINDOW case. Other types of keystrokes will be handled by walking the hierarchy That simplifies some potentially hairy stuff.


getTopAncestor

private static Container getTopAncestor(JComponent c)
find the top Window or Applet


unregisterKeyStroke

public void unregisterKeyStroke(KeyStroke ks,
                                JComponent c)

fireKeyboardAction

public boolean fireKeyboardAction(KeyEvent e,
                                  boolean pressed,
                                  Container topAncestor)
This method is called when the focused component (and none of its ancestors) want the key event. This will look up the keystroke to see if any chidren (or subchildren) of the specified container want a crack at the event. If one of them wants it, then it will "DO-THE-RIGHT-THING"


fireBinding

void fireBinding(JComponent c,
                 KeyStroke ks,
                 KeyEvent e,
                 boolean pressed)

registerMenuBar

public void registerMenuBar(JMenuBar mb)

unregisterMenuBar

public void unregisterMenuBar(JMenuBar mb)

registerNewTopContainer

protected Hashtable registerNewTopContainer(Container topContainer)