I am porting same very handy Canvas and Animation libraries to GWT using the JSNI feature. Being the first library I am wrapping I could use a little assistance with this particular constructor:
/**
* This is passed as the parameter to onPress, onMouseMove, onMouseUp, onMouseDown, and onClick handlers on
* DisplayObject instances.
* By default, mouse events are disabled for performance reasons. In order to enabled them for a specified stage
* set mouseEventsEnabled to true on your stage instance.
* @class MouseEvent
* @constructor
* @param {String} type The event type.
* @param {Number} stageX The mouseX position relative to the stage.
* @param {Number} stageY The mouseY position relative to the stage.
* @param {DisplayObject} target The display object this event relates to.
* @param {MouseEvent} nativeEvent The native DOM event related to this mouse event.
**/
var MouseEvent = function(type, stageX, stageY, target, nativeEvent) {
this.initialize(type, stageX, stageY, target, nativeEvent);
}
var p = MouseEvent.prototype;
You can view the entire class here: http://easeljs.com/docs/MouseEvent.js.html
My question is, how do I go about passing the event from GWT and successfully feed it to the JSNI constructor for this class?
FYI: I have forked Timknip’s GWT port of Easeljs (0.2.1) and i’m updating it to include the latest Easel features (0.4.0). https://github.com/timknip/easel-gwt
EDIT: I think the native event would be a function you have written in Java, correct? Say you want to add a ONMOUSEUP event when you click the canvas somewhere, and the logic is kept in a function you wrote called “onClickSomeButton()”, then you want to pass this method as a parameter in this constructor? I don’t think Java can pass methods as parameters but isn’t there some way to wrap this by extending some abstract GWT class?
All JavaScript functions are treated as objects, so you can simply pass it as an overlay type (extending
JavaScriptObject), or as the underlying type (JavaScriptObjectitself).When encountering an issue like this, it’s best to treat the handler (JavaScript event handler) – appearing as a function at the JavaScript layer – as an interface, defining one method at the Java layer, and wrapping a JSO underneath.
Please refer to Google’s docs on overlay types for more on this.