I have a small program that demonstrates a problem with JSVGComponent. I run an infinite loop that alternates the loading of two SVG docs. After running for a while, a race condition appears to cause one of the documents to get "stuck" in the canvas; subsequent calls to setSVGDocument seem to have no effect. The canvas seems "alive" insofar as responding to window resizes/redraws, but the setSVGDocument never seems to have any effect. I suspect that a thread is starving in a RunnableQueue somewhere. Perhaps this has something to do with it:
http://koala.ilog.fr/batik/mlists/batik-dev/archives/msg03651.html
?
I've attached the sample program. You might need to adjust the argument to sleep for your platform. The 400 works for me on my Linux box.
Thanks for your attention.
-- George Armhold Rutgers University eLearning Grant, DCIS
import java.awt.*; import javax.swing.*; import java.io.*;
import org.w3c.dom.svg.*;
import org.apache.batik.swing.svg.*;
import org.apache.batik.dom.svg.*;
import org.apache.batik.util.XMLResourceDescriptor;
/**
* Demonstrate a race condition in RunnableQueue/JSVGComponent.
* Alternate two SVG documents in the JSVGComponent. After a few
* iterations, we seem to get "stuck" on one of the docs.
*/
public class CanvasTest extends JFrame {
private JSVGComponent canvas;
public CanvasTest() {
// allocate canvas
canvas = new JSVGComponent(null, true, false);
canvas.setDocumentState(JSVGComponent.ALWAYS_DYNAMIC);
// allocate an XML parser
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory svgFactory = new SAXSVGDocumentFactory(parser);
getContentPane().add(canvas);
}
public Dimension getPreferredSize() {
return new Dimension(600, 500);
}
public void loadSlide(final SVGDocument doc) {
if (! SwingUtilities.isEventDispatchThread())
throw new IllegalStateException("Must be running in Swing thread.");
System.err.println("loadSlide: " + doc.getURL());
canvas.setSVGDocument(doc);
}
public static void main(final String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: java CanvasTest file1.svg file2.svg");
System.exit(1);
}
final CanvasTest frame = new CanvasTest();
frame.pack();
frame.setVisible(true);
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory svgFactory = new SAXSVGDocumentFactory(parser);
// parse 2 SVG documents and alternate them in the JSVGComponent
File f1 = new File(args[0]);
File f2 = new File(args[1]);
final SVGDocument doc1 =
(SVGDocument) svgFactory.createDocument(f1.toURL().toString());
final SVGDocument doc2 =
(SVGDocument) svgFactory.createDocument(f2.toURL().toString());
// start with doc1
SVGDocument doc = doc1;
// let it spin
while (true) {
final SVGDocument finalDoc = doc;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
frame.loadSlide(finalDoc);
}
});
// switch between doc1 & doc2
if (doc == doc1)
doc = doc2;
else
doc = doc1;
try {
Thread.sleep(400); // you may need to tune this
} catch (InterruptedException e) {
}
}
}
}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
