First of all, I suggest use String.valueOf(int) instead of new Integer(int).toString , 
you create 2 instances and only nedd one instance of a string.

next: use the methode e.setAttributeNS(null, "x", String.valueOf(x));

The updateManager will be automaticly instanciated. The problem is to find the right 
moment when this manager becomes ready to use.

In the class where you hold and use your canvas you must register a lot of listeners...

That a methode from my MainFrame (extends JFrame). 
canvas is a subclass from JSVGCanvas
I set any messages in a status bar.

---------------------------------

        private void registerSVGListeners() {

                //  Set the JSVGCanvas listeners.
                canvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
            
                        public void documentLoadingStarted(SVGDocumentLoaderEvent e) {
                                statusBar.message.setText("Document Loading...");
                        }
            
                        public void documentLoadingCompleted(SVGDocumentLoaderEvent e) 
{
                                statusBar.message.setText("Document Loaded.");
                        }
                });

                canvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
            
                        public void gvtBuildStarted(GVTTreeBuilderEvent e) {
                                statusBar.message.setText("Build Started...");
                        }
            
                        public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
                                statusBar.message.setText("Build Done.");
                                domPanel.refresh();
                        }
                });

                canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
            
                        public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
                                statusBar.message.setText("Rendering Started...");
                        }
            
                        public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
                                statusBar.message.setText("Ready.");
                        }
                });

        }

---------------------------------------
I think the in gvtBuildCompleted you will find the correct moment to have an instance 
from updateManager. You can see her I prepare a JTree model to diplay the DOM tree. I 
you want to be absolute shure than use gvtRenderingCompleted.

Jan


-----Urspr�ngliche Nachricht-----
Von: Reinhard Brandst�dter [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 12. Juni 2003 15:35
An: Batik Users
Betreff: getting Update Manager for JSVGCanvas...


Jan suggested updating a SVGDocument displayed in a JSVGCanvas via the 
UpdateManager, but now I'm struggling with getting the UpdateManager for 
my canvas.

I'm new to Batik and just playing around a little bit, but the Javadoc 
isn't very helpful...

How do I create a UpdateManager so that I can use it in the way 
described by Jan below?

I tried something (useless as the UpdateManager returned is null) like this:
This test should only "move" the rectangle "myrect" accross the canvas (?)
------
svgCanvas.setSVGDocument(svgDoc);
svgCanvas.getUpdateManager(). \\
getUpdateRunnableQueue().invokeLater(new Runnable() {
   public void run() {
     int x=0, y=0;
     for (;;) {
       x = (x+1)%400;
       y = (y+1)%400;
       Element e = svgDoc.getElementById("myrect");
       e.setAttribute("x",(new Integer(x)).toString());
       e.setAttribute("y",(new Integer(y)).toString());
     }
   }
}
);
------

thx,
Reinhard

Lolling, Jan wrote:
> OK now it is clear.
> 
> BATIK is the right think to solve your task.
> 
> Than all comments from Vincent are correct and the best way to create and remove 
> elements is manipulating the DOM in the update manager.
> 
> You can retrieve this from JSVGCanvas methode 
> getUpdateManager().getUpdateRunnableQueue().invokeLater(yourDOMUpdateRunnable);
> 
> here is an code snippet---------------
> 
>                 canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new 
> Runnable() {
>                     public void run() {
>                         Element rectangle = document.createElementNS(svgNS, "rect");
>                         rectangle.setAttributeNS(null, "x", String.valueOf(x));
>                         rectangle.setAttributeNS(null, "y", String.valueOf(y));
>                         rectangle.setAttributeNS(null, "width", String.valueOf(ddx));
>                         rectangle.setAttributeNS(null, "height", 
> String.valueOf(ddy));
>                         rectangle.setAttributeNS(null, "style", "fill:white; 
> stroke:black");
>                         svgRoot.appendChild(rectangle);
>                     } //run
>                 });
> 
> ---------------------------------


-- 
Reinhard Brandstaedter   [EMAIL PROTECTED]  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: [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