xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathan wood <jonathanshaww...@gmail.com>
Subject Re: How to use org.apache.batik.bridge.UpdateManager?
Date Sun, 25 Apr 2010 13:38:33 GMT
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.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
            public void gvtBuildCompleted(GVTTreeBuilderEvent e) {

Runnable() {
                    public void run() {
                        Element rect =
SVGConstants.SVG_X_ATTRIBUTE, "100");
SVGConstants.SVG_Y_ATTRIBUTE, "100");
SVGConstants.SVG_FILL_ATTRIBUTE, "#2222ee");

        Document doc =
"svg", null);
        svgCanvas.setSVGDocument((SVGDocument) doc);

On Sun, Apr 25, 2010 at 1:23 AM, Rishabh Rao <rishabhsrao@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-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

View raw message