如何将EasleJS库中的MouseEvent构造函数包装在GWT中?



我正在使用JSNI特性将同样非常方便的Canvas和Animation库移植到GWT。作为我包装的第一个库,我可以使用这个特殊的构造函数的一点帮助:

/**
* 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;

你可以在这里查看整个类:http://easeljs.com/docs/MouseEvent.js.html

我的问题是,我如何从GWT传递事件并成功地将其提供给该类的JSNI构造函数?

仅供参考:我已经分叉了Timknip的GWT端口的Easeljs(0.2.1),我正在更新它,以包括最新的Easel功能(0.4.0)。https://github.com/timknip/easel-gwt

编辑:我认为本地事件将是你用Java写的一个函数,对吗?假设您想在单击画布时添加ONMOUSEUP事件,并且逻辑保存在您编写的称为"onClickSomeButton()"的函数中,然后您想将此方法作为参数传递给此构造函数?我不认为Java可以传递方法作为参数,但是不是有一些方式来包装这扩展一些抽象的GWT类?

所有JavaScript函数都被视为对象,因此您可以简单地将其作为覆盖类型(扩展JavaScriptObject)传递,或者作为底层类型(JavaScriptObject本身)。

遇到这样的问题时,最好将处理程序(JavaScript事件处理程序)——在JavaScript层作为函数出现——视为接口,在Java层定义一个方法,并在下面包装一个JSO。

请参考谷歌文档中关于覆盖类型的更多信息

相关内容

最新更新