Search in sources :

Example 1 with SvgFile

use of org.apache.hop.core.svg.SvgFile in project hop by apache.

the class PipelinePainter method drawArrow.

@Override
protected void drawArrow(EImage arrow, int x1, int y1, int x2, int y2, double theta, int size, double factor, PipelineHopMeta pipelineHop, Object startObject, Object endObject) throws HopException {
    int mx;
    int my;
    int a;
    int b;
    int dist;
    double angle;
    gc.drawLine(x1, y1, x2, y2);
    // What's the distance between the 2 points?
    a = Math.abs(x2 - x1);
    b = Math.abs(y2 - y1);
    dist = (int) Math.sqrt(a * a + b * b);
    // 0-->100%)
    if (factor < 0) {
        if (dist >= 2 * iconSize) {
            factor = 1.3;
        } else {
            factor = 1.2;
        }
    }
    // in between 2 points
    mx = (int) (x1 + factor * (x2 - x1) / 2);
    my = (int) (y1 + factor * (y2 - y1) / 2);
    // calculate points for arrowhead
    angle = Math.atan2(y2 - y1, x2 - x1) + (Math.PI / 2);
    boolean q1 = Math.toDegrees(angle) >= 0 && Math.toDegrees(angle) < 90;
    boolean q2 = Math.toDegrees(angle) >= 90 && Math.toDegrees(angle) < 180;
    boolean q3 = Math.toDegrees(angle) >= 180 && Math.toDegrees(angle) < 270;
    boolean q4 = Math.toDegrees(angle) >= 270 || Math.toDegrees(angle) < 0;
    if (q1 || q3) {
        gc.drawImage(arrow, mx, my + 1, magnification, angle);
    } else if (q2 || q4) {
        gc.drawImage(arrow, mx, my, magnification, angle);
    }
    if (startObject instanceof TransformMeta && endObject instanceof TransformMeta) {
        factor = 0.8;
        TransformMeta fs = (TransformMeta) startObject;
        TransformMeta ts = (TransformMeta) endObject;
        // in between 2 points
        mx = (int) (x1 + factor * (x2 - x1) / 2) - miniIconSize / 2;
        my = (int) (y1 + factor * (y2 - y1) / 2) - miniIconSize / 2;
        boolean errorHop = fs.isSendingErrorRowsToTransform(ts) || (startErrorHopTransform && fs.equals(startHopTransform));
        boolean targetHop = Const.indexOfString(ts.getName(), fs.getTransform().getTransformIOMeta().getTargetTransformNames()) >= 0;
        if (targetHop) {
            ITransformIOMeta ioMeta = fs.getTransform().getTransformIOMeta();
            IStream targetStream = ioMeta.findTargetStream(ts);
            if (targetStream != null) {
                EImage image = BasePainter.getStreamIconImage(targetStream.getStreamIcon(), pipelineHop.isEnabled());
                gc.drawImage(image, mx, my, magnification);
                areaOwners.add(new AreaOwner(AreaType.TRANSFORM_TARGET_HOP_ICON, mx, my, 16, 16, offset, fs, targetStream));
            }
        } else if (fs.isDistributes() && fs.getRowDistribution() != null && !ts.getTransformPartitioningMeta().isMethodMirror() && !errorHop) {
            // Draw the custom row distribution plugin icon
            // 
            SvgFile svgFile = fs.getRowDistribution().getDistributionImage();
            if (svgFile != null) {
                // 
                gc.drawImage(svgFile, mx, my, 16, 16, magnification, 0);
                areaOwners.add(new AreaOwner(AreaType.ROW_DISTRIBUTION_ICON, mx, my, 16, 16, offset, fs, STRING_ROW_DISTRIBUTION));
                mx += 16;
            }
        } else if (!fs.isDistributes() && !ts.getTransformPartitioningMeta().isMethodMirror() && !errorHop) {
            // Draw the copy icon on the hop
            // 
            EImage image = (pipelineHop.isEnabled()) ? EImage.COPY_ROWS : EImage.COPY_ROWS_DISABLED;
            gc.drawImage(image, mx, my, magnification);
            areaOwners.add(new AreaOwner(AreaType.HOP_COPY_ICON, mx, my, 16, 16, offset, fs, STRING_HOP_TYPE_COPY));
            mx += 16;
        }
        if (errorHop) {
            EImage image = (pipelineHop.isEnabled()) ? EImage.ERROR : EImage.ERROR_DISABLED;
            gc.drawImage(image, mx, my, magnification);
            areaOwners.add(new AreaOwner(AreaType.HOP_ERROR_ICON, mx, my, 16, 16, offset, fs, ts));
            mx += 16;
        }
        ITransformIOMeta ioMeta = ts.getTransform().getTransformIOMeta();
        String[] infoTransformNames = ioMeta.getInfoTransformNames();
        if ((candidateHopType == StreamType.INFO && ts.equals(endHopTransform) && fs.equals(startHopTransform)) || Const.indexOfString(fs.getName(), infoTransformNames) >= 0) {
            EImage image = (pipelineHop.isEnabled()) ? EImage.INFO : EImage.INFO_DISABLED;
            gc.drawImage(image, mx, my, magnification);
            areaOwners.add(new AreaOwner(AreaType.HOP_INFO_ICON, mx, my, 16, 16, offset, fs, ts));
            mx += 16;
        }
        // 
        if (!Utils.isEmpty(infoTransformNames)) {
            // 
            for (String infoTransform : infoTransformNames) {
                if (fs.getName().equalsIgnoreCase(infoTransform)) {
                    // 
                    if (fs.isPartitioned() && ts.isPartitioned()) {
                        // TODO explain in the UI what's going on.
                        // 
                        gc.drawImage(EImage.PARALLEL, mx, my, magnification);
                        areaOwners.add(new AreaOwner(AreaType.HOP_INFO_TRANSFORMS_PARTITIONED, mx, my, miniIconSize, miniIconSize, offset, fs, ts));
                        mx += 16;
                    } else if (fs.getCopies(variables) > 1) {
                        // This is not a desirable situation, it will always end in error.
                        // As such, it's better not to give feedback on it.
                        // We do this by drawing an error icon over the hop...
                        // 
                        gc.drawImage(EImage.ERROR, mx, my, magnification);
                        areaOwners.add(new AreaOwner(AreaType.HOP_INFO_TRANSFORM_COPIES_ERROR, mx, my, miniIconSize, miniIconSize, offset, fs, ts));
                        mx += 16;
                    }
                }
            }
        }
    }
    PipelinePainterExtension extension = new PipelinePainterExtension(gc, areaOwners, pipelineMeta, null, pipelineHop, x1, y1, x2, y2, mx, my, offset, iconSize, stateMap);
    try {
        ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, variables, HopExtensionPoint.PipelinePainterArrow.id, extension);
    } catch (Exception e) {
        LogChannel.GENERAL.logError("Error calling extension point(s) for the pipeline painter arrow", e);
    }
}
Also used : IStream(org.apache.hop.pipeline.transform.stream.IStream) SvgFile(org.apache.hop.core.svg.SvgFile) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException) ITransformIOMeta(org.apache.hop.pipeline.transform.ITransformIOMeta) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta)

