tags:

views:

39

answers:

0

I'm using RaphaelGWT to draw shapes with the underlying RaphaelJS library. The basic RaphaelGWT Shape classes extends Widget, Circle extends Shape, and my CircleClickable extends Circle. I've tried to extend these objects so they can handle clicks but it's not working. There's an example in the RaphaelGWT for this, and I'm doing the same thing, but it's not working.

Here's my CircleClickable:

public class CircleClickable extends Raphael.Circle implements HasClickHandlers {
    public CircleClickable(double x, double y, double r) {
        super(x, y, r);
        attr("fill", "white");
    }

    public HandlerRegistration addClickHandler(ClickHandler handler) {
        return this.addDomHandler(handler, ClickEvent.getType());
    }

}

The base Raphael class also extends Widget and is comparable to a drawing canvas. So I've got a class which extends Raphael, contains all these shapes I'm drawing, and handles all the clicks for all the shapes so they don't each have they're own ClickHandler :

public class MyRaphaelDrawing extends Raphael implements ClickHandler {
    public void onClick(ClickEvent e) {
        System.out.println("MyRaphaelDrawing::onClick, clicked on " + e.getSource());
    }

    public void addCircle() {
        CircleClickable cc = new CircleClickable(50, 50, 25);
        cc.addClickHandler(this);
    }
}

The onClick in MyRaphaelDrawing is never being called. Why? Do I need to add sinkEvents() to MyRaphaelDrawing? I thought that was the 'old' way of doing things.

FYI, if you're curious about the RaphaelGWT project, here's an excellent blog post about it.