Search in sources :

Example 1 with Graphics

use of org.eclipse.draw2d.Graphics 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 2 with Graphics

use of org.eclipse.draw2d.Graphics 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 3 with Graphics

use of org.eclipse.draw2d.Graphics in project tdi-studio-se by Talend.

the class TalendDrawerFigure method createHoverHelp.

protected void createHoverHelp(final Control control) {
    if (control == null) {
        return;
    }
    // If a control was provided, create the tipLabel -- if the text in the
    // header is
    // truncated, it will display it as a tooltip.
    tipLabel = new Label() {

        /**
             * @see org.eclipse.draw2d.Figure#getToolTip()
             */
        @Override
        public IFigure getToolTip() {
            return buildTooltip();
        }

        @Override
        protected void paintFigure(Graphics graphics) {
            Rectangle r = Rectangle.SINGLETON;
            r.setBounds(getBounds());
            graphics.pushState();
            paintToggleGradient(graphics, getBounds());
            graphics.popState();
            super.paintFigure(graphics);
        }
    };
    tipLabel.setOpaque(false);
    tipLabel.setBorder(TOOLTIP_BORDER);
    try {
        Field tipLabelField = DrawerFigure.class.getDeclaredField("tipLabel");
        tipLabelField.setAccessible(true);
        tipLabelField.set(this, tipLabel);
    } catch (Exception e) {
        CommonExceptionHandler.process(e);
    }
    collapseToggle.addMouseMotionListener(new MouseMotionListener.Stub() {

        @Override
        public void mouseMoved(MouseEvent e) {
            if (!talendDrawerLabel.getBounds().contains(e.getLocation())) {
                return;
            }
            if (skipNextEvent) {
                skipNextEvent = false;
                return;
            }
            if (talendDrawerLabel.isTextTruncated() && !TalendEditPartTipHelper.isCurrent(tipHelper)) {
                tipLabel.setText(talendDrawerLabel.getText());
                tipLabel.setIcon(talendDrawerLabel.getIcon());
                tipLabel.setFont(talendDrawerLabel.getFont());
                tipHelper = new TalendEditPartTipHelper(control);
                Rectangle bounds = talendDrawerLabel.getBounds().getExpanded(2, 2);
                talendDrawerLabel.translateToAbsolute(bounds);
                org.eclipse.swt.graphics.Rectangle loc = new org.eclipse.swt.graphics.Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                loc = Display.getCurrent().map(control, null, loc);
                tipHelper.displayToolTipAt(tipLabel, loc.x, loc.y);
            }
        }
    });
    tipLabel.addMouseListener(new MouseListener.Stub() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.button == 1) {
                Rectangle original = getCollapseToggle().getBounds().getCopy();
                getCollapseToggle().requestFocus();
                setExpanded(!isExpanded());
                // toggle to move
                if (!original.equals(getCollapseToggle().getBounds())) {
                    tipHelper.hide();
                }
            } else {
                tipHelper.hide();
                if (e.button == 3) {
                    skipNextEvent = true;
                }
            }
        }
    });
}
Also used : MouseEvent(org.eclipse.draw2d.MouseEvent) Label(org.eclipse.draw2d.Label) Rectangle(org.eclipse.draw2d.geometry.Rectangle) MouseMotionListener(org.eclipse.draw2d.MouseMotionListener) Graphics(org.eclipse.draw2d.Graphics) Field(java.lang.reflect.Field) MouseListener(org.eclipse.draw2d.MouseListener) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

Graphics (org.eclipse.draw2d.Graphics)3 IFigure (org.eclipse.draw2d.IFigure)2 SWTGraphics (org.eclipse.draw2d.SWTGraphics)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 GC (org.eclipse.swt.graphics.GC)2 Image (org.eclipse.swt.graphics.Image)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Field (java.lang.reflect.Field)1 FreeformViewport (org.eclipse.draw2d.FreeformViewport)1 Label (org.eclipse.draw2d.Label)1 MouseEvent (org.eclipse.draw2d.MouseEvent)1 MouseListener (org.eclipse.draw2d.MouseListener)1 MouseMotionListener (org.eclipse.draw2d.MouseMotionListener)1 Point (org.eclipse.draw2d.geometry.Point)1 LayerManager (org.eclipse.gef.editparts.LayerManager)1 ImageLoader (org.eclipse.swt.graphics.ImageLoader)1 IProcess2 (org.talend.core.model.process.IProcess2)1