Hi All,
 
I've looked for an example of handling events, but I still can't figure it out! I made the method below
to add a listener for _EACH_ path in an svg file (I'm doing this in Batik Squiggle, after a document is loaded):
 

    public void setupEvents(SVGDocumentLoaderEvent e) {
 
        DocumentTraversal dt = (DocumentTraversal) e.getSVGDocument();
        NodeIterator      iter = dt.createNodeIterator(e.getSVGDocument().getRootElement(),                NodeFilter.SHOW_ALL, new MyFilter(), true);
        Node              n = iter.nextNode();
        int               id = 0;
        String            pathId = null;
        org.w3c.dom.events.EventListener OnClickAction(svgCanvas);

        while (n != null) {
            if (n instanceof SVGOMPathElement) {
                SVGOMPathElement s = (SVGOMPathElement) n;
                if ((s.getId() == null) || (s.getId().length() == 0)) {
                    pathId = "path" + id;
                    s.setId(pathId);
                    id++;
                } else {
                    pathId = s.getId();
                }
                EventTarget t;
                t = (EventTarget) (e.getSVGDocument().getElementById(pathId));
                t.addEventListener("click", onClick, true);
            }
            n = iter.nextNode();
        }
    }

The listener is not called when you click on the image after it's loaded. How should I do this?

 

Thanks,

 

Ron

Reply via email to