APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

pack-priv Class KeyboardManager

extends Object
Class Inheritance
Imports
java.util.*, java.awt.*, java.awt.event.*, sun.awt.EmbeddedFrame

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 semantics of how keyboard dispatching should work at least 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, KeyStrokes 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 and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static 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

Modifier and TypeField and Description
pack-priv Hashtable<KeyboardManager.ComponentKeyStrokePair, Container>
componentKeyStrokeMap

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

pack-priv Hashtable<Container, Hashtable<Object, Object>>
containerMap

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

pack-priv static KeyboardManager

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
fireBinding(JComponent c, KeyStroke ks, KeyEvent e, boolean pressed)

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.

public static KeyboardManager
private static Container
getTopAncestor(JComponent c)

Find the top focusable Window, or InternalFrame

public void
registerKeyStroke(KeyStroke k, JComponent c)

register keystrokes here which are for the WHEN_IN_FOCUSED_WINDOW case.

public void
protected Hashtable<Object, Object>
public static void
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

componentKeyStrokeMapback to summary
pack-priv Hashtable<KeyboardManager.ComponentKeyStrokePair, Container> componentKeyStrokeMap

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

containerMapback to summary
pack-priv Hashtable<Container, Hashtable<Object, Object>> containerMap

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

currentManagerback to summary
pack-priv static KeyboardManager currentManager

Constructor Detail

KeyboardManagerback to summary
pack-priv KeyboardManager()

Method Detail

fireBindingback to summary
pack-priv void fireBinding(JComponent c, KeyStroke ks, KeyEvent e, boolean pressed)
fireKeyboardActionback to summary
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 children (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"

Annotations
@SuppressWarnings:deprecation
getCurrentManagerback to summary
public static KeyboardManager getCurrentManager()
getTopAncestorback to summary
private static Container getTopAncestor(JComponent c)

Find the top focusable Window, or InternalFrame

registerKeyStrokeback to summary
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.

registerMenuBarback to summary
public void registerMenuBar(JMenuBar mb)
registerNewTopContainerback to summary
protected Hashtable<Object, Object> registerNewTopContainer(Container topContainer)
setCurrentManagerback to summary
public static void setCurrentManager(KeyboardManager km)
unregisterKeyStrokeback to summary
public void unregisterKeyStroke(KeyStroke ks, JComponent c)
unregisterMenuBarback to summary
public void unregisterMenuBar(JMenuBar mb)
javax.swing back to summary

pack-priv Class KeyboardManager.ComponentKeyStrokePair

extends Object
Class Inheritance

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

Modifier and TypeField and Description
pack-priv Object
pack-priv Object

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

componentback to summary
pack-priv Object component
keyStrokeback to summary
pack-priv Object keyStroke

Constructor Detail

ComponentKeyStrokePairback to summary
public ComponentKeyStrokePair(Object comp, Object key)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.