Clicking on SVG elements in the JSVGCanvas

Stefan Van Uffelen <[email protected]>
Newsgroups gmane.text.xml.batik.user
Message-ID <[email protected]>
Hi,

I'm making an application that opens SVG files in a JSVGCanvas. The application loads SVG-files from an external source and
Displays the JSVGCanvas wrapped in a JScrollPane which, in his turn, is wrapped in a Jframe. My JSVGCanvas is set to ALWAYS_STATIC:

jsvgCanvas.setDocumentState(AbstractJSVGComponent.ALWAYS_STATIC);

I do this to prevent a memoryleak from occuring. Now i wanted to add mouselistener that can give me the SVG element you clicked
On. My SVG consists of only <rect> and <circle> elements. Also text elements excist within the SVG. But those don't need to be clickable.
First I made a list of all the <rect> and <circle> elements  with:

jsvgCanvas.getSVGDocument().getElementsByTagName("rect");
jsvgCanvas.getSVGDocument().getElementsByTagName("circle");

Now i can get the X and Y position of each of the elements in the lists returned by the method calls above. The problem now is that the
Mouseclick X and Y values are very different from the X and Y from the nearest element. The problem gets even worse when u rescale
The SVG.

Does batik provide an easy way to know which element is nearest to the point the user clicked on? Or is there anyway to convert the
SVG coördinates to screen coördinates?

The application is running on windows 7 with JDK 1.6 using the latest version of batik.

---------
Stefan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.