Search in sources :

Example 1 with SwtUniversalImage

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

the class KettleXulLoader method getResourceAsStream.

@Override
public InputStream getResourceAsStream(String resource) {
    int height = iconHeight;
    int width = iconWidth;
    if (resource.contains(":")) {
        // we have height/width overrides
        width = Integer.parseInt(resource.substring(resource.indexOf(":") + 1, resource.indexOf("#")));
        height = Integer.parseInt(resource.substring(resource.indexOf("#") + 1, resource.indexOf(".")));
        resource = resource.substring(0, resource.indexOf(":")) + resource.substring(resource.indexOf("."));
    }
    if (SvgSupport.isSvgEnabled() && (SvgSupport.isSvgName(resource) || SvgSupport.isPngName(resource))) {
        InputStream in = null;
        try {
            in = super.getResourceAsStream(SvgSupport.toSvgName(resource));
            // load SVG
            SvgImage svg = SvgSupport.loadSvgImage(in);
            SwtUniversalImage image = new SwtUniversalImageSvg(svg);
            Display d = Display.getCurrent() != null ? Display.getCurrent() : Display.getDefault();
            // write to png
            Image result = image.getAsBitmapForSize(d, width, height);
            ImageLoader loader = new ImageLoader();
            loader.data = new ImageData[] { result.getImageData() };
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            loader.save(out, SWT.IMAGE_PNG);
            image.dispose();
            return new ByteArrayInputStream(out.toByteArray());
        } catch (Throwable ignored) {
        // any exception will result in falling back to PNG
        } finally {
            IOUtils.closeQuietly(in);
        }
        resource = SvgSupport.toPngName(resource);
    }
    return super.getResourceAsStream(resource);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SwtUniversalImageSvg(org.pentaho.di.core.SwtUniversalImageSvg) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SvgImage(org.pentaho.di.core.svg.SvgImage) Image(org.eclipse.swt.graphics.Image) SvgImage(org.pentaho.di.core.svg.SvgImage) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage) ImageLoader(org.eclipse.swt.graphics.ImageLoader) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage) Display(org.eclipse.swt.widgets.Display)

Example 2 with SwtUniversalImage

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

the class TransGraph method getImageFor.

private Image getImageFor(StreamInterface stream) {
    Display disp = shell.getDisplay();
    SwtUniversalImage swtImage = SWTGC.getNativeImage(BasePainter.getStreamIconImage(stream.getStreamIcon()));
    return swtImage.getAsBitmapForSize(disp, ConstUI.SMALL_ICON_SIZE, ConstUI.SMALL_ICON_SIZE);
}
Also used : Display(org.eclipse.swt.widgets.Display) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage)

Example 3 with SwtUniversalImage

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

the class Splash method loadAsResource.

// load image from svg
private Image loadAsResource(Display display, String location) {
    SwtUniversalImage img = SwtSvgImageUtil.getImageAsResource(display, location);
    Image image = new Image(display, img.getAsBitmap(display), SWT.IMAGE_COPY);
    img.dispose();
    return image;
}
Also used : Image(org.eclipse.swt.graphics.Image) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage)

Example 4 with SwtUniversalImage

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

the class GUIResource method loadJobEntryImages.

/**
 * Load all step images from files.
 */
private void loadJobEntryImages() {
    imagesJobentries = new Hashtable<String, SwtUniversalImage>();
    imagesJobentriesSmall = new Hashtable<String, Image>();
    // //
    // // JOB ENTRY IMAGES TO LOAD
    // //
    PluginRegistry registry = PluginRegistry.getInstance();
    List<PluginInterface> plugins = registry.getPlugins(JobEntryPluginType.class);
    for (int i = 0; i < plugins.size(); i++) {
        PluginInterface plugin = plugins.get(i);
        if ("SPECIAL".equals(plugin.getIds()[0])) {
            continue;
        }
        SwtUniversalImage image = null;
        Image small_image = null;
        String filename = plugin.getImageFile();
        try {
            ClassLoader classLoader = registry.getClassLoader(plugin);
            image = SwtSvgImageUtil.getUniversalImage(display, classLoader, filename);
        } catch (Throwable t) {
            log.logError("Error occurred loading image [" + filename + "] for plugin " + plugin.getIds()[0], t);
        } finally {
            if (image == null) {
                log.logError("Unable to load image [" + filename + "] for plugin " + plugin.getIds()[0]);
                image = SwtSvgImageUtil.getMissingImage(display);
            }
        }
        // 
        if (image != null) {
            small_image = image.getAsBitmapForSize(display, ConstUI.MEDIUM_ICON_SIZE, ConstUI.MEDIUM_ICON_SIZE);
        }
        imagesJobentries.put(plugin.getIds()[0], image);
        imagesJobentriesSmall.put(plugin.getIds()[0], small_image);
    }
}
Also used : PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) Image(org.eclipse.swt.graphics.Image) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage) Point(org.eclipse.swt.graphics.Point) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage)

Example 5 with SwtUniversalImage

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

the class GUIResource method getImage.

/**
 * Loads an image from a location once. The second time, the image comes from a cache. Because of this, it's important
 * to never dispose of the image you get from here. (easy!) The images are automatically disposed when the application
 * ends.
 *
 * @param location the location of the image resource to load
 * @param width    The height to resize the image to
 * @param height   The width to resize the image to
 * @return the loaded image
 */
public Image getImage(String location, int width, int height) {
    Image image = imageMap.get(location);
    if (image == null) {
        SwtUniversalImage svg = SwtSvgImageUtil.getImage(display, location);
        image = new Image(display, svg.getAsBitmapForSize(display, width, height), SWT.IMAGE_COPY);
        svg.dispose();
        imageMap.put(location, image);
    }
    return image;
}
Also used : Image(org.eclipse.swt.graphics.Image) SwtUniversalImage(org.pentaho.di.core.SwtUniversalImage) 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