Search in sources :

Example 1 with ModelReferencedImage

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();
        }
    }
}
Also used : ModelReferencedImage(com.archimatetool.editor.diagram.util.ModelReferencedImage) IDiagramModel(com.archimatetool.model.IDiagramModel) Hashtable(java.util.Hashtable) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ModelReferencedImage(com.archimatetool.editor.diagram.util.ModelReferencedImage) Image(org.eclipse.swt.graphics.Image) ImageLoader(org.eclipse.swt.graphics.ImageLoader) STGroupFile(org.stringtemplate.v4.STGroupFile) File(java.io.File)

Aggregations

ModelReferencedImage (com.archimatetool.editor.diagram.util.ModelReferencedImage)1 IDiagramModel (com.archimatetool.model.IDiagramModel)1 File (java.io.File)1 Hashtable (java.util.Hashtable)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 Image (org.eclipse.swt.graphics.Image)1 ImageLoader (org.eclipse.swt.graphics.ImageLoader)1 STGroupFile (org.stringtemplate.v4.STGroupFile)1