Documentation of 'org.jdesktop.swingx.event.KeyBindingDispatcher' Java class
KeyBindingDispatcher
org.jdesktop.swingx.event

Class KeyBindingDispatcher

  • All Implemented Interfaces:
    java.awt.KeyEventDispatcher


    public class KeyBindingDispatcher
    extends java.lang.Object
    implements java.awt.KeyEventDispatcher
    KeyEventDispatcher for application-wide KeyBindings.

    The mechanism is the same as for component bindings, that is using a pair InputMap/ActionMap. The maps can be accessed directly to bind KeyStrokes and Actions individually. Additionally, the implementation provides convenience methods to bind pairs of KeyStroke/Action easily. Once the dispatcher is added to the KeyboardFocusManager, all KeyEvents will be served first to the bindings (modulo other dispatchers earlier in the chain), and consumed if an action is available, enabled and performed.

    Usage:

     
         KeyBindingDispatcher d = new KeyBindingDispatcher();
         d.bind(myKeyStroke, myAction);
         KeyboardFocusManager.getCurrentKeyboardFocusManager()
             .addKeyEventDispatcher(d);
     
     
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void bind(javax.swing.KeyStroke keyStroke, javax.swing.Action action)
      Binds the keyStroke and action, a key is auto-created.
      void bind(javax.swing.KeyStroke keyStroke, javax.swing.Action action, java.lang.Object key)
      Binds the keyStroke and action, using the given key which must not be null.
      boolean dispatchKeyEvent(java.awt.event.KeyEvent e)
      Implemented to process the key binding for the event.
      java.lang.Object get(javax.swing.KeyStroke keyStroke)
      Returns the actionMapKey registerd for the keyStroke.
      javax.swing.Action get(java.lang.Object key)
      Returns the Action registered for key or null if none.
      javax.swing.ActionMap getActionMap()
      Returns the ActionMap used for key bindings, lazily created if not yet done.
      javax.swing.InputMap getInputMap()
      Returns the InputMap used for key bindings, lazily created if not yet done.
      void put(javax.swing.KeyStroke keyStroke, java.lang.Object actionMapKey)
      Registers a binding for keyStroke to actionMapKey.
      void put(java.lang.Object key, javax.swing.Action action)
      Registers a binding for key to action.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • KeyBindingDispatcher

        public KeyBindingDispatcher()
    • Method Detail

      • dispatchKeyEvent

        public boolean dispatchKeyEvent(java.awt.event.KeyEvent e)
        Implemented to process the key binding for the event. If a binding is available, the bound action is performed and the event is consumed. Does nothing if the event already is consumed. The returned value is false always to allow other dispatchers to handle the event as well

        Subclasses may re-implement to return true and end the dispatch here.

        Specified by:
        dispatchKeyEvent in interface java.awt.KeyEventDispatcher
        Parameters:
        e - the keyEvent to dispatch
        Returns:
        unconditionally false
      • bind

        public void bind(javax.swing.KeyStroke keyStroke,
                         javax.swing.Action action,
                         java.lang.Object key)
        Binds the keyStroke and action, using the given key which must not be null.

        Parameters:
        keyStroke - the keyStroke to bind
        action - the action to bind.
        key - the key used for binding, must not be null.
      • getActionMap

        public javax.swing.ActionMap getActionMap()
        Returns the ActionMap used for key bindings, lazily created if not yet done.
        Returns:
        the ActionMap used for key bindings
      • getInputMap

        public javax.swing.InputMap getInputMap()
        Returns the InputMap used for key bindings, lazily created if not yet done.
        Returns:
        the InputMap used for key bindings.
      • bind

        public void bind(javax.swing.KeyStroke keyStroke,
                         javax.swing.Action action)
        Binds the keyStroke and action, a key is auto-created.
        Parameters:
        keyStroke - the keyStroke to bind
        action - the action to bind.
      • put

        public void put(javax.swing.KeyStroke keyStroke,
                        java.lang.Object actionMapKey)
        Registers a binding for keyStroke to actionMapKey. Semantics are the same as the corresponding method in InputMap.
        Parameters:
        keyStroke - the keyStroke to bind
        key - the key used for binding.
        See Also:
        InputMap.put(KeyStroke, Object)
      • get

        public java.lang.Object get(javax.swing.KeyStroke keyStroke)
        Returns the actionMapKey registerd for the keyStroke.
        Parameters:
        keyStroke - the keyStroke to bind
        Returns:
        the actionMapKey for the keyStroke or null if unbound.
      • put

        public void put(java.lang.Object key,
                        javax.swing.Action action)
        Registers a binding for key to action. Semantics are the same as that of the corresponding method in ActionMap.
        Parameters:
        key - the key used for binding.
        action - the action to bind.
        See Also:
        ActionMap.put(Object, Action)
      • get

        public javax.swing.Action get(java.lang.Object key)
        Returns the Action registered for key or null if none.
        Parameters:
        key - the key used for binding.
        Returns:
        the action registered for key or null it none available.

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.