Example 2 with SvgFile

use of org.apache.hop.core.svg.SvgFile in project hop by apache.

the class SvgGc method init.

private void init() throws HopException {
    this.lineStyle = ELineStyle.SOLID;
    this.lineWidth = 1;
    this.alpha = 255;
    this.background = new Color(255, 255, 255);
    this.black = new Color(0, 0, 0);
    this.red = new Color(255, 0, 0);
    this.yellow = new Color(255, 255, 0);
    this.green = new Color(0, 255, 0);
    this.blue = new Color(0, 0, 255);
    this.magenta = new Color(255, 0, 255);
    this.purpule = new Color(128, 0, 128);
    this.indigo = new Color(75, 0, 130);
    this.gray = new Color(215, 215, 215);
    this.lightGray = new Color(225, 225, 225);
    this.darkGray = new Color(100, 100, 100);
    // light sky blue
    this.lightBlue = new Color(135, 206, 250);
    this.crystal = new Color(61, 99, 128);
    this.hopDefault = new Color(61, 99, 128);
    this.hopTrue = new Color(12, 178, 15);
    this.hopFalse = new Color(255, 165, 0);
    this.deprecated = new Color(246, 196, 56);
    imageLocked = new SvgFile("ui/images/lock.svg", this.getClass().getClassLoader());
    imageFailure = new SvgFile("ui/images/failure.svg", this.getClass().getClassLoader());
    imageEdit = new SvgFile("ui/images/edit.svg", this.getClass().getClassLoader());
    imageContextMenu = // Used ?
    new SvgFile("ui/images/settings.svg", this.getClass().getClassLoader());
    imageTrue = new SvgFile("ui/images/true.svg", this.getClass().getClassLoader());
    imageTrueDisabled = new SvgFile("ui/images/true-disabled.svg", this.getClass().getClassLoader());
    imageFalse = new SvgFile("ui/images/false.svg", this.getClass().getClassLoader());
    imageFalseDisabled = new SvgFile("ui/images/false-disabled.svg", this.getClass().getClassLoader());
    imageError = new SvgFile("ui/images/error.svg", this.getClass().getClassLoader());
    imageErrorDisabled = new SvgFile("ui/images/error-disabled.svg", this.getClass().getClassLoader());
    imageInfo = new SvgFile("ui/images/info.svg", this.getClass().getClassLoader());
    imageInfoDisabled = new SvgFile("ui/images/info-disabled.svg", this.getClass().getClassLoader());
    imageTarget = new SvgFile("ui/images/target.svg", this.getClass().getClassLoader());
    imageTargetDisabled = new SvgFile("ui/images/target-disabled.svg", this.getClass().getClassLoader());
    imageInput = new SvgFile("ui/images/input.svg", this.getClass().getClassLoader());
    imageOutput = new SvgFile("ui/images/output.svg", this.getClass().getClassLoader());
    imageArrow = new SvgFile("ui/images/arrow.svg", this.getClass().getClassLoader());
    imageCopyRows = new SvgFile("ui/images/copy-rows.svg", this.getClass().getClassLoader());
    imageCopyRowsDisabled = new SvgFile("ui/images/copy-rows-disabled.svg", this.getClass().getClassLoader());
    imageLoadBalance = new SvgFile("ui/images/scales.svg", this.getClass().getClassLoader());
    imageCheckpoint = new SvgFile("ui/images/checkpoint.svg", this.getClass().getClassLoader());
    imageDatabase = new SvgFile("ui/images/database.svg", this.getClass().getClassLoader());
    imageParallel = new SvgFile("ui/images/parallel-hop.svg", this.getClass().getClassLoader());
    imageParallelDisabled = new SvgFile("ui/images/parallel-hop-disabled.svg", this.getClass().getClassLoader());
    imageUnconditional = new SvgFile("ui/images/unconditional.svg", this.getClass().getClassLoader());
    imageUnconditionalDisabled = new SvgFile("ui/images/unconditional-disabled.svg", this.getClass().getClassLoader());
    imageBusy = new SvgFile("ui/images/busy.svg", this.getClass().getClassLoader());
    imageInject = new SvgFile("ui/images/inject.svg", this.getClass().getClassLoader());
    imageMissing = new SvgFile("ui/images/missing.svg", this.getClass().getClassLoader());
    imageDeprecated = new SvgFile("ui/images/deprecated.svg", this.getClass().getClassLoader());
    // Hop arrow
    // 
    imageArrowDefault = new SvgFile("ui/images/hop-arrow-default.svg", this.getClass().getClassLoader());
    imageArrowFalse = new SvgFile("ui/images/hop-arrow-false.svg", this.getClass().getClassLoader());
    imageArrowTrue = new SvgFile("ui/images/hop-arrow-true.svg", this.getClass().getClassLoader());
    imageArrowError = new SvgFile("ui/images/hop-arrow-error.svg", this.getClass().getClassLoader());
    imageArrowDisabled = new SvgFile("ui/images/hop-arrow-disabled.svg", this.getClass().getClassLoader());
    fontGraph = new Font("FreeSans", Font.PLAIN, 10);
    fontNote = new Font("FreeSans", Font.PLAIN, 10);
    fontSmall = new Font("FreeSans", Font.PLAIN, 8);
    gc.setFont(fontGraph);
    gc.setColor(background);
    gc.fillRect(0, 0, area.x, area.y);
}
Also used : SvgFile(org.apache.hop.core.svg.SvgFile)

