Christian,
The main problem I've had with this approach had nothing to do with
Batik. Obviously, (in hindsight) if you change the color attributes on
a <g/> element and some (all) of the enclosed elements have color
attributes (or styles) of their own, the change will have no effect.
But, in case it will help, here's some selected code.
First some background:
I'm displaying an SVG file and receiving updates from another thread.
These updates may change colors, etc.
The functionality is split across two classes, one contains the update
information and 'knows' how to apply the change to an element. The
relevant method is:
/** Update the colors on the specified discrete point */
private void updateColors( Element use )
{
String color = getFillColor();
String stroke = getStrokeColor();
if(null != color)
use.setAttributeNS( null, "fill", color );
if(null != stroke)
use.setAttributeNS( null, "stroke", stroke );
}
Another class contains a list of these UpdateEvents and interacts
with the canvas. The three relevant methods are:
/** Submit an update event to the queue.
*
* @param upd update request to queue
*
*/
public synchronized void submitUpdateEvent(UpdateEvent upd)
{
boolean mustLaunch = ((changeList_.size() == 0) || (null ==
runQueue_));
changeList_.add( upd );
try
{
if(null == runQueue_)
runQueue_ =
canvas_.getUpdateManager().getUpdateRunnableQueue();
// Only add to RunQueue if I'm not already there.
if(mustLaunch)
runQueue_.invokeLater( this );
} // if UpdateManager fails, ignore. We'll reattempt later.
catch(Exception ignore) { }
}
/** apply all currently queued changes */
synchronized void applyChanges()
{
Document doc = canvas_.getSVGDocument();
while(!changeList_.isEmpty())
{
UpdateEvent upd = (UpdateEvent)changeList_.remove( 0 );
upd.applyChange( doc );
}
}
/** This method is called when the <code>DisplayUpdater</code> can
apply
* changes to the SVG display.
* <p>The method applies all outstanding changes and then
returns.</p>
* <p>
* The general contract of the method <code>run</code> is that it
may
* take any action whatsoever.
*
* @see java.lang.Thread#run()
*
*/
public void run()
{
try
{
if(canChange())
applyChanges();
} catch(Exception ex)
{
ex.printStackTrace();
}
}
HTH,
G. Wade
Christian Enklaar wrote:
>
> Hi !
>
> Can you send me a copy of your code ?
> Might help me to find what I am doing wrong ...
>
> Greetings,
> Christian.
>
> > -----Urspr�ngliche Nachricht-----
> > Von: G. Wade Johnson [mailto:[EMAIL PROTECTED]
> > Gesendet: Freitag, 21. M�rz 2003 14:52
> > An: Batik Users
> > Betreff: Re: AW: Dynamic DOM updates
> >
> >
> > I regularly modify 'stroke' and 'fill' dynamically without
> > any problems.
> >
> > G. Wade
> >
> > josh wrote:
> > >
> > > At 11:17 AM 3/20/2003, I wrote:
> > >
> > > > Are there only certain attributes that are
> > > >changeable
> > >
> > > This seems to be the case. Altering the 'transform'
> > attribute works, but
> > > style, fill, stroke, d, and a few others I've tried don't.
> > >
> > > Is there a list of the supported attributes somewhere?
> > >
> > > - josh
> > >
> > >
> > ---------------------------------------------------------------------
> > > 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]
> >
>
> ---------------------------------------------------------------------
> 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]