Thanks for the answer,
in fact I use the example given on the page "Java Scripting" and I've
just modified it to support a file chooser and my event :
public void registerListeners() {
// Gets an element from the loaded document.
Element elt = document.getElementById("elt-id");
EventTarget t = (EventTarget)elt;
// Adds a 'onclick' listener
t.addEventListener("testEvent", new OnClickAction(), false);
}
public class OnClickAction implements EventListener {
public void handleEvent(Event evt) {
// Make some actions here...
label.setText("Event captured");
}
}
I've taken the svg example of the french svg article of wikipedia and
I've added an onclick event (onclick="testEvent") on a rectangle :
<?xml version="1.0" encoding="utf-8"?>
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ev="http://www.w3.org/2001/xml-events"
version="1.1"
baseProfile="full"
x="0"
y="0"
width="300"
height="200"
id="svg2">
<title>Rectangles</title>
<defs
id="defs4" />
<g
id="layer1">
<rect
width="300"
height="120"
x="0"
y="20"
fill="green"
id="rect1306" />
<rect
/*Here is my event */
onclick="testEvent"
width="80"
height="150"
x="20"
y="30"
fill="red"
id="rect1308" />
<rect
width="140"
height="80"
x="50"
y="50"
fill="blue"
id="rect1310" />
</g>
</svg>
When I run my code with this svg, and I click on the rectangle, I
obtain a message "svg error, testEvent not defined", perhaps it comes
from my event in the svg file ?
Quoting [EMAIL PROTECTED]:
Hi nmotte,
[EMAIL PROTECTED] wrote on 04/16/2006 08:41:03 PM:
I'm a beginner in svg and batik. I would like to use an svg event (for
example an onclick on a rectangle in a svg file) in my java code to
call a method. I thought that the example given the page Java
Scripting of the Batik website would do that, but apparently it's not
the case.
I think it does this, perhaps you can explain why you think it
doesn't? In particular the following code from the example on
that page seems like it meets your needs (you can do what ever you want
in the handleEvent method of the listeners).
public void registerListeners() {
// Gets an element from the loaded document.
Element elt = document.getElementById("elt-id");
EventTarget t = (EventTarget)elt;
// Adds a 'onload' listener
t.addEventListener("SVGLoad", new OnLoadAction(), false);
// Adds a 'onclick' listener
t.addEventListener("click", new OnClickAction(), false);
}
public class OnLoadAction implements EventListener {
public void handleEvent(Event evt) {
// Make some actions here...
// ...for example start an animation loop:
window.setInterval(new Animation(), 50);
}
}
public class OnClickAction implements EventListener {
public void handleEvent(Event evt) {
// Make some actions here...
// ...for example schedule an action for later:
window.setTimeout(new DelayedTask(), 500);
}
}
Is there any simple solution ?
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]