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:
009: package com.gwtext.client.core;
010:
011: import com.google.gwt.core.client.JavaScriptObject;
012: import com.google.gwt.user.client.Element;
013: import com.google.gwt.user.client.Event;
014:
015: /**
016: * A normalized Event object. Can use DOM.eventGetType(Event) for determinint event type too.
017: */
018: public class EventObject extends JsObject {
019:
020: public static int BACKSPACE, CONTROL, DELETE, DOWN, END, ENTER,
021: ESC, F5, HOME, LEFT, PAGEDOWN, PAGEUP, RETURN, RIGHT,
022: SHIFT, SPACE, TAB, UP;
023:
024: /*
025: Initializing constants from JsObject static bloc instead of here because of issue with OS X
026: See http://code.google.com/p/gwt-ext/issues/detail?id=71
027: static {
028: initConstants();
029: }*/
030:
031: public EventObject(JavaScriptObject jsObj) {
032: super (jsObj);
033: }
034:
035: public static EventObject instance(JavaScriptObject event) {
036: return new EventObject(event);
037: }
038:
039: /**
040: * Gets the key code for the event.
041: *
042: * @return the key code for the event.
043: */
044: public native int getCharCode() /*-{
045: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
046: return e.getCharCode();
047: }-*/;
048:
049: /**
050: * Returns a normalized keyCode for the event.
051: *
052: * @return a normalized keyCode for the event.
053: */
054: public native int getKey() /*-{
055: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
056: var key = e.getKey();
057: return key == null || key === undefined ? -1 : key;
058: }-*/;
059:
060: /**
061: * Gets the related target.
062: *
063: * @return the related target.
064: */
065: public native Element getRelatedTarget() /*-{
066: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
067: var rt = e.getRelatedTarget();
068: return rt === undefined ? null : rt;
069: }-*/;
070:
071: /**
072: * Gets the target for the event.
073: *
074: * @return the target for the event.
075: */
076: public native Element getTarget() /*-{
077: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
078: var el = e.getTarget();
079: return el === undefined ? null : el;
080: }-*/;
081:
082: public native Element getTarget(String selector, int maxDepth) /*-{
083: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
084: var el = e.getTarget(selector, maxDepth);
085: return el === undefined ? null : el;
086: }-*/;
087:
088: public native long getTime() /*-{
089: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
090: return e.getTime();
091: }-*/;
092:
093: public native int getWheelDelta() /*-{
094: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
095: return e.getWheelDelta();
096: }-*/;
097:
098: /**
099: * Gets the xy coordinates of the event.
100: *
101: * @return the xy coordinates of the event.
102: */
103: public int[] getXY() {
104: return new int[] { getPageX(), getPageY() };
105: }
106:
107: /**
108: * Gets the x coordinate of the event.
109: *
110: * @return the x coordinate of the event.
111: */
112: public native int getPageX() /*-{
113: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
114: return e.getPageX();
115: }-*/;
116:
117: /**
118: * Gets the y coordinate of the event.
119: *
120: * @return the y coordinate of the event.
121: */
122: public native int getPageY() /*-{
123: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
124: return e.getPageY();
125: }-*/;
126:
127: /**
128: * Returns true if the control, meta, shift or alt key was pressed during this event.
129: *
130: * @return true if the control, meta, shift or alt key was pressed during this event.
131: */
132: public native boolean hasModifier() /*-{
133: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
134: return e.hasModifier();
135: }-*/;
136:
137: /**
138: * Stop the event (preventDefault and stopPropagation)
139: */
140: public native void stopEvent() /*-{
141: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
142: e.stopEvent();
143: }-*/;
144:
145: /**
146: * Cancels bubbling of the event.
147: */
148: public native void stopPropagation() /*-{
149: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
150: e.stopPropagation();
151: }-*/;
152:
153: /**
154: * Returns true if the target of this event equals el or is a child of el
155: *
156: * @param id the element ID
157: * @return true if target within
158: */
159: public native boolean within(String id) /*-{
160: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
161: var bool = e.within(id);
162: return bool == undefined || bool == null ? false : bool;
163: }-*/;
164:
165: /**
166: * Returns true if the target of this event equals el or is a child of el
167: *
168: * @param elem the element
169: * @return true if target within
170: */
171: public native boolean within(Element elem) /*-{
172: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
173: var bool = e.within(elem);
174: return bool == undefined || bool == null ? false : bool;
175: }-*/;
176:
177: /**
178: * Return true if is Alt key.
179: *
180: * @return true if is Alt key.
181: */
182: public native boolean isAltKey() /*-{
183: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
184: var isAlt = e.altKey;
185: return (isAlt == null || isAlt === undefined) ? false : isAlt;
186: }-*/;
187:
188: /**
189: * Return true if is Ctrl key.
190: *
191: * @return true if is Ctrl key.
192: */
193: public native boolean isCtrlKey() /*-{
194: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
195: var isCrtl = e.ctrlKey;
196: return (isCrtl == null || isCrtl === undefined) ? false : isCrtl;
197: }-*/;
198:
199: /**
200: * Return true if is Shift key.
201: *
202: * @return true if is Shift key.
203: */
204: public native boolean isShiftKey() /*-{
205: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
206: var isShift = e.shiftKey;
207: return (isShift == null || isShift === undefined) ? false : isShift;
208: }-*/;
209:
210: /**
211: * @return -1 = none, 0 = left, 1 = middle, 2 right
212: */
213: public native int getMouseButton() /*-{
214: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
215: return e.button;
216: }-*/;
217:
218: /**
219: * Return the native browser event.
220: *
221: * @return the native browser event
222: */
223: public native Event getBrowserEvent() /*-{
224: var e = this.@com.gwtext.client.core.JsObject::getJsObj()();
225: return e.browserEvent;
226: }-*/;
227: }
|