Hi Thomas,
Thank you for the reply, Its working now. I forgot to set the set the canvas
to 'ALWAYS_DYNAMIC'....
On 2/2/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Hi Ned,
Ned <[EMAIL PROTECTED]> wrote on 02/02/2007 05:16:16 AM:
> Now what I want to do is register listeners on elements of this
> [newly loaded] document and this where it all falls
> apart. Even though the document has been updated it just wont add a
> listener to the element in the new SVG document.
> Now I m just wondering if I m missing something or if this is
> possible. Any help would be appreciated.
It should be possible, I saw to suspicious things
in the code below;
1) You should register your SVGLoadEventDispatcherListener
before calling setURI, since loading is async it's
possible the thread get's past the SVGLoad dispatch
before your listener is attached.
2) The call the 'createWindow()' does just that creates
the window object, it doesn't tie it into the document
fully, so if your register code is depending on this
you might have problems...
That all said I'm not very confident that either of
those is really your problem.
Perhaps Batik doesn't think your document is dynamic?
Did you set the canvas to 'ALWAYS_DYNAMIC'? Otherwise
if your document lacks any event attributes Batik will
assume it's a static document and not dispatch any
events.
> Here is sample code...
>
> // get the location of the doc and set it to canvas
> String loc = "sample.svg";
> File f = new File(loc);
> try{
> jSVGCanvas1.setURI(f.toURL().toString());
> }
> catch (Exception ex) {
> ex.printStackTrace();
> }
>
> jSVGCanvas1.addSVGLoadEventDispatcherListener
> (new SVGLoadEventDispatcherAdapter() {
> public void svgLoadEventDispatchStarted
> (SVGLoadEventDispatcherEvent e) {
> document = jSVGCanvas1.getSVGDocument();
> window = jSVGCanvas1.getUpdateManager().
> getScriptingEnvironment().createWindow();
> // Registers the listeners on the document just
> before the SVGLoad event is dispatched.
> registerListeners();
> }
> });
>
> jSVGCanvas1.addSVGDocumentLoaderListener(new
> SVGDocumentLoaderAdapter(){
> public void documentLoadingStarted(SVGDocumentLoaderEvent
e){
> System.out.println("loading...");
> }
>
> public void documentLoadingCompleted(SVGDocumentLoaderEvent
e) {
> System.out.println("finished loading...");
> }
> });
>
> jSVGCanvas1.addGVTTreeBuilderListener (new
GVTTreeBuilderAdapter(){
> public void gvtBuildStarted(GVTTreeBuilderEvent e){
> System.out.println("building...");
> }
>
> public void gvtBuildCompleted(GVTTreeBuilderEvent e){
> System.out.println("finished building...");
> }
> });
>
> jSVGCanvas1.addGVTTreeRendererListener(new
GVTTreeRendererAdapter(){
> public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
> System.out.println("rendering...");
> }
> public void gvtRenderingCompleted(GVTTreeRendererEvent e){
> System.out.println("Finished rendering...");
> // want to set the document element to what ever is
> in the JSVGCanvas and register listenrs again
> document = jSVGCanvas1.getSVGDocument();
> registerListeners();
> }
> });
>
> public void registerListeners() {
> // element "Primary" belongs to samle.svg file
> Element elt = document.getElementById("Primary");
> if(elt != null){
> EventTarget t = (EventTarget)elt;
> // Adds a 'onclick' listener
> t.addEventListener("click", new
> OnClickAction(), false);
> }
>
> // element home belongs to sample2.svg file
> Element elt2 = document.getElementById("home");
> if(elt2 != null){
> EventTarget t2 = (EventTarget)elt2;
> t2.addEventListener("SVGLoad", new OnLoadAction1(),
true);
> t2.addEventListener("click", new OnClickAct(), true);
> }
> }
>
> // when a hotspot is clicked then change the document in JSVGCanvas
> public class OnClickAction implements EventListener {
> public void handleEvent(Event evt) {
> String loc1 = "sample1.svg";
> File f = new File(loc1);
> try{
> jSVGCanvas1.setURI(f.toURL().toString());
> }
> catch (Exception ex){
> ex.printStackTrace();
> }
> }
> }
>
> // when hotspot is clicked bring back to original
> public class OnClickAct implements EventListener {
> public void handleEvent(Event evt) {
> String loc = "sample.svg";
> File f = new File(loc);
> try{
> jSVGCanvas1.setURI(f.toURL().toString());
> }
> catch (Exception ex){
> ex.printStackTrace();
> }
> }
> }
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]