Search in sources :

Example 11 with SwtUniversalImage

use of org.pentaho.di.core.SwtUniversalImage in project pentaho-kettle by pentaho.

the class SwtSvgImageUtil method getUniversalImage.

/**
 * Load image from several sources.
 */
public static SwtUniversalImage getUniversalImage(Display display, ClassLoader classLoader, String filename) {
    if (StringUtils.isBlank(filename)) {
        log.logError("Unable to load image [" + filename + "]");
        return getImageAsResource(display, NO_IMAGE);
    }
    SwtUniversalImage result = null;
    if (SvgSupport.isSvgEnabled()) {
        result = getUniversalImageInternal(display, classLoader, SvgSupport.toSvgName(filename));
    }
    // if we haven't loaded SVG attempt to use PNG
    if (result == null) {
        result = getUniversalImageInternal(display, classLoader, SvgSupport.toPngName(filename));
    }
    // if we can't load PNG, use default "no_image" graphic
    if (result == null) {
        log.logError("Unable to load image [" + filename + "]");
        result = getImageAsResource(display, NO_IMAGE);
    }
    return result;
}
Also used : SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage)

Example 12 with SwtUniversalImage

use of org.pentaho.di.core.SwtUniversalImage in project pentaho-kettle by pentaho.

the class SwtSvgImageUtil method getImageAsResource.

/**
 * Load image from several sources.
 */
public static SwtUniversalImage getImageAsResource(Display display, String location) {
    SwtUniversalImage result = null;
    if (result == null && SvgSupport.isSvgEnabled()) {
        result = getImageAsResourceInternal(display, SvgSupport.toSvgName(location));
    }
    if (result == null) {
        result = getImageAsResourceInternal(display, SvgSupport.toPngName(location));
    }
    if (result == null && !location.equals(NO_IMAGE)) {
        log.logError("Unable to load image [" + location + "]");
        result = getImageAsResource(display, NO_IMAGE);
    }
    if (result == null) {
        log.logError("Unable to load image [" + location + "]");
        result = getMissingImage(display);
    }
    return result;
}
Also used : SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage)

Example 13 with SwtUniversalImage

use of org.pentaho.di.core.SwtUniversalImage in project pentaho-kettle by pentaho.

the class SwtSvgImageUtil method getMissingImage.

/**
 * Get the image for when all other fallbacks have failed.  This is an image
 * drawn on the canvas, a square with a red X.
 *
 * @param display the device to render the image to
 * @return the missing image
 */
public static SwtUniversalImage getMissingImage(Display display) {
    Image img = new Image(display, ConstUI.ICON_SIZE, ConstUI.ICON_SIZE);
    GC gc = new GC(img);
    gc.setForeground(new Color(display, 0, 0, 0));
    gc.drawRectangle(4, 4, ConstUI.ICON_SIZE - 8, ConstUI.ICON_SIZE - 8);
    gc.setForeground(new Color(display, 255, 0, 0));
    gc.drawLine(4, 4, ConstUI.ICON_SIZE - 4, ConstUI.ICON_SIZE - 4);
    gc.drawLine(ConstUI.ICON_SIZE - 4, 4, 4, ConstUI.ICON_SIZE - 4);
    gc.dispose();
    return new SwtUniversalImageBitmap(img);
}
Also used : Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage) GC(org.eclipse.swt.graphics.GC) SwtUniversalImageBitmap(org.pentaho.di.core.SwtUniversalImageBitmap)

Example 14 with SwtUniversalImage

use of org.pentaho.di.core.SwtUniversalImage in project pentaho-kettle by pentaho.

the class KettleImageUtil method loadImages.

/**
 * Load multiple images from svg, or just png file.
 */
public static Image[] loadImages(XulDomContainer container, Shell shell, String resource) {
    Display d = shell.getDisplay();
    if (d == null) {
        d = Display.getCurrent() != null ? Display.getCurrent() : Display.getDefault();
    }
    if (SvgSupport.isSvgEnabled() && (SvgSupport.isSvgName(resource) || SvgSupport.isPngName(resource))) {
        InputStream in = null;
        try {
            in = getResourceInputStream(resource, container);
            // getResourceInputStream( SvgSupport.toSvgName( resource ) );
            // load SVG
            SvgImage svg = SvgSupport.loadSvgImage(in);
            SwtUniversalImage image = new SwtUniversalImageSvg(svg);
            Image[] result = new Image[IMAGE_SIZES.length];
            for (int i = 0; i < IMAGE_SIZES.length; i++) {
                result[i] = image.getAsBitmapForSize(d, IMAGE_SIZES[i], IMAGE_SIZES[i]);
            }
            return result;
        } catch (Throwable ignored) {
            // any exception will result in falling back to PNG
            ignored.printStackTrace();
        } finally {
            IOUtils.closeQuietly(in);
        }
        resource = SvgSupport.toPngName(resource);
    }
    InputStream in = null;
    try {
        in = getResourceInputStream(resource, container);
        return new Image[] { new Image(d, in) };
    } catch (Throwable ignored) {
    // any exception will result in falling back to PNG
    } finally {
        IOUtils.closeQuietly(in);
    }
    return null;
}
Also used : InputStream(java.io.InputStream) SwtUniversalImageSvg(org.pentaho.di.core.SwtUniversalImageSvg) SvgImage(org.pentaho.di.core.svg.SvgImage) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage) Image(org.eclipse.swt.graphics.Image) SvgImage(org.pentaho.di.core.svg.SvgImage) Display(org.eclipse.swt.widgets.Display) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage)

Aggregations

SwtUniversalImage (org.pentaho.di.core.SwtUniversalImage)14 Image (org.eclipse.swt.graphics.Image)11 Display (org.eclipse.swt.widgets.Display)3 BufferedImage (java.awt.image.BufferedImage)2 InputStream (java.io.InputStream)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 SwtUniversalImageSvg (org.pentaho.di.core.SwtUniversalImageSvg)2 Point (org.pentaho.di.core.gui.Point)2 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 SvgImage (org.pentaho.di.core.svg.SvgImage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Color (org.eclipse.swt.graphics.Color)1 GC (org.eclipse.swt.graphics.GC)1 ImageLoader (org.eclipse.swt.graphics.ImageLoader)1 Point (org.eclipse.swt.graphics.Point)1 SwtUniversalImageBitmap (org.pentaho.di.core.SwtUniversalImageBitmap)1