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);
}
}
Aggregations