Search in sources :

Example 16 with SWTGraphics

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);
}
Also used : SWTGraphics(org.eclipse.draw2d.SWTGraphics) Rectangle(org.eclipse.draw2d.geometry.Rectangle) org.eclipse.swt.graphics(org.eclipse.swt.graphics) BufferedImage(java.awt.image.BufferedImage) Image(org.eclipse.swt.graphics.Image)

Example 17 with SWTGraphics

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);
}
Also used : SWTGraphics(org.eclipse.draw2d.SWTGraphics) Rectangle(org.eclipse.draw2d.geometry.Rectangle) org.eclipse.swt.graphics(org.eclipse.swt.graphics) BufferedImage(java.awt.image.BufferedImage) Image(org.eclipse.swt.graphics.Image)

Example 18 with SWTGraphics

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();
}
Also used : SWTGraphics(org.eclipse.draw2d.SWTGraphics) Graphics(org.eclipse.draw2d.Graphics) SWTGraphics(org.eclipse.draw2d.SWTGraphics) Device(org.eclipse.swt.graphics.Device) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) ImageLoader(org.eclipse.swt.graphics.ImageLoader)

Aggregations

SWTGraphics (org.eclipse.draw2d.SWTGraphics)18 Image (org.eclipse.swt.graphics.Image)18 GC (org.eclipse.swt.graphics.GC)16 Rectangle (org.eclipse.draw2d.geometry.Rectangle)12 Graphics (org.eclipse.draw2d.Graphics)10 ImageLoader (org.eclipse.swt.graphics.ImageLoader)6 BufferedImage (java.awt.image.BufferedImage)4 IFigure (org.eclipse.draw2d.IFigure)4 FileOutputStream (java.io.FileOutputStream)3 FreeformLayeredPane (org.eclipse.draw2d.FreeformLayeredPane)3 Dimension (org.eclipse.draw2d.geometry.Dimension)3 ImageData (org.eclipse.swt.graphics.ImageData)3 DBException (org.jkiss.dbeaver.DBException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Point (org.eclipse.draw2d.geometry.Point)2 org.eclipse.swt.graphics (org.eclipse.swt.graphics)2 ArchiLabelProvider (com.archimatetool.editor.ui.ArchiLabelProvider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 FreeformViewport (org.eclipse.draw2d.FreeformViewport)1