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 Ben Drees <be...@apmindsf.com> on 2003/05/23 19:28:22 UTC

changing element href doesn't result in repaint

Hi,

We are seeking a workaround for this problem:

- Our app is an interactive graph editor

- We use Batik's JSVGCanvas to render a document in dynamic mode

- There is a DOM <use> element with an "href" attribute pointing to a
<g> element in the <defs> section of an external document sitting in the
filesystem

- When we change that "href" attribute to point to a different <g>
element in that same external document, the JSVGCanvas does not get
repainted

Other attribute changes result in appropriate repainting, so I think our
basic wiring is correct.

Is this a known bug, or is it the specified behavior?

Is there a way to force a repaint of the affected screen bounds?

Thanks,
Ben

-- 
Ben Drees <be...@apmindsf.com>


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


Re: changing element href doesn't result in repaint

Posted by William Billingsley <wh...@cam.ac.uk>.
[snipped messages from Thomas and Vincent about why DOM updates must be on the 
UpdateManager thread]`

Great, thanks very much for those replies; they were very informative.

cheers,
Will.

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


Re: changing element href doesn't result in repaint

Posted by Vincent Hardy <vi...@sun.com>.
Hi William,

William Billingsley wrote:

>>    Since you go into great detail but fail to mention making the
>>change in the UpdateManger's thread I suspect that you need to make
>>your change in the Update Manager's thread.  Search the archives this
>>is a very common problem for people modifying the DOM from Java.
>>
>>    
>>
>
>Out of interest, are there any design documents indicating why this was 
>designed to be the case?  
>When I started with Batik, I naturally expected that the DOM update functions 
>as implemented in Batik would be synchronised/atomic, and would [as the last 
>thing they do] create an event that the UpdateManager would respond to -- 
>with the idea that DOM updates could happen anywhere, rather than solely from 
>the UpdateManager thread.  [or as an alternative, that the internals of the 
>SVGOMElement would perform the thread switching].  I was quite surprised to 
>find that switching to UpdateManager thread is necessary -- it seems to be an 
>unusual level of detail for an external system using a Batik JSVGCanvas to 
>need to know.
>  
>
Actually, this is not unusual. If you look at the Java plug-in 
specification, you'll see there is a similar mechanism to update the 
DOM. I also know of another example in the TV space where DOM access is 
synchronized in a similar way. One advantage of using the UpdateManager 
is that you can group together your updates and have them executed 
serially rather than synchronizing on every single DOM call.

Vincent.




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


Re: changing element href doesn't result in repaint

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "WB" == William Billingsley <wh...@cam.ac.uk> writes:

>>  Since you go into great detail but fail to mention making the
>> change in the UpdateManger's thread I suspect that you need to make
>> your change in the Update Manager's thread.  Search the archives
>> this is a very common problem for people modifying the DOM from
>> Java.
>> 

WB> Out of interest, are there any design documents indicating why
WB> this was designed to be the case?  When I started with Batik, I
WB> naturally expected that the DOM update functions as implemented in
WB> Batik would be synchronised/atomic, and would [as the last thing
WB> they do] create an event that the UpdateManager would respond to
WB> -- with the idea that DOM updates could happen anywhere, rather
WB> than solely from the UpdateManager thread.

    The problem is that most DOM interaction involves a long series of
DOM calls to get one thing done (take for instance creating a
rectangle - createElementNS, 5x setAttribute, then appendElement). If
these are not synchronized as a group bad things can happen (for
example your parent element may change), another good example is a DOM
walk (getNextSibling).  

    In other words synchronizing 'setAttribute' is not nearly enough
you need to synchronize a block of user code and make that atomic.

WB> [or as an alternative, that the internals of the SVGOMElement
WB> would perform the thread switching].  I was quite surprised to
WB> find that switching to UpdateManager thread is necessary -- it
WB> seems to be an unusual level of detail for an external system
WB> using a Batik JSVGCanvas to need to know.

    Swing has exactly the same requirement, you don't notice it so
much since your event handlers get called back in the Swing event
thread (and BTW likewise DOM callbacks get called in the UpdateManger
thread).

    It would be possible to add a checker thread that peeks a the GVT
tree to see if it has changed and if so add an update runnable, but
all this would do is encourage 'bad behavior'.

    It would have been possible to use the Swing thread for this but
since rendering also requires the DOM to be locked your Swing GUI
would 'lockup' when ever the SVG document was rendering.

    Does this make it clear why we force you to take such care?


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


Re: changing element href doesn't result in repaint

Posted by William Billingsley <wh...@cam.ac.uk>.
>
>     Since you go into great detail but fail to mention making the
> change in the UpdateManger's thread I suspect that you need to make
> your change in the Update Manager's thread.  Search the archives this
> is a very common problem for people modifying the DOM from Java.
>

Out of interest, are there any design documents indicating why this was 
designed to be the case?  
When I started with Batik, I naturally expected that the DOM update functions 
as implemented in Batik would be synchronised/atomic, and would [as the last 
thing they do] create an event that the UpdateManager would respond to -- 
with the idea that DOM updates could happen anywhere, rather than solely from 
the UpdateManager thread.  [or as an alternative, that the internals of the 
SVGOMElement would perform the thread switching].  I was quite surprised to 
find that switching to UpdateManager thread is necessary -- it seems to be an 
unusual level of detail for an external system using a Batik JSVGCanvas to 
need to know.

cheers,
Will.


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


RE: changing element href doesn't result in repaint

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "BD" == Ben Drees <be...@apmindsf.com> writes:

BD> Hi, We are seeking a workaround for this problem:

    I assume we are talking about one of the Batik 1.5 beta's?

BD> - Our app is an interactive graph editor

BD> - We use Batik's JSVGCanvas to render a document in dynamic mode

BD> - There is a DOM <use> element with an "href" attribute pointing
BD> to a <g> element in the <defs> section of an external document
BD> sitting in the filesystem

BD> - When we change that "href" attribute to point to a different <g>
BD> element in that same external document, the JSVGCanvas does not
BD> get repainted

BD> Other attribute changes result in appropriate repainting, so I
BD> think our basic wiring is correct.

    Since you go into great detail but fail to mention making the
change in the UpdateManger's thread I suspect that you need to make
your change in the Update Manager's thread.  Search the archives this
is a very common problem for people modifying the DOM from Java.


BD> Is this a known bug, or is it the specified behavior?

    I don't think it is a known bug (although it's possible that the
'use' element doesn't support dyanmic update of the href (in which
case you can always force it by removing the use element and adding it
back in, at the same place).

BD> Is there a way to force a repaint of the affected screen bounds?

    Yes, but I don't think you want to go there :) Also since the
problem is almost certainly the updating of the rendering tree (GVT)
from the DOM tree forcing a repaint wouldn't help.


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