Example 3 with SvgFile

use of org.apache.hop.core.svg.SvgFile in project hop by apache.

the class SvgGc method getTransformImageFilenames.

private Map<String, SvgFile> getTransformImageFilenames() throws HopPluginException {
    Map<String, SvgFile> map = new HashMap<>();
    PluginRegistry registry = PluginRegistry.getInstance();
    for (IPlugin plugin : registry.getPlugins(TransformPluginType.class)) {
        for (String id : plugin.getIds()) {
            map.put(id, new SvgFile(plugin.getImageFile(), registry.getClassLoader(plugin)));
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) SvgFile(org.apache.hop.core.svg.SvgFile) IPlugin(org.apache.hop.core.plugins.IPlugin)

Example 4 with SvgFile

use of org.apache.hop.core.svg.SvgFile in project hop by apache.

the class DrawDiffOnActionExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, Object object) throws HopException {
    if (!(object instanceof WorkflowPainter)) {
        return;
    }
    WorkflowPainter painter = (WorkflowPainter) object;
    Point offset = painter.getOffset();
    IGc gc = painter.getGc();
    WorkflowMeta workflowMeta = painter.getWorkflowMeta();
    try {
        workflowMeta.getActions().stream().filter(je -> je.getAttribute(ATTR_GIT, ATTR_STATUS) != null).forEach(je -> {
            if (workflowMeta.getWorkflowVersion() == null ? false : workflowMeta.getWorkflowVersion().startsWith("git")) {
                String status = je.getAttribute(ATTR_GIT, ATTR_STATUS);
                Point n = je.getLocation();
                String location;
                if (status.equals(REMOVED)) {
                    location = "removed.svg";
                } else if (status.equals(CHANGED)) {
                    location = "changed.svg";
                } else if (status.equals(ADDED)) {
                    location = "added.svg";
                } else {
                    // Unchanged
                    return;
                }
                int iconSize = ConstUi.ICON_SIZE;
                try {
                    iconSize = PropsUi.getInstance().getIconSize();
                } catch (Exception e) {
                // Exception when accessed from Hop Server
                }
                int x = (n.x + iconSize + offset.x) - (iconSize / 4);
                int y = n.y + offset.y - (iconSize / 4);
                try {
                    gc.drawImage(new SvgFile(location, getClass().getClassLoader()), x, y, iconSize / 4, iconSize / 4, gc.getMagnification(), 0);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
                je.getAttributesMap().remove(ATTR_GIT);
            }
        });
    } catch (Exception e) {
        throw new HopException("Error drawing status icon on action", e);
    }
}
Also used : ILogChannel(org.apache.hop.core.logging.ILogChannel) SvgFile(org.apache.hop.core.svg.SvgFile) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IVariables(org.apache.hop.core.variables.IVariables) WorkflowPainter(org.apache.hop.workflow.WorkflowPainter) HopDiff(org.apache.hop.git.HopDiff) HopException(org.apache.hop.core.exception.HopException) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) PropsUi(org.apache.hop.ui.core.PropsUi) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) IGc(org.apache.hop.core.gui.IGc) Point(org.apache.hop.core.gui.Point) ConstUi(org.apache.hop.ui.core.ConstUi) IGc(org.apache.hop.core.gui.IGc) HopException(org.apache.hop.core.exception.HopException) WorkflowPainter(org.apache.hop.workflow.WorkflowPainter) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) Point(org.apache.hop.core.gui.Point) SvgFile(org.apache.hop.core.svg.SvgFile) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) Point(org.apache.hop.core.gui.Point) HopException(org.apache.hop.core.exception.HopException) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta)

