Certainly - remember that all of the GwtEvent objects are completely artificial and are based off of events fired from the native JavaScript. That JavaScript event object, (which comes in via onBrowserEvent
) gets wrapped up as a ClickEvent
or a KeyDownEvent
based on the details of the original object, and then fired off via the internal HandlerManager
instance. In the same way, you could listen for a MouseDownEvent
, set some state, then if a MouseMoveEvent
occurs, fire your own CanvasDrag
event. You'd probably stop listening to those move events once a MouseUpEvent
happens, then you would issue something like a CanvasDropEvent
. If isntead the MouseUpEvent
occurred right away with no move, you could trigger a CanvasSelectEvent
(or you might have something else in mind for that select event).
Each of these new event types you declare then might contain specifics about whatever is going on. For example, while a MouseMoveEvent just has the element that the mouse is over and the x/y coords, you might be indicating what is being dragged around the page. That might be in the form of the shape that was last clicked, or even the data it represents.
Yes, the 'sender', or source, is already there, but it'll be easier to use if you expose some kind of a method to add handlers like addCanvasDragHandler
, etc. This is not required - all users of your code could just use addHandler
, but it does make it a little ambiguous about whether or not the widget supports the event in question. You would then call fireEvent
on the canvas object to make all handlers of that event type listen.
Or, you could make a new class that contains an internal Canvas
widget - possibly a Composite
object or just something that implements IsWidget
(Canvas has a private constructor, so you can't subclass it). This would enable you to add your own particular handlers, and keep your own HandlerManager/EventBus to track the events you are concerned with.