final File pngFile = new File(docDir, getParent().getName()+".png");
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
GraphicalViewer viewer = new ScrollingGraphicalViewer();
viewer.setEditPartFactory(new AttackExecutionModelEditPartFactory());
ScalableFreeformRootEditPart rootPart = new ScalableFreeformRootEditPart();
viewer.setRootEditPart(rootPart);
viewer.setContents(getCastedModel().getAeg());
IFigure rootFigure = ((LayerManager)rootPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
Rectangle rootFigureBounds = rootFigure.getBounds();
viewer.createControl(new Shell());
viewer.flush();
Control figureCanvas = viewer.getControl();
// The bounds are (0,0) at this point, so let's change them and see if the rest of the code works...
rootFigureBounds.height = 1000;
rootFigureBounds.width = 1000;
Image img = new Image(Display.getDefault(), rootFigureBounds.width, rootFigureBounds.height);
GC imageGC = new GC(img);
figureCanvas.print(imageGC);
ImageLoader imgLoader = new ImageLoader();
imgLoader.data = "" ImageData[] { img.getImageData() };
imgLoader.save(pngFile.getAbsolutePath(), SWT.IMAGE_PNG);
}
});
I get a 1000x1000 white PNG file out of it. Any suggestions would be VERY welcome. I've run out of ideas at this point.
Forti et Fordeli nihil difficile – Nothing is difficult to the brave and faithful.