Hello Matthew,

I think that you didn't put a listener in the correct/normal use.
I will give you an small example how to put a circle on a canvas on mouse
clicks.

Code:
=====

//We are going to react on mouse clicks, so the appropriate listener is
added
svgCanvas.addMouseListener(this);

// The following line is needed for our canvas to react on every change of
the document
// associated with it
svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);

............

public void mouseClicked(MouseEvent e) {
              addBall(e.getX(), e.getY());
}

private void addBall(int x, int y) {
    // The code is put into a Runnable object
        final int a = x;
        final int b = y;
        Runnable r = new Runnable() {
            public void run() {
                Element root = canvas.getSVGDocument().getDocumentElement();
                doc = (SVGDocument) canvas.getSVGDocument();
                // A new ball is created
                Element circle = doc.createElementNS(svgNS,
"circle");
                circle.setAttributeNS(null, "stroke", "black");
                circle.setAttributeNS(null, "stroke-width", "1");
                circle.setAttributeNS(null, "r", "" + 5);
                circle.setAttributeNS(null, "cx", "" + a);
                circle.setAttributeNS(null, "cy", "" + b);

                root.appendChild(circle);
            }
        };
        // Running our code in the UpdateManager thread
        UpdateManager um = canvas.getUpdateManager();
        um.getUpdateRunnableQueue().invokeLater(r);
    }

Pay attention on what you "listen" and how you update your canvas and I
think that you will get it.

PS: Please excuse my English.

Regards,


On Jan 20, 2008 11:47 PM, Matthew Wilson < [EMAIL PROTECTED]> wrote:

> Hi,
> I have written a Swing component which wraps JSVGCanvas, and I would
> like to capture DOM mouse click events so that I can draw on the canvas
> where the user has clicked. So I register and define my event listener
> like this:
>
> public class PlanViewPanel extends JPanel implements MouseWheelListener,
> EventListener, SVGLoadEventDispatcherListener {
>
> ....... stuff ......
>
>        public PlanViewPanel(SVGDocument svg) {
>        svgCanvas.setDocument(svg);
>           svgCanvas.addMouseWheelListener(this); // this is for
> something else entirely
>          scrollPane = new JSVGScrollPane(svgCanvas);
>        scrollPane.setScrollbarsAlwaysVisible(true);
>
> scrollPane.setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
>        add(scrollPane);
>        setMinimumSize(new Dimension(800,600));
>
> svgCanvas.getSVGDocument().getRootElement().addEventListener("click",
> this, false);
>        }
>
>             .... stuff ....
>        public void handleEvent(org.w3c.dom.events.Event evt) {
>                System.out.println("did something");
>
>        }
>
> }
>
> but my event handler is never called (I've placed a breakpoint and run
> it in the eclipse debugger to confirm this).  I have confirmed also
> using a debugger that the event handler is present in the hashtable in
> the document root's EventSupport structure, but I do not understand why
> it is not called. I have messed around with various different event
> types and tried bubble/capture, but nothing works.
>
> Using JDK 1.6.0 and Batik 1.7.
>
> Any suggestions would be greatly appreciated.
>
> Matthew Wilson.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to