Search in sources :

Example 1 with SVGHandlerListener

use of org.csstudio.utility.batik.SVGHandlerListener 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

BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 SAXSVGDocumentFactory (org.apache.batik.anim.dom.SAXSVGDocumentFactory)1 SVGHandler (org.csstudio.utility.batik.SVGHandler)1 SVGHandlerListener (org.csstudio.utility.batik.SVGHandlerListener)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 Image (org.eclipse.swt.graphics.Image)1 SVGDocument (org.w3c.dom.svg.SVGDocument)1