use of org.eclipse.draw2d.SWTGraphics in project archi by archimatetool.
the class DiagramUtils method createModelReferencedImage.
private static ModelReferencedImage createModelReferencedImage(IFigure figure, double scale, int margin) {
if (scale <= 0) {
scale = 1;
}
if (scale > 5) {
scale = 5;
}
Rectangle bounds = getMinimumBounds(figure);
if (bounds == null) {
// At least a minimum
bounds = new Rectangle(0, 0, 100, 100);
} else {
bounds.expand(margin / scale, margin / scale);
}
Image image = new Image(Display.getDefault(), (int) (bounds.width * scale), (int) (bounds.height * scale));
GC gc = new GC(image);
SWTGraphics graphics = new SWTGraphics(gc);
// Issue #621: SWTGraphics supports scale() so no need to use ScaledGraphics
if (scale != 1) {
graphics.scale(scale);
}
// Compensate for negative co-ordinates
graphics.translate(bounds.x * -1, bounds.y * -1);
// Paint onto graphics
figure.paint(graphics);
// Dispose
gc.dispose();
graphics.dispose();
return new ModelReferencedImage(image, bounds);
}
use of org.eclipse.draw2d.SWTGraphics in project cubrid-manager by CUBRID.
the class ExportPictureTask method createImage.
private byte[] createImage(IFigure figure, int format) {
Rectangle r = figure.getBounds();
ByteArrayOutputStream result = new ByteArrayOutputStream();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new Image(null, r.width, r.height);
gc = new GC(image);
g = new SWTGraphics(gc);
g.translate(r.x * -1, r.y * -1);
figure.paint(g);
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData() };
imageLoader.save(result, format);
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
}
return result.toByteArray();
}
use of org.eclipse.draw2d.SWTGraphics in project tdi-studio-se by Talend.
the class AbstractTalendEditor method saveOutlinePicture.
/**
* Save the outline picture for this editor.
*
* @param viewer
*/
protected void saveOutlinePicture(ScrollingGraphicalViewer viewer) {
GlobalConstant.generatingScreenShoot = true;
LayerManager layerManager = (LayerManager) viewer.getEditPartRegistry().get(LayerManager.ID);
// save image using swt
// get root figure
IFigure backgroundLayer = layerManager.getLayer(LayerConstants.GRID_LAYER);
IFigure contentLayer = layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);
// create image from root figure
FreeformViewport viewport = (FreeformViewport) ((TalendScalableFreeformRootEditPart) layerManager).getFigure();
viewport.getUpdateManager().performUpdate();
int width = contentLayer.getBounds().width;
int height = contentLayer.getBounds().height;
Image img = new Image(null, width, height);
GC gc = new GC(img);
Graphics graphics = new SWTGraphics(gc);
Point point = contentLayer.getBounds().getTopLeft();
graphics.translate(-point.x, -point.y);
IProcess2 process = getProcess();
process.setPropertyValue(IProcess.SCREEN_OFFSET_X, String.valueOf(-point.x));
process.setPropertyValue(IProcess.SCREEN_OFFSET_Y, String.valueOf(-point.y));
backgroundLayer.paint(graphics);
contentLayer.paint(graphics);
graphics.dispose();
gc.dispose();
process.getScreenshots().put("process", ImageUtils.saveImageToData(img));
img.dispose();
// service.getProxyRepositoryFactory().refreshJobPictureFolder(outlinePicturePath);
GlobalConstant.generatingScreenShoot = false;
}
use of org.eclipse.draw2d.SWTGraphics in project netxms by netxms.
the class BirtChartFigure method takeSnapshot.
/**
* Take snapshot of network map
*
* @return
*/
public Image takeSnapshot() {
Rectangle rect = getClientArea();
Image image = new Image(Display.getCurrent(), rect.width, rect.height);
GC gc = new GC(image);
Graphics g = new SWTGraphics(gc);
paint(g);
g.dispose();
gc.dispose();
return image;
}
use of org.eclipse.draw2d.SWTGraphics in project netxms by netxms.
the class ExtendedGraphViewer method takeSnapshot.
/**
* Take snapshot of network map
*
* @return
*/
public Image takeSnapshot() {
IFigure rootLayer = graph.getRootLayer();
Dimension d = rootLayer.getSize();
Image image = new Image(graph.getDisplay(), d.width, d.height);
GC gc = new GC(image);
Graphics g = new SWTGraphics(gc);
rootLayer.paint(g);
g.dispose();
gc.dispose();
return image;
}
Aggregations