use of org.w3c.dom.svg.SVGDocument in project yamcs-studio by yamcs.
the class SVGHandler method createWrapper.
private Document createWrapper(final SVGDocument doc) {
// creation of the SVG document
String svgNamespace = SVGDOMImplementation.SVG_NAMESPACE_URI;
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
final Document newDocument = impl.createDocument(svgNamespace, "svg", null);
// get the root element
svgRootNode = newDocument.getDocumentElement();
mainGraphicNode = newDocument.createElementNS(svgNamespace, "g");
// attach the root of original doc to transform to the root
Node copiedRoot = newDocument.importNode(doc.getDocumentElement(), true);
mainGraphicNode.appendChild(copiedRoot);
svgRootNode.appendChild(mainGraphicNode);
updateMatrix();
return newDocument;
}
use of org.w3c.dom.svg.SVGDocument in project charts by vaadin.
the class PdfExportDemo method createSVGDocument.
private SVGDocument createSVGDocument(String svg, UserAgent agent) throws IOException {
SVGDocumentFactory documentFactory = new SAXSVGDocumentFactory(agent.getXMLParserClassName(), true);
SVGDocument svgdoc = documentFactory.createSVGDocument(null, new StringReader(svg));
return svgdoc;
}
use of org.w3c.dom.svg.SVGDocument in project charts by vaadin.
the class PdfExportDemo method buildBatikGraphicsNode.
/**
* Use Batik SVG Toolkit to create GraphicsNode for the target SVG.
* <ol>
* <li>Create SVGDocument</li>
* <li>Create BridgeContext</li>
* <li>Build GVT tree. Results to GraphicsNode</li>
* </ol>
*
* @param svg
* SVG as a String
* @return GraphicsNode
* @throws IOException
* Thrown when SVG could not be read properly.
*/
private GraphicsNode buildBatikGraphicsNode(String svg) throws IOException {
UserAgent agent = new UserAgentAdapter();
SVGDocument svgdoc = createSVGDocument(svg, agent);
DocumentLoader loader = new DocumentLoader(agent);
BridgeContext bridgeContext = new BridgeContext(agent, loader);
bridgeContext.setDynamicState(BridgeContext.STATIC);
GVTBuilder builder = new GVTBuilder();
GraphicsNode imageGraphics = builder.build(bridgeContext, svgdoc);
return imageGraphics;
}
use of org.w3c.dom.svg.SVGDocument in project charts by vaadin.
the class SwingDemo method display.
public static void display(Configuration conf) {
String svg = SVGGenerator.getInstance().generate(conf);
String parser = XMLResourceDescriptor.getXMLParserClassName();
SVGDocumentFactory documentFactory = new SAXSVGDocumentFactory(parser, true);
SVGDocument svgdoc;
try {
svgdoc = documentFactory.createSVGDocument(null, new StringReader(svg));
JSVGCanvas jsvgCanvas = new JSVGCanvas();
jsvgCanvas.setSVGDocument(svgdoc);
JFrame f = new JFrame();
f.setSize(600, 400);
f.getContentPane().add(jsvgCanvas);
f.pack();
f.setVisible(true);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.w3c.dom.svg.SVGDocument in project knime-core by knime.
the class HistogramColumn method createSvgImageCell.
/**
* @param histogramData A {@link HistogramModel}.
* @return The SVG image cell.
*/
private DataCell createSvgImageCell(final HistogramModel<?> histogramData, final boolean paintLabels) {
DOMImplementation domImpl = new SVGDOMImplementation();
String svgNS = "http://www.w3.org/2000/svg";
Document myFactory = domImpl.createDocument(svgNS, "svg", null);
SVGGraphics2D g = new SVGGraphics2D(myFactory);
g.setSVGCanvasSize(new Dimension(m_width, m_height));
paint(histogramData, paintLabels, g);
myFactory.replaceChild(g.getRoot(), myFactory.getDocumentElement());
DataCell dc = new SvgCell((SVGDocument) myFactory);
return dc;
}
Aggregations