You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by mahesh karanth <tu...@yahoo.com> on 2006/01/11 07:08:15 UTC
Event listener problem
Hello All,
I want to handle a "click" event in a SVG document.
My code looks like this
public class PositionNrSelect implements EventListener
{
public void handleEvent(Event evt)
{
Element e=(Element)evt.getTarget();
if(e.getFirstChild()!=null)
{
// Do necessary processing....
}
}
}
I am adding the EVent listener as follows
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
svgDocument = (SVGDocument) f.createDocument(svgFileSys.toURL().toString());
svgCanvas.setDocument(svgDocument);
Element elt2 = svgCanvas.getSVGDocument().getRootElement();
EventTarget t2 = (EventTarget)elt2;
t2.addEventListener("click",new PositionNrSelect(),true);
Problem I am facing is ,Whenever I click on a number which is shown on loaded SVG I am able to enter into the evnt handling code that I have written , after this I am getting error Dailog of following type.
----
SVG Error:
E:\Mahesh\projects\geproject\Valid-test-data\new-test-data\case1\F3.072.200--001TKGMUL_03\UT_1 (The system cannot find the file specified)
-----
If I click on "details" button error shown is as folows
java.io.FileNotFoundException: E:\Mahesh\projects\geproject\Valid-test-data\new-test-data\case1\F3.072.200--001TKGMUL_03\UT_1 (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at org.apache.batik.util.ParsedURLData.openStreamInternal(Unknown Source)
at org.apache.batik.util.ParsedURLData.openStream(Unknown Source)
at org.apache.batik.util.ParsedURL.openStream(Unknown Source)
at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument(Unknown Source)
at org.apache.batik.dom.svg.SAXSVGDocumentFactory.createSVGDocument(Unknown Source)
at org.apache.batik.bridge.DocumentLoader.loadDocument(Unknown Source)
at org.apache.batik.swing.svg.SVGDocumentLoader.run(Unknown Source)
After which click has no effects ,either I donmt get error nor I the control enters the Event handling code.
What is the problem?
Is this possible fource to ignore the error dialog?
Please reply
Note:
I am pasting that part of SVG on which I am clicking...
<g id="UT">
<metadata id="CorelCorpID_2Corel-Layer"/>
<g id="UT_1_REF">
<polyline id="UT_1_REF_1" class="fil2 str2" points="203.483,72.9546 203.483,67.3247 209.113,67.3247 209.113,72.9546 203.483,72.9546 "/>
<line id="UT_1_REF_2" class="fil2 str2" x1="166.739" y1="105.01" x2="203.713" y2= "71.3094" />
<polyline id="UT_1_REF_3" class="fil2 str3" points="203.686,72.7773 203.686,67.5537 208.91,67.5537 208.91,72.7773 203.686,72.7773 "/>
<a xlink:href="UT_1">
<rect class="fil4" x="205" y="68" width="1" height="3"/>
<g transform="matrix(0.691005 0 0 1 108.866 -19.0694)">
<text x="140.034" y="90.4591" id="UT_1_REF_4" class="fil5 fnt0">1</text>
</g>
</a>
</g>
Best Regards
Mahesh Karanth
---------------------------------
Yahoo! Photos
Got holiday prints? See all the ways to get quality prints in your hands ASAP.
Re: Event listener problem
Posted by th...@kodak.com.
Hi Mahesh,
mahesh karanth <tu...@yahoo.com> wrote on 01/11/2006 01:08:15 AM:
> I want to handle a "click" event in a SVG document.
> Problem I am facing is ,Whenever I click on a number which is shown on
loaded
> SVG I am able to enter into the evnt handling code that I have written ,
after
> this I am getting error Dailog of following type.
> ----
> SVG Error:
> E:\Mahesh\projects\geproject\Valid-test-data\new-test-data\case1\F3.072.
> 200--001TKGMUL_03\UT_1 (The system cannot find the file specified)
Your SVG document has 'links' in it (the 'a' element with an xlink:href
attribute). The default behavior when one of these elements (or
it's children) is clicked is to load the referenced document (which
it appears you do not have), just like in HTML.
There are two solutions to this:
1) Remove the 'a' elements (the correct solution)
2) call 'preventDefault()' on the event object passed to your
event handler (the 'hack' solution ;).
> <a xlink:href="UT_1">
> <rect class="fil4" x="205" y="68" width="1" height="3"/>
> <g transform="matrix(0.691005 0 0 1 108.866 -19.0694)">
> <text x="140.034" y="90.4591" id="UT_1_REF_4" class="fil5
fnt0">1</text>
> </g>
> </a>
PS: Questions like this should really be asked on the 'users' list
not on the developers list.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org