Gerdes,
I have attached a sample that does what you are asking for. As you
guessed, you do not have to stream out the document before viewing
it: it can be done directly.
Cheers,
Vincent.
Gerdes Kim wrote:
>
> hi there,
>
> there is something basic i didn't get on SVGGraphics2D:
>
> i would like to create an svg and show it in a JSVGCanvas. this must
> be easy but it just doesn't work :-(
>
> looking at the first example on
> http://xml.apache.org/batik/svggen.html, i don't understand what the
> Document document is good for. the streaming is done directly from the
> SVGGraphics2D svgGenerator
>
> if i look at the document, it remained an empty svg-document.
>
> if i use the trick i found in the mailing list:
>
> document.removeChild(document.getDocumentElement());
> document.appendChild(treeManager.getRoot());
>
> i can get some elements in the documents, but it doesn't show when i
> put the document into the JSVGCanvas by canvas
> canvas.setSVGDocument(document);
> and moreover, manipulating the document in this way has the side
> effect of emptying the SVGGraphics2D svgGenerator: all graphic parts i
> just drew in the svgGenerator are cut away when streaming out the
> svgGenerator.
>
> it can't be that i have to stream out and into a new svg document, can
> it?
>
> if someone could just give me the probably 3 lines of code of making
> an SVGDocument and showing it in the canvas, i'd be really very
> grateful!
>
> thanks in advance
>
> kim
> --------------------------------------------------
> Oreka ! Nous sommes l'internet moins cher !
> Surfez 25% moins cher avec http://www.oreka.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
import org.apache.batik.swing.*;
import org.apache.batik.svggen.*;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.w3c.dom.*;
import org.w3c.dom.svg.*;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class ShowGraphics2DOutput {
public static void main(String args[]) throws Exception {
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
SVGDocument doc = (SVGDocument)impl.createDocument(svgNS, "svg", null);
SVGGraphics2D g = new SVGGraphics2D(doc);
Shape circle = new Ellipse2D.Double(0,0,50,50);
g.setPaint(Color.red);
g.fill(circle);
g.translate(60,0);
g.setPaint(Color.green);
g.fill(circle);
g.translate(60,0);
g.setPaint(Color.blue);
g.fill(circle);
g.setSVGCanvasSize(new Dimension(180,50));
Element root = doc.getDocumentElement();
// The following populates the document root with the
// generated SVG content.
g.getRoot(root);
// Now, display the document
JSVGCanvas canvas = new JSVGCanvas();
JFrame f = new JFrame();
f.getContentPane().add(canvas);
canvas.setSVGDocument(doc);
f.pack();
f.setVisible(true);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]