Hello Jonathan, Thank you for your reply! We understood a lot of things by examining your code snippet.
Also, this book (http://www.sundraw.ws/batik.jsp) is an excellent resource for newbies learning Batik. We learnt a lot from this book too! Also, guess what, we were able to update our canvas display without using UpdateManager! Actually, in our main project, we've created a class that extends SwingWorker (our backend processing is a tad bit time consuming, so we're scheduling it on a SwingWorker thread.) So now, we've overridden the SwingWorker.done method to our advantage! We're calling the JSVGCanvas object's setSVGDocument method in the above done method. So we can be sure that the SVGDocument is populated. For a more in-depth look, please have a look at our project at http://kenai.com/projects/chartglazer. The file ChartGlazerGUI.java is located in the edu.jss.ise.chartglazer.ui package. I hope this is the correct approach. Please correct us if we are wrong. Thank you once again! Best regards, Rishabh Rao, Narendra G S and Praveen K S On 4/25/10, jonathan wood <jonathanshaww...@gmail.com> wrote: > Hello Rishabh, Narendra and Praveen, > > A couple of observations: > > You really have no context in which to manipulate the DOM until the > document is loaded. Your best bet is to add a GVTTreeBuilderListener. > Also, it is much easier to work directly with the DOM objects and let the > GVT take care of rendering the 2D. > Red the attached snippet carefully...the listener code is invoked after > the document is loaded. > > private void runDemo() { > svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); > svgCanvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() { > @Override > public void gvtBuildCompleted(GVTTreeBuilderEvent e) { > > svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new > Runnable() { > public void run() { > Element rect = > svgCanvas.getSVGDocument().createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, > SVGConstants.SVG_RECT_TAG); > rect.setAttributeNS(null, > SVGConstants.SVG_X_ATTRIBUTE, "100"); > rect.setAttributeNS(null, > SVGConstants.SVG_Y_ATTRIBUTE, "100"); > rect.setAttributeNS(null, > SVGConstants.SVG_WIDTH_ATTRIBUTE, "100"); > rect.setAttributeNS(null, > SVGConstants.SVG_HEIGHT_ATTRIBUTE, "100"); > rect.setAttributeNS(null, > SVGConstants.SVG_FILL_ATTRIBUTE, "#2222ee"); > > svgCanvas.getSVGDocument().getDocumentElement().appendChild(rect); > } > }); > } > }); > Document doc = > SVGDOMImplementation.getDOMImplementation().createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, > "svg", null); > svgCanvas.setSVGDocument((SVGDocument) doc); > } > > > On Sun, Apr 25, 2010 at 1:23 AM, Rishabh Rao <rishabhs...@gmail.com> wrote: > >> Hello! >> We are a team 3 students who are developing an opensource application >> called Chart Glazer. The application helps the users draw charts (process >> diagrams, organization charts etc.) easily. It is very much similar to >> Microsoft Office 2007's SmartArt. >> We're using Apache Batik and Java Swing for our development. Our project >> is >> hosted at http://kenai.com/projects/chartglazer. >> The FAQ at http://xmlgraphics.apache.org/batik/faq.html talks about using >> the UpdateManager. >> We are facing the exact same problem, as in section 3.3 of the FAQ, "When >> I >> change the document in Java it only updates if I move the mouse over the >> canvas?" >> We have reproduced our problem into a smaller application (called >> SVGApplication), using NetBeans. It has a JButton (called >> loadDocumentJButton) and a JSVGCanvas (called myJSVGCanvas) present inside >> a >> JScrollPane object. >> Our requirement is that when we click this "loadDocumentJButton" button, >> the the "myJSVGCanvas" object must display the "myRectangle" (see code >> below.) >> Here is the "actionPerformed" event handler for "loadDocumentJButton"... >> private void loadDocumentJButtonActionPerformed(java.awt.event.ActionEvent >> evt) >> { >> DOMImplementation myDOMImplementation = >> SVGDOMImplementation.getDOMImplementation(); >> Document myDocument = >> myDOMImplementation.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, >> "svg", null); >> Element svgRoot = myDocument.getDocumentElement(); >> >> SVGGraphics2D mySVGGraphics2D = new SVGGraphics2D(myDocument); >> mySVGGraphics2D.setSVGCanvasSize(new Dimension(320, 240)); >> >> myJSVGCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); >> myJSVGCanvas.setDocument(myDocument); >> >> Rectangle myRectangle = new Rectangle(10, 10, 60, 40); >> >> mySVGGraphics2D.draw(myRectangle); >> >> svgRoot.appendChild(mySVGGraphics2D.getRoot()); >> } >> The rectangle is being displayed only when we move the mouse over the >> "myJSVGCanvas" object in the Swing GUI window. >> >> We understand that we must use UpdateManager to solve this problem. But we >> don't know how to use it. We searched a lot on the Internet and >> mail-archives, but we are not able to figure things out. We did not find >> any >> example programs. If we get an example program that demonstrates the use >> of >> UpdateManager, we will figure it out on our own. It would be great if you >> provide us with such an example program. >> Please help us. >> We are attaching the 3 files of "SVGApplication" (created usingNetBeans) >> for your reference. The above event handler function is located in the >> SVGView.java. Probably, the other two files will not be required; we have >> just attached it for completeness' sake. >> Thank you very much! >> Regards, >> Rishabh Rao, Narendra G S and Praveen K S >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org >> For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org >> > --------------------------------------------------------------------- To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org