xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Grant Mc Auley" <gmcau...@som.llu.edu>
Subject Dynamic JSVGCanvas Updates
Date Fri, 08 Aug 2003 19:21:53 GMT
Hello,

My simple test program (relevant code below) loads an SVG file into a
JSVGCanvas.  Clicking a button calls a method that iteratively resizes a
circle in the SVG document.

What I am observing is this:
1) After clicking the toolbar button, I do not see the circle resize
unless I move my mouse into the canvas.
2) Further, unless I continually move my mouse over the canvas I do not
see the iterative resizing.  That is, when I continuously move the
mouse, I see the circle change size every second.  When I stop, the
circle size does not change.  When I move again, I see the updates.  If
I move outside of the canvas I see no updates.

How are canvas updates related to mouse position and movement?  Is there
something else that I must do to see live or dynamic canvas updates?


// ------- Code:

JSVGCanvas canvas = new JSVGCanvas();
File f = new File(shapes.svg");
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
Document doc = factory.createDocument(f.toURL().toString());
canvas.setDocument(doc);
canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);

...

button.addActionListener(new ActionListener() {

  public void actionPerformed(ActionEvent e) {
    Thread t = new Thread(new Runnable() {
      public void run() {
        resizeCircle();
      }
    });
    t.start();
  }

});

...

private void resizeCircle() throws DOMException {

  SVGDocument doc = canvas.getSVGDocument();
  Element el = doc.getElementById("circleOne");
  for (int i = 0; i < 10; i++) {

    if (el.getAttribute("r").equals("20")) { // initial value of r
(radius) is 20
      el.setAttribute("r", "50");
    else
      el.setAttribute("r", "20");
    try {
      Thread.sleep(1000);
    }
    catch (InterruptedException ex) {
    }

  }

}
// -------


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


Mime
View raw message