Search in sources :

Example 1 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class WindowsImageTransfer method nativeToJava.

protected Object nativeToJava(TransferData transferData) {
    final Object o = super.nativeToJava(transferData);
    final byte[] bytes = (byte[]) o;
    try {
        final InputStream bis = new PrependWinBMPHeaderFilterInputStream(new UncompressDibFilterInputStream(new ByteArrayInputStream(bytes)));
        final ImageData[] data = new ImageLoader().load(bis);
        if (data.length < 1) {
            return null;
        }
        return data[0];
    } catch (IOException e) {
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ImageData(org.eclipse.swt.graphics.ImageData) IOException(java.io.IOException) ImageLoader(org.eclipse.swt.graphics.ImageLoader)

Example 2 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class WindowsImageTransfer method javaToNative.

protected void javaToNative(Object object, TransferData transferData) {
    final ImageData imgData = (ImageData) object;
    final ImageLoader loader = new ImageLoader();
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final byte[] bytes;
    loader.data = new ImageData[] { imgData };
    loader.save(new RemoveWinBMPHeaderFilterOutputStream(bos), SWT.IMAGE_BMP);
    bytes = bos.toByteArray();
    super.javaToNative(bytes, transferData);
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageLoader(org.eclipse.swt.graphics.ImageLoader)

Example 3 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class GraphicalWidgetBase method regenerateCaches.

protected void regenerateCaches(final int width, final int height) {
    // For performance reasons, we defer regeneration until we exit fast mode
    if (!this.fast) {
        if (View.isDrawingOK()) {
            // Recompute the cached data in the background
            //            new Thread () {
            //                public void run() {
            boolean needsRepaint = false;
            // Recompute the midground cache if it is dirty
            if (cachedMidgroundDirty) {
                needsRepaint = true;
                if ((width == 0) || (height == 0)) {
                    throw new IllegalArgumentException("Width or Height on a widget is 0. This " + "should have been prevented in setShape " + "Size");
                }
                // Create a temporary canvas on which to draw the midground
                Image img = new Image(null, width, height);
                GC gc = new GC(img);
                SWTGraphics g = new SWTGraphics(gc);
                g.setAntialias(SWT.OFF);
                // Use the renderer & clipper to paint the midground nicely
                g.setBackgroundColor(getSelectionColor());
                renderer.paintMidground(g);
                //      value.
                if (OSUtils.WINDOWS) {
                    ImageData id = img.getImageData();
                    id.alpha = displayAlpha.determineAlpha(false);
                    img.dispose();
                    img = new Image(null, id);
                }
                // WARNING: this might dispose img, or it might return it
                // DO NOT DISPOSE img!
                Image newFG = clipper.clip(img);
                // Clean the cache
                cachedMidgroundDirty = false;
                cachedMidground.dispose();
                cachedMidground = newFG;
                //                            cachedMidgroundData = newFG.getImageData();
                // Dispose of temporary resources
                //                            newFG.dispose();
                g.dispose();
                gc.dispose();
            }
            // Recompute the background cache if it is dirty
            if (cachedBackgroundDirty) {
                needsRepaint = true;
                Image newBG = null;
                // Check if background is present
                byte[] bgImageData = model.getImage();
                if (bgImageData != null) {
                    ImageData bg = new ImageData(new ByteArrayInputStream(bgImageData));
                    newBG = clipper.clip(new Image(null, bg.scaledTo(width, height)));
                }
                // Clean the cache
                cachedBackgroundDirty = false;
                if (cachedBackground != null) {
                    cachedBackground.dispose();
                }
                cachedBackground = newBG;
            }
            // Make sure the results of our update are shown
            if (needsRepaint && View.isDrawingOK()) {
                //                        WindowUtil.globalDisplay.syncExec(
                //                            new Runnable() {
                //                                public void run() {
                repaint();
            //                                 }
            //                            }
            //                        );
            }
        //                }
        //            }.start();
        }
    }
}
Also used : SWTGraphics(org.eclipse.draw2d.SWTGraphics) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 4 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class GraphicalWidgetBase method updateImage.

public synchronized void updateImage() {
    // Mark the caches as dirty so that no one will use them
    synchronized (this.flagLock) {
        this.cachedBackgroundDirty = true;
    }
    // Confirm that the image is readable (throws an exception if it is not)
    if (model.getImage() != null) {
        new ImageData(new ByteArrayInputStream(model.getImage()));
    }
    this.renderer.updateData();
    regenerateCaches();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData)

Example 5 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class WindowUtil method getOpenHandCursor.

/**
     * Returns a hand cursor.
     *
     * IMPORTANT: this cursor must be disposed when its creator is disposed,
     *            or we will have a memory link.
     *
     * @return a hew hand cursor
     */
public static Cursor getOpenHandCursor() {
    if (OPEN_HAND_CURSOR == null) {
        ImageData curData = GraphicsUtil.getImageDataFromResource("edu/cmu/cs/hcii/cogtool/resources/open_hand.gif");
        if (curData == null) {
            return null;
        }
        OPEN_HAND_CURSOR = new Cursor(GLOBAL_DISPLAY, curData, 8, 8);
    }
    return OPEN_HAND_CURSOR;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Cursor(org.eclipse.swt.graphics.Cursor)

Aggregations

ImageData (org.eclipse.swt.graphics.ImageData)54 Image (org.eclipse.swt.graphics.Image)29 Point (org.eclipse.swt.graphics.Point)15 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 GC (org.eclipse.swt.graphics.GC)7 ImageLoader (org.eclipse.swt.graphics.ImageLoader)7 Display (org.eclipse.swt.widgets.Display)6 Composite (org.eclipse.swt.widgets.Composite)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 PaletteData (org.eclipse.swt.graphics.PaletteData)3 RGB (org.eclipse.swt.graphics.RGB)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Event (org.eclipse.swt.widgets.Event)3 FileDialog (org.eclipse.swt.widgets.FileDialog)3 Listener (org.eclipse.swt.widgets.Listener)3 EImage (org.talend.commons.ui.runtime.image.EImage)3 IImage (org.talend.commons.ui.runtime.image.IImage)3