Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [ZEST] png export
[ZEST] png export [message #1077152] Thu, 01 August 2013 09:58 Go to next message
Low Coupling is currently offline Low Coupling
Messages: 31
Registered: June 2013
Member
I'd like to programmatically create a zest diagram and export it as a png.
I have managed to create the diagram by means of a GraphViewer instance having as composite parent a shell instaniated this way:
 
Shell shell = new Shell(Display.getDefault()); 
 

Note that the graph is not shown.
I can't see now how to export the graph in a png file. Is there any way to do that?


interested on Eclipse, DSL and MDA? Visit http://www.lowcoupling.com

[Updated on: Thu, 01 August 2013 09:59]

Report message to a moderator

Re: [ZEST] png export [message #1077268 is a reply to message #1077152] Thu, 01 August 2013 13:08 Go to previous message
Zoltan Ujhelyi is currently offline Zoltan Ujhelyi
Messages: 215
Registered: July 2009
Senior Member
Hi,

yes, it is possible to export the contents of the graph as a png. See the following snippet (we have used this in the VIATRA2 project in http://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.viatra2/trunk/plugins/org.eclipse.viatra2.visualisation/src/org/eclipse/viatra2/visualisation/ViatraGraphViewer.java); it does not need to be defined inside a GraphViewer, it only needs a reference to the Graph widget.

Graph g = (Graph) getControl();
Rectangle bounds = g.getContents().getBounds();
Point size = new Point(g.getContents().getSize().width, g.getContents()
	.getSize().height);
org.eclipse.draw2d.geometry.Point viewLocation = g.getViewport()
	.getViewLocation();
final Image image = new Image(null, size.x, size.y);
GC gc = new GC(image);
SWTGraphics swtGraphics = new SWTGraphics(gc);

swtGraphics.translate(-1 * bounds.x + viewLocation.x, -1 * bounds.y
	+ viewLocation.y);
g.getViewport().paint(swtGraphics);
gc.copyArea(image, 0, 0);
gc.dispose();
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { image.getImageData() };
loader.save(filename, format);


Hope this helps. Cheers,
Zoltán
Previous Topic:Threading Job issue when Graphical editor has large number of editparts.
Next Topic:Connection bend points and snap to grid
Goto Forum:
  


Current Time: Tue Sep 23 02:37:29 GMT 2014

Powered by FUDForum. Page generated in 0.16628 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software