xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: Require repaint in applet to update canvas
Date Wed, 12 Sep 2007 10:45:36 GMT
Hi Noni,

noni_4444 <naveed.0972@gmail.com> wrote on 09/07/2007 03:57:16 PM:

> I have an SVG document containing a rectangle which is to be animated
> repeatedly depending upon a value received in a callback function.
> [..] If i call the repaint method myself inside the callback method,
> i see the canvas flickering.

    Does the shape move?  If not the problem may be that your
code to move the rectangle isn't really moving the rectangle.
In which case the canvas will decide that nothing had changed so
there is nothing to redraw.

>  I have already read a dozen posts on this
> forum related to this and have tried all the suggested solutions. All 
point to
> something like
> 
> "If you set the canvas's document state to JSVGCanvas.ALWAYS_DYNAMIC and 
run
> all your document updates in the UpdateManager, it should update 
itself".
> 
> What to do to update the SVG canvas without calling repaint() ? I am 
already
> following the above guideline.

   Then something must be broken because there is nothing
else to do.  I've looked over your code and nothing really 
obvious jumps out at me, but I have commented on some possible
problem code below.

> Following are relevant portions of my code.
> 
> public class BatikApplet extends Applet {
>         UpdateManager updateManager = null;
> 
>         //Initialize the applet
>         public void init() {
>                 jbInit();
>                 svgCanvas = new JSVGCanvas();
>                 svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
>                 String parser =
> XMLResourceDescriptor.getXMLParserClassName();
>                 docFactory = new SAXSVGDocumentFactory(parser);
>                 rectDoc =
> docFactory.createSVGDocument("http://localhost:8080/"+screenName);
>            registerListeners();
>                 svgCanvas.setDocument(rectDoc);
>                 this.add(svgCanvas, BorderLayout.NORTH);

   This is potentially bad you should add the Canvas pack the
window and then set the Document.  Otherwise there is a chance
that the document will do a wasted rendering at "zero" size.

>                 svgCanvas.repaint();
>           }
> 
>    // Paint method
>         public void paint(Graphics g) {
>               svgCanvas.paintComponent(g);
>         }

     This is probably flailing on your part but I think this
is wrong, since you have added the canvas as a child of the Applet
Swing should ensure that it gets painted.  I'm not sure what the
impact of adding this call would be...


> 
>    // Method which is called repeatedly with updated animation values to 
be
> drawn
>           public synchronized void callback(final String strData) {
>                   runnable = new Runnable() {
>                       public void run() {
>            //Call to external object which changes the SVG document
>                           oAnimEngine.animateScreen(strData); 
>                       }
>                   };
> 
>               try {
> 
> updateManager.getUpdateRunnableQueue().invokeLater(runnable);
>               } catch (Exception ex) {
> 
>               }
>           }
> 
>     // Register listener method
>           public void registerListeners() {
>               svgCanvas.addGVTTreeRendererListener(new
> GVTTreeRendererAdapter() {
>                   public void gvtRenderingCompleted(GVTTreeRendererEvent 
e)
> {
>                       updateManager = svgCanvas.getUpdateManager();
>                       oAnimEngine.setCustomSVGDocument(rectDoc);

    This might be your problem.  You should get the Document from the
Canvas rather than remember the document you passed to the canvas.  In
some cases the canvas has to clone the document passed to it so that it
is using our DOM Implementation.  I would think that your parsing code 
would generate a DOM that passes this test but if not this could explain
your problems (you are changing rectDoc, but the canvas is displaying a
separate document cloned from rectDoc).



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


Mime
View raw message