use of org.eclipse.draw2d.SWTGraphics in project dbeaver by serge-rider.
the class GraphicsToGraphics2DAdaptor method createSWTGraphics.
/**
* This is a helper method used to create the SWT Graphics object
*/
private void createSWTGraphics() {
// we need this temp Rect just to instantiate an swt image in order to
// keep state, the size of this Rect is of no consequence and we just set it
// to such a small size in order to minimize memory allocation
org.eclipse.swt.graphics.Rectangle tempRect = new org.eclipse.swt.graphics.Rectangle(0, 0, 10, 10);
image = new Image(Display.getCurrent(), tempRect);
GC gc = new GC(image);
swtGraphics = new SWTGraphics(gc);
}
use of org.eclipse.draw2d.SWTGraphics in project dbeaver by dbeaver.
the class GraphicsToGraphics2DAdaptor method createSWTGraphics.
/**
* This is a helper method used to create the SWT Graphics object
*/
private void createSWTGraphics() {
// we need this temp Rect just to instantiate an swt image in order to
// keep state, the size of this Rect is of no consequence and we just set it
// to such a small size in order to minimize memory allocation
org.eclipse.swt.graphics.Rectangle tempRect = new org.eclipse.swt.graphics.Rectangle(0, 0, 10, 10);
image = new Image(Display.getCurrent(), tempRect);
GC gc = new GC(image);
swtGraphics = new SWTGraphics(gc);
}
use of org.eclipse.draw2d.SWTGraphics in project jbosstools-hibernate by jbosstools.
the class ExportImageAction method createImage.
/**
* Returns the bytes of an encoded image for the specified
* IFigure in the specified format.
*
* @param figure the Figure to create an image for.
* @param format one of SWT.IMAGE_BMP, SWT.IMAGE_BMP_RLE, SWT.IMAGE_GIF
* SWT.IMAGE_ICO, SWT.IMAGE_JPEG, or SWT.IMAGE_PNG
* @return the bytes of an encoded image for the specified Figure
*/
private byte[] createImage(IFigure figure, int format) {
// Device device = getDiagramViewer().getEditPartViewer().getControl()
// .getDisplay();
Device device = null;
Rectangle r = figure.getBounds();
ByteArrayOutputStream result = new ByteArrayOutputStream();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new Image(device, 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);
} catch (Throwable e) {
// $NON-NLS-1$
HibernateConsolePlugin.getDefault().logErrorMessage("ExportImageAction - save:", e);
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
}
return result.toByteArray();
}
Aggregations