[prev in list] [next in list] [prev in thread] [next in thread] 

List:       batik-users
Subject:    Clicking on SVG elements in the JSVGCanvas
From:       Stefan Van Uffelen <stefan.vanuffelen () uzleuven ! be>
Date:       2011-11-09 12:25:19
Message-ID: 07644620C52695468C8A85C76AC59CD669F2 () EX14MBX1E ! uz ! kuleuven ! ac ! be
[Download RAW message or body]

Hi,

I'm making an application that opens SVG files in a JSVGCanvas. The applica=
tion loads SVG-files from an external source and
Displays the JSVGCanvas wrapped in a JScrollPane which, in his turn, is wra=
pped 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 mousel=
istener that can give me the SVG element you clicked
On. My SVG consists of only <rect> and <circle> elements. Also text element=
s 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 ret=
urned 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 near=
est 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 poin=
t the user clicked on? Or is there anyway to convert the
SVG co=F6rdinates to screen co=F6rdinates?

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

---------
Stefan

[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.E-mailStijl17
	{mso-style-type:personal-compose;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="NL" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="NL-BE">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="NL-BE"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="NL-BE">I&#8217;m making an application that opens \
SVG files in a JSVGCanvas. The application loads SVG-files from an external source \
and<o:p></o:p></span></p> <p class="MsoNormal"><span lang="NL-BE">Displays the \
JSVGCanvas wrapped in a JScrollPane which, in his turn, is wrapped in a Jframe. My \
JSVGCanvas is set to ALWAYS_STATIC:<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE">jsvgCanvas.setDocumentState(AbstractJSVGComponent.ALWAYS_STATIC);<o:p></o:p></span></p>
 <p class="MsoNormal"><span lang="NL-BE"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="NL-BE">I do this to prevent a memoryleak from \
occuring. Now i wanted to add mouselistener that can give me the SVG element you \
clicked<o:p></o:p></span></p> <p class="MsoNormal"><span lang="NL-BE">On. My SVG \
consists of only &lt;rect&gt; and &lt;circle&gt; elements. Also text elements excist \
within the SVG. But those don&#8217;t need to be clickable.<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="NL-BE">First I made a list of all the &lt;rect&gt; and \
&lt;circle&gt; elements&nbsp; with:<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE">jsvgCanvas.getSVGDocument().getElementsByTagName(&quot;rect&quot;);<o:p></o:p></span></p>
 <p class="MsoNormal"><span \
lang="NL-BE">jsvgCanvas.getSVGDocument().getElementsByTagName(&quot;circle&quot;);<o:p></o:p></span></p>
 <p class="MsoNormal"><span lang="NL-BE"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span lang="NL-BE">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<o:p></o:p></span></p> <p class="MsoNormal"><span lang="NL-BE">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<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE">The SVG.<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE">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<o:p></o:p></span></p> <p \
class="MsoNormal"><span lang="NL-BE">SVG coördinates to screen \
coördinates?<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span lang="NL-BE">The \
application is running on windows 7 with JDK 1.6 using the latest version of \
batik.<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE">---------<o:p></o:p></span></p> <p class="MsoNormal"><span \
lang="NL-BE">Stefan<o:p></o:p></span></p> </div>
</body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic