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