You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Stefano Bruna <st...@tiscalinet.it> on 2003/12/05 00:51:25 UTC

Sending event to SVG document loaded in JSVGCanvas

Hi all !

 

Is this the correct way ti send an event to an element of a svg document
loader in a SVGCanvas ?

 

 
this.m_svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater
(new Runnable() {

                public void run() {

                    DocumentEvent de = null;

                    Element element = null;

                    try {

                        SVGDocument document =
m_svgCanvas.getSVGDocument();

                        element = document.getElementById("unload");

                        de = (DocumentEvent) document;

                    } catch (Exception e) {

                        // probabilemtne l’svg non è conforme al nostro
protocollo

                        e.printStackTrace();

                    }

                    Event ev = (Event)de.createEvent("MouseEvents");

                    ev.initEvent("click",false,false);

                    EventTarget t = (EventTarget) element;

                        t.dispatchEvent(ev); /// <------here sometimes
stop for secs 

 

                }

            });

 

Normally it works. But when application (an applet) uses network
sometimes execution flow hangs on method “ t.dispatchEvent(ev); “

The execution stops for a minnumum of 1 sec to a max of 10 sec on slow
PC. Normally execution, also on slow PC, doesn’t stop on it.

But the very strange think is that detaching Ethernet cable it always
run well.

 

The method t.dispatchEvent(ev); causes a click event on an element with
the attribute OnClick that call a Jscript function that do some Jscript
work and finally call the method “Commit” of an extended Jscript
interpreter :

 

…

ExtendedInterpreter extends RhinoInterpreter {

…

public ExtendedInterpreter(URL docURL) {

    super(docURL);

    final String[] names = {"Initialize",
"SetValue","GetValue","Commit","Finish"};

    try {

      getGlobalObject().defineFunctionProperties(names,
ExtendedInterpreter.class, ScriptableObject.DONTENUM);

    }

    catch (Exception e) {

      e.printStackTrace();

    }

  }

  …

 

so execution goes in Java environment doing some works and at the of
method returns in svg.

Then call “Finish” that cause SVG to be unloaded and substituted with
another svg document.

 

Dispathing event to the element permits Java -> SVG Jscript
communication

Extending RhinoInterpreter allows SVG JScript -> Java communication.

 

Is this a good way to obtain desired behaviour ?

And if yes why that strange “thinking” when dispatching event to DOM
only when application uses network ? (RMI and sockets)

 

The last thing to notice is that this happens only with recent nightly
batik release (probably 03-11-27 ) but work always well with old
downloadable batik jars.

 

I need to use new batik jar because of their good performance on very
heavy (1000 png and lots Jscript) svg document.

 

Thx for help. Bye

 

Stefano.

 

P.S. Msg.

Ciao Meo !!!

 


Re: Sending event to SVG document loaded in JSVGCanvas

Posted by Thomas DeWeese <Th...@Kodak.com>.
Stefano Bruna wrote:

> 
> 
> Hi all !
> 
>  
> 
> Is this the correct way ti send an event to an element of a svg document 
> loader in a SVGCanvas ?

    It looks mostly correct.

> 
> Normally it works. But when application (an applet) uses network 
> sometimes execution flow hangs on method “ t.dispatchEvent(ev); “
> 
> The execution stops for a minnumum of 1 sec to a max of 10 sec on slow 
> PC. Normally execution, also on slow PC, doesn’t stop on it.
> 
> But the very strange think is that detaching Ethernet cable it always 
> run well.

     Sounds like some network communication is timing out.

> The method t.dispatchEvent(ev); causes a click event on an element with 
> the attribute OnClick that call a Jscript function that do some Jscript 
> work and finally call the method “Commit” of an extended Jscript 
> interpreter :

   [...]

> Then call “Finish” that cause SVG to be unloaded and substituted with 
> another svg document.
> 
> Dispathing event to the element permits Java -> SVG Jscript communication
> 
> Extending RhinoInterpreter allows SVG JScript -> Java communication.

    Well I would probably just use interpreter.eval to do Java to
JavaScript communication.

    And I would probably just bind a Java object to enable JScript
to Java communication (if fact this is what I would do as I have
done it :).

> Is this a good way to obtain desired behaviour ?

    It sounds like it should work although I think the eval
and bind are a little cleaner.

> And if yes why that strange “thinking” when dispatching event to DOM 
> only when application uses network ? (RMI and sockets)

     Sounds like a problem in your RMI code?

> The last thing to notice is that this happens only with recent nightly 
> batik release (probably 03-11-27 ) but work always well with old 
> downloadable batik jars.

     I guess I don't follow you think the bug was introduced
on 11/27?  There wasn't a commit on 11/27 there was on 11/25
but I doubt that had anything to do with this.  Can you check
what the treads are doing while it is 'thinking'?  On Windows
you can trigger a thread dump with 'ctrl-break'  on Unix I
think a kill -3 does the same thing.

> I need to use new batik jar because of their good performance on very 
> heavy (1000 png and lots Jscript) svg document.

     I'm glad to hear this.  Let's see what we can find.



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org