com.gwtext.client.util
Class KeyMap

java.lang.Object
  extended by com.gwtext.client.core.JsObject
      extended by com.gwtext.client.util.KeyMap

public class KeyMap
extends JsObject

Handles mapping keys to actions for an element. One key map can be used for multiple actions. If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key combination it will call the function with this signature (if the match is a multi-key combination the callback will still be called only once): (String key, EventObject e) A KeyMap can also handle a string representation of keys.

       // map one key by key code
       KeyMap map = new KeyMap("my-element", new KeyMapConfig() {
           {
               setKey(13);  // or EventObject.ENTER
               setKeyListener(new KeyListener() {
                   public void onKey(int key, EventObject e) {
                       //handle key
                   }
               });
           }
       });
 

// map multiple keys to one action by string KeyMap map = new KeyMap("my-element", new KeyMapConfig() { { setKey("a\r\n\t"); setKeyListener(new KeyListener() { public void onKey(int key, EventObject e) { //handle key } }); } });

KeyMap map = new KeyMap("my-element", new KeyMapConfig() { { setKey(new int[]{10, 13}); setKeyListener(new KeyListener() { public void onKey(int key, EventObject e) { // return was pressed } }); } });

KeyMap map = new KeyMap("my-element", new KeyMapConfig() { { setKey("abc"); setKeyListener(new KeyListener() { public void onKey(int key, EventObject e) { // a, b or c was pressed } }); } });

KeyMap map = new KeyMap("my-element", new KeyMapConfig() { { setKey("\t"); setCtrl(true); setShift(true); setKeyListener(new KeyListener() { public void onKey(int key, EventObject e) { // Ctrl + shift + tab was pressed } }); } });


Field Summary
 
Fields inherited from class com.gwtext.client.core.JsObject
jsObj
 
Constructor Summary
KeyMap(com.google.gwt.user.client.Element el, KeyMapConfig config)
          Create a new key map for the element.
KeyMap(com.google.gwt.user.client.Element el, KeyMapConfig config, java.lang.String eventName)
          Create a new key map for the element.
KeyMap(com.google.gwt.core.client.JavaScriptObject jsObj)
           
KeyMap(java.lang.String id, KeyMapConfig config)
          Create a new key map for the element.
KeyMap(java.lang.String id, KeyMapConfig config, java.lang.String eventName)
          Create a new key map for the element.
 
Method Summary
 void addBinding(KeyMapConfig config)
          Add a new binding to this KeyMap.
 void disable()
          Disable this KeyMap.
 void enable()
          Enable this KeyMap,
 boolean isEnabled()
          Returns true if this KeyMap is enabled.
 void setStopEvent(boolean stopEvent)
          True to stop the event from bubbling and prevent the default browser action if the key was handled by the KeyMap (defaults to false).
 
Methods inherited from class com.gwtext.client.core.JsObject
getJsObj, getProperties, isCreated, setJsObj
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyMap

public KeyMap(com.google.gwt.core.client.JavaScriptObject jsObj)

KeyMap

public KeyMap(java.lang.String id,
              KeyMapConfig config)
Create a new key map for the element.

Parameters:
id - the element id
config - keymap config

KeyMap

public KeyMap(com.google.gwt.user.client.Element el,
              KeyMapConfig config)
Create a new key map for the element.

Parameters:
el - the element
config - keymap config

KeyMap

public KeyMap(java.lang.String id,
              KeyMapConfig config,
              java.lang.String eventName)
Create a new key map for the element.

Parameters:
id - the element id
config - keymap config
eventName - the event to bind to (defaults to "keydown")

KeyMap

public KeyMap(com.google.gwt.user.client.Element el,
              KeyMapConfig config,
              java.lang.String eventName)
Create a new key map for the element.

Parameters:
el - the element
config - keymap config
eventName - the event to bind to (defaults to "keydown")
Method Detail

addBinding

public void addBinding(KeyMapConfig config)
Add a new binding to this KeyMap.

Parameters:
config - new binding config

disable

public void disable()
Disable this KeyMap.


enable

public void enable()
Enable this KeyMap,


isEnabled

public boolean isEnabled()
Returns true if this KeyMap is enabled.

Returns:
true if enabled

setStopEvent

public void setStopEvent(boolean stopEvent)
True to stop the event from bubbling and prevent the default browser action if the key was handled by the KeyMap (defaults to false).

Parameters:
stopEvent - true to stop event bubbling