001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.client.util;
009:
010: import com.gwtext.client.core.BaseConfig;
011: import com.gwtext.client.widgets.event.KeyListener;
012:
013: /**
014: * KeyMap configuration class.
015: */
016: public class KeyMapConfig extends BaseConfig {
017:
018: public KeyMapConfig() {
019: }
020:
021: /**
022: * The keycode to handle.
023: *
024: * @param keyCode the keycode
025: */
026: public KeyMapConfig(int keyCode) {
027: JavaScriptObjectHelper.setAttribute(jsObj, "key", keyCode);
028: }
029:
030: /**
031: * An array of keycodes to handle.
032: *
033: * @param keyCodes keycodes
034: */
035: public KeyMapConfig(int[] keyCodes) {
036: JavaScriptObjectHelper.setAttribute(jsObj, "key",
037: JavaScriptObjectHelper
038: .convertToJavaScriptArray(keyCodes));
039: }
040:
041: /**
042: * A list of keys to handle.
043: *
044: * @param keys the keys to handles
045: */
046: public KeyMapConfig(String keys) {
047: JavaScriptObjectHelper.setAttribute(jsObj, "key", keys);
048: }
049:
050: /**
051: * The keycode to handle.
052: *
053: * @param key the keycode
054: */
055: public void setKey(int key) {
056: JavaScriptObjectHelper.setAttribute(jsObj, "key", key);
057: }
058:
059: /**
060: * A list of keys to handle.
061: *
062: * @param keys the keys to handles
063: */
064: public void setKey(String keys) {
065: JavaScriptObjectHelper.setAttribute(jsObj, "key", keys);
066: }
067:
068: /**
069: * An array of keycodes to handle.
070: *
071: * @param keyCodes keycodes
072: */
073: public void setKey(int[] keyCodes) {
074: JavaScriptObjectHelper.setAttribute(jsObj, "key",
075: JavaScriptObjectHelper
076: .convertToJavaScriptArray(keyCodes));
077: }
078:
079: /**
080: * True to handle key only when ctrl is pressed (defaults to false).
081: *
082: * @param ctrl true to handle ctrl
083: */
084: public void setCtrl(boolean ctrl) {
085: JavaScriptObjectHelper.setAttribute(jsObj, "ctrl", ctrl);
086: }
087:
088: /**
089: * True to handle key only when alt is pressed (defaults to false).
090: *
091: * @param alt true to handle alt
092: */
093: public void setAlt(boolean alt) {
094: JavaScriptObjectHelper.setAttribute(jsObj, "alt", alt);
095: }
096:
097: /**
098: * True to handle key only when shift is pressed (defaults to false)
099: *
100: * @param shift true to handle shift
101: */
102: public void setShift(boolean shift) {
103: JavaScriptObjectHelper.setAttribute(jsObj, "shift", shift);
104: }
105:
106: /**
107: * The listener to call when KeyMap finds the expected key combination.
108: *
109: * @param listener the listener
110: */
111: public native void setKeyListener(KeyListener listener) /*-{
112: var config = this.@com.gwtext.client.core.JsObject::getJsObj()();
113: config['fn'] = function(key, event) {
114: var e = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(event);
115: listener.@com.gwtext.client.widgets.event.KeyListener::onKey(ILcom/gwtext/client/core/EventObject;)(key, e);
116: };
117: }-*/;
118: }
|