Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[gef-dev] Trying to export a GEF diagram as a PNG without displaying it

I've been trying to figure out a GEF issue for about a month now and I'm not getting anywhere. I have tried other discussion venues first, but I'm hoping someone here can assist. I have a GEF diagram that I want to save directly to a PNG file. I need to do this without displaying the diagram graphically (actually, it needs to work when the RCP app is running headlessly). 

Here is the code I have so far:

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.

Thanks,
Ken Keefe



--
Forti et Fordeli nihil difficile – Nothing is difficult to the brave and faithful.

Back to the top