Example 5 with SvgFile

use of org.apache.hop.core.svg.SvgFile in project hop by apache.

the class DrawDiffOnPipelineHopExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, PipelinePainterExtension ext) throws HopException {
    IGc gc = ext.gc;
    ClassLoader classLoader = this.getClass().getClassLoader();
    try {
        Map<String, String> gitHops = ext.pipelineMeta.getAttributes(ATTR_GIT_HOPS);
        if (gitHops == null) {
            return;
        }
        for (String hopName : gitHops.keySet()) {
            String pipelineHopName = getPipelineHopName(ext.pipelineHop);
            if (ext.pipelineHop != null && pipelineHopName.equals(hopName)) {
                // Draw this status...
                // 
                SvgFile svgFile = null;
                String status = gitHops.get(hopName);
                if (status != null) {
                    switch(status) {
                        case ADDED:
                            svgFile = new SvgFile("added.svg", classLoader);
                            break;
                        case REMOVED:
                            svgFile = new SvgFile("removed.svg", classLoader);
                            break;
                        case CHANGED:
                            svgFile = new SvgFile("changed.svg", classLoader);
                            break;
                    }
                    if (svgFile != null) {
                        // Center of hop...
                        // 
                        Point fr = ext.pipelineHop.getFromTransform().getLocation();
                        Point to = ext.pipelineHop.getToTransform().getLocation();
                        Point middle = new Point((fr.x + to.x) / 2, (fr.y + to.y) / 2);
                        int iconSize = ConstUi.ICON_SIZE;
                        try {
                            iconSize = PropsUi.getInstance().getIconSize();
                        } catch (Exception e) {
                        // Exception when accessed from Hop Server
                        }
                        gc.drawImage(svgFile, middle.x, middle.y, iconSize / 2, iconSize / 2, gc.getMagnification(), 0);
                    }
                }
            }
        }
    } catch (Exception e) {
        throw new HopException("Error drawing status on pipeline hop", e);
    }
}
Also used : IGc(org.apache.hop.core.gui.IGc) HopException(org.apache.hop.core.exception.HopException) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) Point(org.apache.hop.core.gui.Point) SvgFile(org.apache.hop.core.svg.SvgFile) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) Point(org.apache.hop.core.gui.Point) HopException(org.apache.hop.core.exception.HopException)

Aggregations

SvgFile (org.apache.hop.core.svg.SvgFile)16 HopException (org.apache.hop.core.exception.HopException)8 ExtensionPoint (org.apache.hop.core.extension.ExtensionPoint)5 IExtensionPoint (org.apache.hop.core.extension.IExtensionPoint)5 IGc (org.apache.hop.core.gui.IGc)4 Point (org.apache.hop.core.gui.Point)4 PropsUi (org.apache.hop.ui.core.PropsUi)4 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)3 HashMap (java.util.HashMap)2 SwtUniversalImageSvg (org.apache.hop.core.SwtUniversalImageSvg)2 Rectangle (org.apache.hop.core.gui.Rectangle)2 ILogChannel (org.apache.hop.core.logging.ILogChannel)2 IPlugin (org.apache.hop.core.plugins.IPlugin)2 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)2 SvgCacheEntry (org.apache.hop.core.svg.SvgCacheEntry)2 SvgImage (org.apache.hop.core.svg.SvgImage)2 IVariables (org.apache.hop.core.variables.IVariables)2 HopDiff (org.apache.hop.git.HopDiff)2 ConstUi (org.apache.hop.ui.core.ConstUi)2 SwtGc (org.apache.hop.ui.hopgui.shared.SwtGc)2