Search in sources :

Example 6 with SWTGraphics

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

Example 7 with SWTGraphics

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();
}
Also used : Graphics(org.eclipse.draw2d.Graphics) SWTGraphics(org.eclipse.draw2d.SWTGraphics) SWTGraphics(org.eclipse.draw2d.SWTGraphics) 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)

Example 8 with SWTGraphics

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;
}
Also used : Graphics(org.eclipse.draw2d.Graphics) SWTGraphics(org.eclipse.draw2d.SWTGraphics) SWTGraphics(org.eclipse.draw2d.SWTGraphics) FreeformViewport(org.eclipse.draw2d.FreeformViewport) IProcess2(org.talend.core.model.process.IProcess2) Point(org.eclipse.draw2d.geometry.Point) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) LayerManager(org.eclipse.gef.editparts.LayerManager) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Example 9 with SWTGraphics

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

Example 10 with SWTGraphics

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;
}
Also used : SWTGraphics(org.eclipse.draw2d.SWTGraphics) Graphics(org.eclipse.draw2d.Graphics) SWTGraphics(org.eclipse.draw2d.SWTGraphics) Dimension(org.eclipse.draw2d.geometry.Dimension) NetworkMapDCIImage(org.netxms.client.maps.elements.NetworkMapDCIImage) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) IFigure(org.eclipse.draw2d.IFigure)

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