Hi Danh!

I tried this and it works fine, just don't forget to do:

JSVGCanvas canvas = new JSVGCanvas();
canvas.setDocumentState( JSVGComponent.ALWAYS_DYNAMIC );

When a change occurres some code piece( it's ugly, I know ;-) ):

final String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
final SVGDocument sd = canvas.getSVGDocument();
final org.w3c.dom.Element root = sd.getDocumentElement();
final int centx = x + (width/2);
final int centy = y + (height/2);
final int wd = width;
final int hg = height;
final org.w3c.dom.Element e = sd.createElementNS(svgNS, "ellipse");

UpdateManager um = canvas.getUpdateManager();
RunnableQueue rq = um.getUpdateRunnableQueue();
rq.invokeLater(new Runnable() {
        public void run()
        {
        e.setAttributeNS( null, "cx", new Integer( centx ).toString() );
        e.setAttributeNS( null, "cy", new Integer( centy ).toString() );
        e.setAttributeNS( null, "rx", new Integer( wd/2 ).toString() );
        e.setAttributeNS( null, "ry", new Integer( hg/2 ).toString() );
        e.setAttributeNS( null, "stroke", "red" );
        e.setAttributeNS( null, "stroke-width", "2px" );
        e.setAttributeNS( null, "style", "fill:none"  );
        root.appendChild( e );
        }
});

rq.invokeLater(new Runnable() {
        public void run()
        {
        e.setAttributeNS( null, "stroke", "blue" );
        }
});

This example shows a circle being drawn and appended to the root of the 
doc. After that the stroke attribute is set. In practice this results 
into a red circle being painted and very quickly after that it turns to 
blue.

I also tried: e.setAttribute( style", "blue" ). This works fine too.

invokeAndWait, lets my app hang (why?).

About GVT: What I know is that the GVT tree is build (and changed) 
according to the DOMtree. The GVT tree is therefor not to be changed; I 
assume you don't want to interfere with the way the SVG xml is rendered?

Maybe use java140 + Batik CVS.

Good luck and happy codin',

Michael.


Danh Hoai wrote:
> I tried to do the following with no success (no visible change to
> JSVGcanvas):
>      rq.invokeLater(new Runnable()
>      {
>         public void run()
>         {
>            elem1.setAttribute("style","fill:red;display:inline;opacity:2;");
>         }
>      });
> 
> I also tried invokeAndWait but I got an error:
> java.lang.IllegalStateException: cannot be called  from RunnableQueue thread
> 
> 
> Another related (may be unrelated) question--do we need to mess with GVT to
> change DOM?
> 
> 
> 
> ----- Original Message -----
> From: "Thomas E Deweese" <[EMAIL PROTECTED]>
> To: "Batik Users" <[EMAIL PROTECTED]>; "Danh Hoai"
> <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Monday, May 06, 2002 12:31 PM
> Subject: repaint
> 
> 
> 
>>>>>>>"DH" == Danh Hoai <[EMAIL PROTECTED]> writes:
>>>>>>
>>DH> We are running into a similar problem.  Can you elaborate on how
>>DH> you got your case to work.
>>
>>>>JSVGCanvas canvas = ...
>>>>canvas.setDocumentState(JSVGCanvs.ALWAYS_DYNAMIC);
>>>>
>>>>import org.apache.batik.bridge.UpdateManager; import
>>>>org.apache.batik.util.RunnableQueue;
>>>>
>>>>UpdateManager um = canvas.getUpdateManager(); RunnableQueue rq =
>>>>um.getUpdateRunnableQueue(); rq.invokeLater(new Runnable() { public
>>>>void run() { /*...*/ } }); rq.invokeAndWait(new Runnable() { public
>>>>void run() { /*...*/ } });
>>>
>>
>>DH> Specifically, where do you make the change to DOM.  Is it done
>>DH> inside the run()
>>
>>    Yes you make your changes inside the run method of the
>>runnable you pass to either invokeLater or invokeAndWait.
>>
>>
>>>>rq.invokeLater(new Runnable() { public void run() { /*...*/ } });
>>>>rq.invokeAndWait(new Runnable() { public void run() { /*...*/ } });
>>>
>>DH> Do we need to invoke both methods?
>>
>>    No, pick one.
>>
>>DH> Also, how do methods invokeAndWait and invokeLater work? do they
>>DH> invoke after the change inside the DOM?
>>
>>    InvokeAndWait will not return until the change has been made in
>>the DOM.  InvokeLater will return 'immediately' usually before your
>>change as been made to the DOM (this of course is left to the vagures
>>of thread scheduling in the JDK).
>>
>>---------------------------------------------------------------------
>>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]

Reply via email to