Ludovic,

You are close to what you want. When you run your code, the circle comes out yellow right? It does in my environment. If it does not in yours, it may be because you are running an old version of Batik. You would need to switch to 1.5beta5 or, even better, the current CVS version.

However, to have an onclick handler, the code in the SVG file and in your Java file need to be modified.

SVG: No 'onclick' attribute

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd";>
<svg xmlns="http://www.w3.org/2000/svg";
xmlns:xlink="http://www.w3.org/1999/xlink";>


  <script type="application/java-archive"
          xlink:href="SVGApplication.jar" />
  <circle id="myclic-circle" cx="25" cy="25" r="25" fill="red" />
</svg>

Handler:

import org.w3c.dom.*;
import org.w3c.dom.events.*;
import org.apache.batik.script.ScriptHandler;
import org.apache.batik.script.Window;

public class SVGApplication implements ScriptHandler, EventListener {
private Document document;
public void run (final Document document, final Window win) {
this.document = document;
EventTarget changecolor = (EventTarget)document.getElementById("myclic-circle");
changecolor.addEventListener("click", this, false);
}
public void handleEvent(Event evt) {
Element changecolor = document.getElementById("myclic-circle");
changecolor.setAttributeNS(null, "fill", "#0F0");
}
}


Vincent.

Ludovic DESFORGES wrote:

What I would like to do, is just a little example of how to use ScripHandler.java
Could you please help me. Just few words.


-----
I have tried this: - but I don't have the expected "yellow circle".

------------------------
SVGApplication.java
------------------------
import org.w3c.dom.*;
import org.apache.batik.script.ScriptHandler;
import org.apache.batik.script.Window;

public class SVGApplication implements ScriptHandler {
public void run (final Document document, final Window win) {
Element changecolor=document.getElementById("myclic-circle");
changecolor.setAttributeNS(null, "style", "fill:yellow");
}
}
------------
manifest.mf
------------
Manifest-Version: 1.0
Script-Handler: SVGApplication
------------------------
SVGApplication.svg
------------------------
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd";>
<svg xmlns="http://www.w3.org/2000/svg";
xmlns:xlink="http://www.w3.org/1999/xlink";>


<script type="application/java-archive"
xlink:href="SVGApplication.jar" />
<circle id="myclic-circle" cx="25" cy="25" r="25" style="fill:blue" onclick="SVGApplication()" />
</svg>
--------
launch
--------
cd c:\temp\ (all are in that directory)
javac SVGApplication.java
jar cmf manifest.mf SVGApplication.jar *.class
My .class and .jar are now in the directory c:\temp\
Then, when I try the svg file, and clic on the "blue circle" I don't have the expected "yellow circle".
---
In fact, with this examle, I would like to succeed the http://xml.apache.org/batik/javaScripting.html SVGApplication.
---


Thank for your help
Ludovic Desforges


--------------------------------------------------------------------- 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]



Reply via email to