Search in sources :

Example 56 with ImageData

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

the class CTable method initImages.

static void initImages(final Display display) {
    PaletteData arrowPalette = new PaletteData(new RGB(0, 0, 0), new RGB(255, 255, 255));
    if (display.getData(ID_ARROWDOWN) == null) {
        ImageData arrowDown = new ImageData(7, 4, 1, arrowPalette, 1, new byte[] { 0x00, (byte) 0x83, (byte) 0xC7, (byte) 0xEF });
        arrowDown.transparentPixel = 0x1;
        /* use white for transparency */
        display.setData(ID_ARROWDOWN, new Image(display, arrowDown));
    }
    if (display.getData(ID_ARROWUP) == null) {
        ImageData arrowUp = new ImageData(7, 4, 1, arrowPalette, 1, new byte[] { (byte) 0xEF, (byte) 0xC7, (byte) 0x83, 0x00 });
        arrowUp.transparentPixel = 0x1;
        /* use white for transparency */
        display.setData(ID_ARROWUP, new Image(display, arrowUp));
    }
    PaletteData checkMarkPalette = new PaletteData(new RGB(0, 0, 0), new RGB(252, 3, 251));
    byte[] checkbox = new byte[] { 0, 0, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 127, -64, 0, 0 };
    ImageData checkmark = new ImageData(7, 7, 1, checkMarkPalette, 1, new byte[] { -4, -8, 112, 34, 6, -114, -34 });
    checkmark.transparentPixel = 1;
    if (display.getData(ID_CHECKMARK) == null) {
        display.setData(ID_CHECKMARK, new Image(display, checkmark));
    }
    if (display.getData(ID_UNCHECKED) == null) {
        PaletteData uncheckedPalette = new PaletteData(new RGB(128, 128, 128), new RGB(255, 255, 255));
        ImageData unchecked = new ImageData(11, 11, 1, uncheckedPalette, 2, checkbox);
        display.setData(ID_UNCHECKED, new Image(display, unchecked));
    }
    if (display.getData(ID_GRAYUNCHECKED) == null) {
        PaletteData grayUncheckedPalette = new PaletteData(new RGB(128, 128, 128), new RGB(192, 192, 192));
        ImageData grayUnchecked = new ImageData(11, 11, 1, grayUncheckedPalette, 2, checkbox);
        display.setData(ID_GRAYUNCHECKED, new Image(display, grayUnchecked));
    }
    display.disposeExec(() -> {
        Image unchecked = (Image) display.getData(ID_UNCHECKED);
        if (unchecked != null)
            unchecked.dispose();
        Image grayUnchecked = (Image) display.getData(ID_GRAYUNCHECKED);
        if (grayUnchecked != null)
            grayUnchecked.dispose();
        Image checkmark1 = (Image) display.getData(ID_CHECKMARK);
        if (checkmark1 != null)
            checkmark1.dispose();
        Image arrowDown = (Image) display.getData(ID_ARROWDOWN);
        if (arrowDown != null)
            arrowDown.dispose();
        Image arrowUp = (Image) display.getData(ID_ARROWUP);
        if (arrowUp != null)
            arrowUp.dispose();
        display.setData(ID_UNCHECKED, null);
        display.setData(ID_GRAYUNCHECKED, null);
        display.setData(ID_CHECKMARK, null);
        display.setData(ID_ARROWDOWN, null);
        display.setData(ID_ARROWUP, null);
    });
}
Also used : PaletteData(org.eclipse.swt.graphics.PaletteData) ImageData(org.eclipse.swt.graphics.ImageData) RGB(org.eclipse.swt.graphics.RGB) Image(org.eclipse.swt.graphics.Image)

Example 57 with ImageData

use of org.eclipse.swt.graphics.ImageData in project yamcs-studio by yamcs.

the class SWTResourceManager method getImage.

/**
 * Returns an {@link Image} encoded by the specified {@link InputStream}.
 *
 * @param stream
 *            the {@link InputStream} encoding the image data
 * @return the {@link Image} encoded by the specified input stream
 */
protected static Image getImage(InputStream stream) throws IOException {
    try {
        Display display = Display.getCurrent();
        ImageData data = new ImageData(stream);
        if (data.transparentPixel > 0) {
            return new Image(display, data, data.getTransparencyMask());
        }
        return new Image(display, data);
    } finally {
        stream.close();
    }
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image) Display(org.eclipse.swt.widgets.Display)

Example 58 with ImageData

use of org.eclipse.swt.graphics.ImageData in project yamcs-studio by yamcs.

the class AnimatedSVGCache method addImage.

public Image addImage(BufferedImage awtImage) {
    if (filled) {
        return null;
    }
    if (entries.size() == maxSize) {
        flush();
    }
    Image image = null;
    long currentWaitTime = Long.MAX_VALUE;
    if (!initialized) {
        // Initialize
        for (TimedElement te : timedDocumentRoot.getChildren()) {
            timeHandlers.put(te, new TimedElementHandler(te));
        }
        entries.clear();
        filled = false;
        repeatCount = 0;
        initialized = true;
    } else {
        // Compare time of each element with previous call
        for (TimedElement te : timedDocumentRoot.getChildren()) {
            if (timeHandlers.get(te) != null && timeHandlers.get(te).update(te) && timeHandlers.get(te).getWaitTime() < currentWaitTime) {
                // Take the minimum
                currentWaitTime = timeHandlers.get(te).getWaitTime();
            }
        }
        // Check if all images have been cached
        filled = hasRepeated();
        // Avoid first repeat
        if (filled && repeatCount == 0) {
            repeatCount++;
            // Reset time counters
            timeHandlers.clear();
            for (TimedElement te : timedDocumentRoot.getChildren()) {
                timeHandlers.put(te, new TimedElementHandler(te));
            }
            filled = false;
        }
    }
    if (filled) {
        // End of the loop, back to first image
        entries.get(0).setWaitTime(currentWaitTime);
        return entries.get(0).getImage();
    }
    ImageData imageData = SVGUtils.toSWT(swtDisplay, awtImage);
    image = new Image(swtDisplay, imageData);
    // Avoid first repeat
    if (repeatCount == 0) {
        return image;
    }
    entries.add(new Entry(currentWaitTime, image));
    return image;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) TimedElement(org.apache.batik.anim.timing.TimedElement) BufferedImage(java.awt.image.BufferedImage) Image(org.eclipse.swt.graphics.Image)

