use of org.apache.hop.core.SwtUniversalImage in project hop by apache.
the class CanvasFacadeImpl method setDataPipeline.
private void setDataPipeline(Canvas canvas, float magnification, AbstractMeta meta) {
final int iconSize = HopGui.getInstance().getProps().getIconSize();
PipelineMeta pipelineMeta = (PipelineMeta) meta;
JsonObject jsonNodes = new JsonObject();
pipelineMeta.getTransforms().forEach(transformMeta -> {
JsonObject jsonNode = new JsonObject();
jsonNode.add("x", transformMeta.getLocation().x);
jsonNode.add("y", transformMeta.getLocation().y);
jsonNode.add("selected", transformMeta.isSelected());
// Translated from org.apache.hop.ui.hopgui.shared.SwtGc.drawTransformIcon(int, int,
// TransformMeta, float)
SwtUniversalImage swtImage = null;
if (transformMeta.isMissing()) {
swtImage = GuiResource.getInstance().getSwtImageMissing();
} else if (transformMeta.isDeprecated()) {
swtImage = GuiResource.getInstance().getSwtImageDeprecated();
} else {
String pluginId = transformMeta.getPluginId();
if (pluginId != null) {
swtImage = GuiResource.getInstance().getImagesTransforms().get(pluginId);
}
}
if (swtImage == null) {
return;
}
int w = Math.round(iconSize * magnification);
int h = Math.round(iconSize * magnification);
Image image = swtImage.getAsBitmapForSize(Display.getCurrent(), w, h);
// Translated
jsonNode.add("img", image.internalImage.getResourceName());
jsonNodes.add(transformMeta.getName(), jsonNode);
});
canvas.setData("nodes", jsonNodes);
JsonArray jsonHops = new JsonArray();
for (int i = 0; i < pipelineMeta.nrPipelineHops(); i++) {
JsonObject jsonHop = new JsonObject();
PipelineHopMeta hop = pipelineMeta.getPipelineHop(i);
if (hop.getFromTransform() != null && hop.getToTransform() != null) {
jsonHop.add("from", hop.getFromTransform().getName());
jsonHop.add("to", hop.getToTransform().getName());
jsonHops.add(jsonHop);
}
}
canvas.setData("hops", jsonHops);
}
use of org.apache.hop.core.SwtUniversalImage in project hop by apache.
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);
// RAP only allows painting on the Canvas widget
if (!EnvironmentUtils.getInstance().isWeb()) {
GC gc = new GC(img);
gc.setForeground(new Color(display, PropsUi.getInstance().contrastColor(0, 0, 0)));
gc.drawRectangle(4, 4, ConstUi.ICON_SIZE - 8, ConstUi.ICON_SIZE - 8);
gc.setForeground(new Color(display, PropsUi.getInstance().contrastColor(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, zoomFactor);
}
use of org.apache.hop.core.SwtUniversalImage in project hop by apache.
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 classLoader the ClassLoader to use to locate resources
* @param width The height to resize the image to
* @param height The width to resize the image to
* @param disabled in case you want to gray-scaled 'disabled' version of the image
* @return the loaded image
*/
public Image getImage(String location, ClassLoader classLoader, int width, int height, boolean disabled) {
// Build image key for a specific size
StringBuilder builder = new StringBuilder(location);
builder.append('|').append(width).append('|').append(height).append('|').append(disabled);
String key = builder.toString();
Image image = imageMap.get(key);
if (image == null) {
SwtUniversalImage svg = SwtSvgImageUtil.getUniversalImage(display, classLoader, location);
Image zoomedImaged = getZoomedImaged(svg, display, width, height);
if (disabled) {
// First disabled the image...
//
image = new Image(display, zoomedImaged, SWT.IMAGE_GRAY);
// Now darken or lighten the image...
//
float factor;
if (PropsUi.getInstance().isDarkMode()) {
factor = 0.4f;
} else {
factor = 2.5f;
}
ImageData data = image.getImageData();
for (int x = 0; x < data.width; x++) {
for (int y = 0; y < data.height; y++) {
int pixel = data.getPixel(x, y);
int a = (pixel >> 24) & 0xFF;
int b = (pixel >> 16) & 0xFF;
int g = (pixel >> 8) & 0xFF;
int r = pixel & 0xFF;
a = (int) (a * factor);
b = (int) (b * factor);
g = (int) (g * factor);
r = (int) (r * factor);
data.setPixel(x, y, r + (g << 8) + (b << 16) + (a << 25));
}
image.dispose();
image = new Image(display, data);
}
} else {
image = new Image(display, zoomedImaged, SWT.IMAGE_COPY);
}
svg.dispose();
imageMap.put(location, image);
}
return image;
}
use of org.apache.hop.core.SwtUniversalImage in project hop by apache.
the class GuiResource method loadAsResource.
// load image from svg
public Image loadAsResource(Display display, String location, int width, int height) {
SwtUniversalImage img = SwtSvgImageUtil.getImageAsResource(display, location);
int newWidth = (int) Math.round(width * zoomFactor);
int newHeight = (int) Math.round(height * zoomFactor);
Image image = new Image(display, img.getAsBitmapForSize(display, newWidth, newHeight), SWT.IMAGE_COPY);
img.dispose();
return image;
}
use of org.apache.hop.core.SwtUniversalImage in project hop by apache.
the class GuiResource method loadWorkflowActionImages.
/**
* Load all transform images from files.
*/
private void loadWorkflowActionImages() {
imagesActions = new Hashtable<>();
// ACTION IMAGES TO LOAD
//
PluginRegistry registry = PluginRegistry.getInstance();
List<IPlugin> plugins = registry.getPlugins(ActionPluginType.class);
for (int i = 0; i < plugins.size(); i++) {
IPlugin plugin = plugins.get(i);
SwtUniversalImage 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);
}
}
imagesActions.put(plugin.getIds()[0], image);
}
}
Aggregations