Hi,
I wish grouped elements "by component".
This code example below generate this svg content
...
<g>
<g style="fill:blue; stroke:blue;">
<circle r="25" style="stroke:none;" cx="25" cy="25"/>
<rect x="0" y="50" width="50" style="fill:lime; stroke:none;"
height="50"/>
</g>
</g>
</svg>
But i would like this (group by component) :
<g>
<g style="fill:blue; stroke:blue;">
<circle r="25" style="stroke:none;" cx="25" cy="25"/>
...
</g>
<g>
<rect x="0" y="50" width="50" style="fill:lime; stroke:none;"
height="50"/>
...
</g>
</g>
I try create a <g> element and call
method getDOMTreeManager().appendGroup(element_g, getDomGroupManager())
but element <g> is simply added, non become parent of future painting
operations of the component.
Is this possible ?
Thanks.
//example
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Graphics2D;
import java.awt.Color;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.GenericDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
class MyForm1 {
public void draw(Graphics2D g) {
g.setColor(Color.BLUE);
g.fillOval(0, 0, 50, 50);
}
}
class MyForm2{
public void draw(Graphics2D g) {
g.setColor(Color.GREEN);
g.fillRect(0, 50, 50, 50);
}
}
public class TestSVGGen {
public static void main(String[] args) throws IOException {
// Get a DOMImplementation.
DOMImplementation domImpl = GenericDOMImplementation
.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
MyForm1 m1 = new MyForm1();
MyForm2 m2 = new MyForm2();
m1.draw(svgGenerator);
m2.draw(svgGenerator);
// Finally, stream out SVG to the standard output using
// UTF-8 encoding.
boolean useCSS = true; // we want to use CSS style attributes
Writer out = new OutputStreamWriter(System.out, "UTF-8");
svgGenerator.stream(out, useCSS);
}
}
--
View this message in context:
http://old.nabble.com/SVGGraphics2D-how-to-group-elements-tp28129357p28129357.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]