Example 59 with ImageData

use of org.eclipse.swt.graphics.ImageData in project yamcs-studio by yamcs.

the class FilePathDialogWithFilter method displayOverview.

private void displayOverview(IPath imgPath) {
    if (imgPath == null || imgPath.isEmpty())
        return;
    try {
        ImageData data = null;
        if (GIF_EXT.equalsIgnoreCase(imgPath.getFileExtension()) || PNG_EXT.equalsIgnoreCase(imgPath.getFileExtension())) {
            final InputStream inputStream = ResourceUtil.pathToInputStream(imgPath);
            ImageData tmpData = new ImageData(inputStream);
            float ratio = (float) tmpData.width / tmpData.height;
            if (ratio >= 1 && tmpData.width > MAX_ICON_WIDTH) {
                float ratio2 = (float) MAX_ICON_WIDTH / tmpData.width;
                data = tmpData.scaledTo(MAX_ICON_WIDTH, Math.round((float) tmpData.height * ratio2));
            } else if (ratio < 1 && tmpData.height > MAX_ICON_HEIGHT) {
                float ratio2 = (float) MAX_ICON_HEIGHT / tmpData.height;
                data = tmpData.scaledTo(Math.round((float) tmpData.width * ratio2), MAX_ICON_HEIGHT);
            } else {
                data = tmpData;
            }
        } else if (SVG_EXT.equalsIgnoreCase(imgPath.getFileExtension())) {
            final InputStream inputStream = ResourceUtil.pathToInputStream(imgPath);
            data = SVGUtils.loadSVG(imgPath, inputStream, MAX_ICON_WIDTH, MAX_ICON_HEIGHT);
        }
        if (data != null && data.width <= MAX_ICON_WIDTH && data.height <= MAX_ICON_HEIGHT && imgOverview != null) {
            Image img = new Image(Display.getCurrent(), data);
            imgOverview.setImage(img);
        }
    } catch (Exception e) {
        OPIBuilderPlugin.getLogger().log(Level.WARNING, "Error loading file overview: " + imgPath, e);
    }
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) InputStream(java.io.InputStream) Image(org.eclipse.swt.graphics.Image)

Example 60 with ImageData

use of org.eclipse.swt.graphics.ImageData in project yamcs-studio by yamcs.

the class GIFSymbolImage method syncLoadImage.

// ************************************************************
// Image loading
// ************************************************************
@Override
public void syncLoadImage() {
    if (imagePath == null)
        return;
    loadingImage = true;
    if (animated) {
        stopAnimation();
        showIndex = 0;
        animationIndex = 0;
    }
    InputStream stream = null;
    Image tempImage = null;
    try {
        stream = ResourceUtil.pathToInputStream(imagePath.toPortableString());
        ImageData[] dataArray = loader.load(stream);
        if (dataArray == null || dataArray.length < 1)
            return;
        originalImageDataArray = dataArray;
        originalImageData = originalImageDataArray[0];
        animated = originalImageDataArray.length > 1;
    } catch (Exception e) {
        Activator.getLogger().log(Level.WARNING, "ERROR in loading PNG image " + imagePath, e);
    } finally {
        try {
            if (stream != null)
                stream.close();
            if (tempImage != null && !tempImage.isDisposed())
                tempImage.dispose();
        } catch (IOException e) {
            Activator.getLogger().log(Level.WARNING, "ERROR in closing GIF image stream ", e);
        }
    }
    loadingImage = false;
    resetData();
    if (animated)
        startAnimation();
}
Also used : InputStream(java.io.InputStream) ImageData(org.eclipse.swt.graphics.ImageData) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) IOException(java.io.IOException)

Aggregations

ImageData (org.eclipse.swt.graphics.ImageData)132 Image (org.eclipse.swt.graphics.Image)78 PaletteData (org.eclipse.swt.graphics.PaletteData)38 RGB (org.eclipse.swt.graphics.RGB)33 Point (org.eclipse.swt.graphics.Point)32 Test (org.junit.Test)26 InputStream (java.io.InputStream)24 GC (org.eclipse.swt.graphics.GC)19 IOException (java.io.IOException)18 SWTException (org.eclipse.swt.SWTException)14 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)13 Rectangle (org.eclipse.swt.graphics.Rectangle)12 Color (org.eclipse.swt.graphics.Color)11 ImageLoader (org.eclipse.swt.graphics.ImageLoader)11 Display (org.eclipse.swt.widgets.Display)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Cursor (org.eclipse.swt.graphics.Cursor)7 Composite (org.eclipse.swt.widgets.Composite)7 GradientPaint (java.awt.GradientPaint)5 URL (java.net.URL)5