Search in sources :

Example 6 with SVGDocument

use of org.w3c.dom.svg.SVGDocument in project yamcs-studio by yamcs.

the class SVGSymbolImage method loadDocument.

private void loadDocument(final InputStream inputStream) {
    svgHandler = null;
    failedToLoadDocument = true;
    if (imagePath == null || imagePath.isEmpty()) {
        return;
    }
    String parser = XMLResourceDescriptor.getXMLParserClassName();
    SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parser);
    try {
        // $NON-NLS-1$
        IPath workSpacePath = ResourceUtil.workspacePathToSysPath(new Path("/"));
        String uri = // $NON-NLS-1$
        "file://" + (workSpacePath == null ? "" : workSpacePath.toOSString()) + imagePath.toString();
        svgDocument = factory.createDocument(uri, inputStream);
        svgHandler = new SVGHandler((SVGDocument) svgDocument, Display.getCurrent());
        svgHandler.setAlignedToNearestSecond(alignedToNearestSecond);
        initRenderingHints();
        BufferedImage awtImage = svgHandler.getOffScreen();
        if (awtImage != null) {
            this.originalImageData = SVGUtils.toSWT(Display.getCurrent(), awtImage);
            resetData();
        }
        svgHandler.setRenderListener(new SVGHandlerListener() {

            @Override
            public void newImage(final Image image) {
                if (disposed) {
                    return;
                }
                animatedImage = image;
                repaintAnimated = true;
                repaint();
            }
        });
        needRender = true;
        failedToLoadDocument = false;
    } catch (Exception e) {
        Activator.getLogger().log(Level.WARNING, "Error loading SVG image " + imagePath, e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) SVGHandler(org.csstudio.utility.batik.SVGHandler) IPath(org.eclipse.core.runtime.IPath) SAXSVGDocumentFactory(org.apache.batik.anim.dom.SAXSVGDocumentFactory) SVGDocument(org.w3c.dom.svg.SVGDocument) BufferedImage(java.awt.image.BufferedImage) Image(org.eclipse.swt.graphics.Image) SVGHandlerListener(org.csstudio.utility.batik.SVGHandlerListener) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException)

Aggregations

SVGDocument (org.w3c.dom.svg.SVGDocument)6 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 SAXSVGDocumentFactory (org.apache.batik.dom.svg.SAXSVGDocumentFactory)2 SVGDocumentFactory (org.apache.batik.dom.svg.SVGDocumentFactory)2 GraphicsNode (org.apache.batik.gvt.GraphicsNode)2 DOMImplementation (org.w3c.dom.DOMImplementation)2 Document (org.w3c.dom.Document)2 Dimension (java.awt.Dimension)1 BufferedImage (java.awt.image.BufferedImage)1 JFrame (javax.swing.JFrame)1 SAXSVGDocumentFactory (org.apache.batik.anim.dom.SAXSVGDocumentFactory)1 SVGDOMImplementation (org.apache.batik.anim.dom.SVGDOMImplementation)1 SVGOMDocument (org.apache.batik.anim.dom.SVGOMDocument)1 BridgeContext (org.apache.batik.bridge.BridgeContext)1 DocumentLoader (org.apache.batik.bridge.DocumentLoader)1 GVTBuilder (org.apache.batik.bridge.GVTBuilder)1 UserAgent (org.apache.batik.bridge.UserAgent)1 UserAgentAdapter (org.apache.batik.bridge.UserAgentAdapter)1 CSSStyleSheetNode (org.apache.batik.css.engine.CSSStyleSheetNode)1