Search in sources :

Example 1 with SwtUniversalImage

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);
}
Also used : JsonArray(org.eclipse.rap.json.JsonArray) PipelineHopMeta(org.apache.hop.pipeline.PipelineHopMeta) JsonObject(org.eclipse.rap.json.JsonObject) SwtUniversalImage(org.apache.hop.core.SwtUniversalImage) Image(org.eclipse.swt.graphics.Image) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) SwtUniversalImage(org.apache.hop.core.SwtUniversalImage)

Example 2 with SwtUniversalImage

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);
}
Also used : Color(org.eclipse.swt.graphics.Color) SwtUniversalImage(org.apache.hop.core.SwtUniversalImage) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) SwtUniversalImageBitmap(org.apache.hop.core.SwtUniversalImageBitmap)

Example 3 with SwtUniversalImage

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;
}
Also used : SwtUniversalImage(org.apache.hop.core.SwtUniversalImage) SwtUniversalImage(org.apache.hop.core.SwtUniversalImage)

Example 4 with SwtUniversalImage

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;
}
Also used : SwtUniversalImage(org.apache.hop.core.SwtUniversalImage) SwtUniversalImage(org.apache.hop.core.SwtUniversalImage)

Example 5 with SwtUniversalImage

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);
    }
}
Also used : SwtUniversalImage(org.apache.hop.core.SwtUniversalImage)

Aggregations

SwtUniversalImage (org.apache.hop.core.SwtUniversalImage)13 Image (org.eclipse.swt.graphics.Image)3 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 HopFileException (org.apache.hop.core.exception.HopFileException)2 Point (org.apache.hop.core.gui.Point)2 SvgImage (org.apache.hop.core.svg.SvgImage)2 JsonArray (org.eclipse.rap.json.JsonArray)2 JsonObject (org.eclipse.rap.json.JsonObject)2 org.eclipse.swt.graphics (org.eclipse.swt.graphics)2 SwtUniversalImageBitmap (org.apache.hop.core.SwtUniversalImageBitmap)1 PipelineHopMeta (org.apache.hop.pipeline.PipelineHopMeta)1 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)1 WorkflowHopMeta (org.apache.hop.workflow.WorkflowHopMeta)1 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)1 Color (org.eclipse.swt.graphics.Color)1 GC (org.eclipse.swt.graphics.GC)1