use of com.archimatetool.editor.diagram.util.ModelReferencedImage in project archi by archimatetool.
the class HTMLReportExporter method saveImages.
/**
* Save diagram images
*/
private void saveImages(File imagesFolder) {
// Use this to generate unique name for image file
Hashtable<IDiagramModel, String> nameTable = new Hashtable<IDiagramModel, String>();
int nameCount = 1;
for (IDiagramModel dm : fModel.getDiagramModels()) {
ModelReferencedImage geoImage = DiagramUtils.createModelReferencedImage(dm, 1, 10);
Image image = geoImage.getImage();
// Generate file name
String diagramName = dm.getId();
if (StringUtils.isSet(diagramName)) {
// removed this because ids can have hyphens in them (when imported from TOG format)
// Let's hope that ids are filename friendly...
// diagramName = FileUtils.getValidFileName(diagramName);
int j = 2;
// $NON-NLS-1$
String s = diagramName + ".png";
while (nameTable.containsValue(s)) {
// $NON-NLS-1$ //$NON-NLS-2$
s = diagramName + "_" + j++ + ".png";
}
diagramName = s;
} else {
// $NON-NLS-1$//$NON-NLS-2$
diagramName = Messages.HTMLReportExporter_1 + " " + nameCount++ + ".png";
}
nameTable.put(dm, diagramName);
// Get and store the bounds of the top-left element in the figure to act as overall x,y offset
Rectangle bounds = geoImage.getBounds();
// Account for device zoom level
bounds.performScale(ImageFactory.getDeviceZoom() / 100);
diagramBoundsMap.put(dm, bounds);
try {
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { image.getImageData(ImageFactory.getDeviceZoom()) };
File file = new File(imagesFolder, diagramName);
loader.save(file.getAbsolutePath(), SWT.IMAGE_PNG);
} finally {
image.dispose();
}
}
}
Aggregations