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