I would like to listen for the mouse over event in GWT 1.6. Since GWT 1.6 has introduced handlers and deprecated listeners I\'m unsure as to how I can accomplish this with what
You'd want to implement these interfaces in your class:
MouseOverEvent is fired when the mouse enters the element, and MouseOutEvent is fired when it's no longer over.
HasMouseOverHandler is implemented like this:
public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
return addDomHandler(handler, MouseOverEvent.getType());
}
HasMouseOutHandler is implemented like this:
public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
return addDomHandler(handler, MouseOutEvent.getType());
}
After that you just handle the events with a MouseOverHandler and MouseOutHandler, should be pretty straightforward after that.
If you want to add an EventHandler to an Element that already exists in the HTML the only idea I've come up with is creating a wrapper class. This is completely untested.
class ElementWrapper extends UIObject implements HasMouseOverHandlers,
HasMouseOutHandlers
{
public ElementWrapper(Element theElement)
{
setElement(theElement);
}
public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
return addDomHandler(handler, MouseOutEvent.getType());
}
public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
return addDomHandler(handler, MouseOverEvent.getType());
}
}
Then you could get an existing Element from the HTML and initialize like this:
onModuleLoad()
{
Element theElement = RootPanel().get("elementID");
ElementWrapper wrapper = new ElementWrapper(theElement);
wrapper.addMouseOverHandler(new myHandler());
}
Hope this helps.