Hi Mikhail,
Mikhail Gerdov <[email protected]> wrote on 02/26/2009 07:33:28 AM:
> Hi, I am trying to load SVG document created in third party
> application. Display it in my Java application, and detect mouse
> clicks on different svg elements.
> I am new to batik so probably I am doing something wrong. Here is my
code:
>
> String svgUri = new
File("data/test.svg").toURI().toString();
>
> JSVGCanvas svg = new JSVGCanvas();
I suspect you just need to set the canvas state to ALWAYS_DYNAMIC.
> try
> {
> String parser =
> XMLResourceDescriptor.getXMLParserClassName();
> SAXSVGDocumentFactory f = new
> SAXSVGDocumentFactory(parser);
> SVGDocument doc = (SVGDocument)f.
> createDocument(svgUri);
>
>
> EventTarget node = (EventTarget)
> doc.getElementById("rect1"); //
[...]
> svg.setSVGDocument(doc);
> }
Also In some cases the Canvas will clone your document (if
the DOM implementation isn't compatible). I don't think this
is your problem. If it were you would need to register an on load,
event handler (with the canvas) and add your event handler there.