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);
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations