Hi all, I was just wondering if anyone could help me out. I m working on an app that displays SVG content in JSVGCanvas. The SVG document contains a few hotspots that when clicked will trigger an action. (I have listeners for these and they work fine). One of these actions is to open another document in the JSVGCanvas when an element is clicked - this also works fine. Now what I want to do is register listeners on elements of this document and this where it all falls apart. Even though the document has been updated it just wont add a listener to the element in the new SVG document.
At the moment I m just trying to do simple navigation between different SVG documents i.e. load SVG file, click on an element on the file, load another svg file, click on an element on that file and that returns you to the original. Now I m just wondering if I m missing something or if this is possible. Any help would be appreciated. Thanks Ned Here is sample code... // get the location of the doc and set it to canvas String loc = "sample.svg"; File f = new File(loc); try{ jSVGCanvas1.setURI(f.toURL().toString()); } catch (Exception ex) { ex.printStackTrace(); } jSVGCanvas1.addSVGLoadEventDispatcherListener (new SVGLoadEventDispatcherAdapter() { public void svgLoadEventDispatchStarted (SVGLoadEventDispatcherEvent e) { document = jSVGCanvas1.getSVGDocument(); window = jSVGCanvas1.getUpdateManager ().getScriptingEnvironment().createWindow(); // Registers the listeners on the document just before the SVGLoad event is dispatched. registerListeners(); } }); jSVGCanvas1.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter(){ public void documentLoadingStarted(SVGDocumentLoaderEvent e){ System.out.println("loading..."); } public void documentLoadingCompleted(SVGDocumentLoaderEvent e) { System.out.println("finished loading..."); } }); jSVGCanvas1.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter(){ public void gvtBuildStarted(GVTTreeBuilderEvent e){ System.out.println("building..."); } public void gvtBuildCompleted(GVTTreeBuilderEvent e){ System.out.println("finished building..."); } }); jSVGCanvas1.addGVTTreeRendererListener(new GVTTreeRendererAdapter(){ public void gvtRenderingPrepare(GVTTreeRendererEvent e) { System.out.println("rendering..."); } public void gvtRenderingCompleted(GVTTreeRendererEvent e){ System.out.println("Finished rendering..."); // want to set the document element to what ever is in the JSVGCanvas and register listenrs again document = jSVGCanvas1.getSVGDocument(); registerListeners(); } }); public void registerListeners() { // element "Primary" belongs to samle.svg file Element elt = document.getElementById("Primary"); if(elt != null){ EventTarget t = (EventTarget)elt; // Adds a 'onclick' listener t.addEventListener("click", new OnClickAction(), false); } // element home belongs to sample2.svg file Element elt2 = document.getElementById("home"); if(elt2 != null){ EventTarget t2 = (EventTarget)elt2; t2.addEventListener("SVGLoad", new OnLoadAction1(), true); t2.addEventListener("click", new OnClickAct(), true); } } // when a hotspot is clicked then change the document in JSVGCanvas public class OnClickAction implements EventListener { public void handleEvent(Event evt) { String loc1 = "sample1.svg"; File f = new File(loc1); try{ jSVGCanvas1.setURI(f.toURL().toString()); } catch (Exception ex){ ex.printStackTrace(); } } } // when hotspot is clicked bring back to original public class OnClickAct implements EventListener { public void handleEvent(Event evt) { String loc = "sample.svg"; File f = new File(loc); try{ jSVGCanvas1.setURI(f.toURL().toString()); } catch (Exception ex){ ex.printStackTrace(); } } }