xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reinhard Brandstädter <r.brandstaed...@gmx.at>
Subject Re: When to register EventListeners?
Date Sat, 11 Oct 2003 10:09:04 GMT
Thomas DeWeese wrote:
> Reinhard Brandstädter wrote:
> 
>> Hi!
>>
>> I'm just playing around with Java Scripting and Event Handling but I 
>> think I'm missing a basic understanding of when to register event 
>> Listeners.
>>
>> When I create a whole dom tree document is it possible to register 
>> listeners when I create and add elements to the tree so that the 
>> listeners can handle events as soon as the DOM is rendered in a canvas?
> 
> 
>   Yes, you should be able to register listeners before the Document
> is associated with the Canvas.
> 
>>
>> jSVGCanvas1.setURI(uri);
>>
>> ...
>>
>> while (cond) {
>> Element elem = <getElement Object here>
>> EventTarget target = (EventTarget)elem;
>> target.addEventListener("OnMouseOver",new OnMouseOverAction(),false);
>> target.addEventListener("OnMouseOut",new OnMouseOutAction(),false);
>> doc.getRootElement().appendChild(gelem);'
> 
> 
>    This confuses me a little why are you appending the element.
> Are you constructing the document "on the fly"?

Yes, I'm generating the document on the fly. I think that's the main 
issue I've got here. The DOM I generate is quite large and I don't have 
the need to do an update of the canvas everytime I append a element so I 
thought of not using the UpdateManager but generating the document, 
registering listeners and then when all of that is finished display the 
document in the canvas and let the listeners do the event handling.

> 
>> }
>>
>> //then set the Canvas to display doc
>> canvas.setSVGDocument(doc);
> 
> 
>    Why are you resetting the document?  If doc is the document
> read from URI then all your modifications are already being tracked.
> When you add an element it is added to the rendering tree, etc.

OK but I would have to use the UpdateManager to be thread safe. In my 
case there is no need to track the changes live, I only need to see the 
final result.

> 
>> I think calling setSVGDocument() after I've created the document 
>> "offline" isn't the right way but how can I use the updateManager to 
>> replace the whole document in the Canvas with the new one?
> 
> 
>    The whole idea of the updateManager is that it tracks the changes
> to the document as you make them.  One consequence of this
> is that it can be faster to make all your changes up front rather
> than have them tracked 'live'.

So this means if I use the invokeLater() from the UpdateManager it's 
slower than directly modifying the document. As I mentioned before there 
is no need to immediately see the changes in the canvas as they are made.
But somehow this interferes with Java Scripting and Event handling.


-- 
Reinhard Brandstaedter   r.brandstaedter@gmx.at  GPG: 0x033B81DB
-    Student of Computer Science - J.K. University of Linz     -
-        <ICQ: 73059068>    <Mobile: +43 699 12419541>         -
-                  http://adelaide.dnsalias.net                -


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


Mime
View raw message