Search in sources :

Example 1 with SwtUniversalImageSvg

use of org.apache.hop.core.SwtUniversalImageSvg in project hop by apache.

the class ExplorerPerspective method loadTypeImages.

private void loadTypeImages(Composite parentComposite) {
    typeImageMap = new HashMap<>();
    int iconSize = (int) (PropsUi.getInstance().getZoomFactor() * 16);
    for (IHopFileType fileType : fileTypes) {
        String imageFilename = fileType.getFileTypeImage();
        if (imageFilename != null) {
            try {
                SvgCacheEntry svgCacheEntry = SvgCache.loadSvg(new SvgFile(imageFilename, fileType.getClass().getClassLoader()));
                SwtUniversalImageSvg imageSvg = new SwtUniversalImageSvg(new SvgImage(svgCacheEntry.getSvgDocument()));
                Image image = imageSvg.getAsBitmapForSize(hopGui.getDisplay(), iconSize, iconSize);
                typeImageMap.put(fileType.getName(), image);
            } catch (Exception e) {
                hopGui.getLog().logError("Error loading image : '" + imageFilename + "' for type '" + fileType.getName() + "'", e);
            }
        }
    }
    // Properly dispose images when done...
    // 
    parentComposite.addListener(SWT.Dispose, e -> {
        for (Image image : typeImageMap.values()) {
            image.dispose();
        }
    });
}
Also used : IHopFileType(org.apache.hop.ui.hopgui.file.IHopFileType) SvgCacheEntry(org.apache.hop.core.svg.SvgCacheEntry) SwtUniversalImageSvg(org.apache.hop.core.SwtUniversalImageSvg) SvgImage(org.apache.hop.core.svg.SvgImage) SvgImage(org.apache.hop.core.svg.SvgImage) Image(org.eclipse.swt.graphics.Image) SvgFile(org.apache.hop.core.svg.SvgFile) HopGuiExtensionPoint(org.apache.hop.ui.hopgui.HopGuiExtensionPoint) HopException(org.apache.hop.core.exception.HopException)

Example 2 with SwtUniversalImageSvg

use of org.apache.hop.core.SwtUniversalImageSvg in project hop by apache.

the class SwtGc method drawImage.

@Override
public void drawImage(SvgFile svgFile, int x, int y, int desiredWidth, int desiredHeight, float magnification, double angle) throws HopException {
    // 
    SvgCacheEntry cacheEntry = SvgCache.loadSvg(svgFile);
    SwtUniversalImageSvg imageSvg = new SwtUniversalImageSvg(new SvgImage(cacheEntry.getSvgDocument()));
    int magnifiedWidth = Math.round(desiredWidth * magnification);
    int magnifiedHeight = Math.round(desiredHeight * magnification);
    if (angle != 0) {
        // A rotated image is blown up to twice its size to allow it to be rendered completely in the
        // center
        // 
        Image img = imageSvg.getAsBitmapForSize(gc.getDevice(), magnifiedWidth, magnifiedHeight, angle);
        Rectangle bounds = img.getBounds();
        int hx = Math.round(bounds.width / magnification);
        int hy = Math.round(bounds.height / magnification);
        gc.drawImage(img, 0, 0, bounds.width, bounds.height, x - hx / 2, y - hy / 2, hx, hy);
    } else {
        // Without rotation we simply draw the image with the desired width
        // 
        Image img = imageSvg.getAsBitmapForSize(gc.getDevice(), magnifiedWidth, magnifiedHeight);
        Rectangle bounds = img.getBounds();
        gc.drawImage(img, 0, 0, bounds.width, bounds.height, x, y, desiredWidth, desiredHeight);
    }
}
Also used : SvgCacheEntry(org.apache.hop.core.svg.SvgCacheEntry) SwtUniversalImageSvg(org.apache.hop.core.SwtUniversalImageSvg) SvgImage(org.apache.hop.core.svg.SvgImage) SwtUniversalImage(org.apache.hop.core.SwtUniversalImage) SvgImage(org.apache.hop.core.svg.SvgImage) Point(org.apache.hop.core.gui.Point)

Example 3 with SwtUniversalImageSvg

use of org.apache.hop.core.SwtUniversalImageSvg in project hop by apache.

the class SvgExplorerFileTypeHandler method paintControl.

private static void paintControl(PaintEvent event, ExplorerFile explorerFile, Canvas canvas) {
    // Render the SVG file...
    // 
    Rectangle area = canvas.getBounds();
    try {
        SvgCacheEntry entry = SvgCache.loadSvg(new SvgFile(explorerFile.getFilename(), SvgExplorerFileType.class.getClassLoader()));
        SwtUniversalImageSvg svg = new SwtUniversalImageSvg(new SvgImage(entry.getSvgDocument()), true);
        float factorX = (float) area.width / entry.getWidth();
        float factorY = (float) area.height / entry.getHeight();
        float minFactor = Math.min(factorX, factorY);
        int imageWidth = (int) (entry.getWidth() * minFactor);
        int imageHeight = (int) (entry.getHeight() * minFactor);
        Image image = svg.getAsBitmapForSize(canvas.getDisplay(), imageWidth, imageHeight);
        event.gc.drawImage(image, 0, 0);
    } catch (Exception e) {
        LogChannel.GENERAL.logError("Error rendering SVG", e);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) SvgCacheEntry(org.apache.hop.core.svg.SvgCacheEntry) SwtUniversalImageSvg(org.apache.hop.core.SwtUniversalImageSvg) SvgImage(org.apache.hop.core.svg.SvgImage) Image(org.eclipse.swt.graphics.Image) SvgImage(org.apache.hop.core.svg.SvgImage) SvgFile(org.apache.hop.core.svg.SvgFile)

Aggregations

SwtUniversalImageSvg (org.apache.hop.core.SwtUniversalImageSvg)3 SvgCacheEntry (org.apache.hop.core.svg.SvgCacheEntry)3 SvgImage (org.apache.hop.core.svg.SvgImage)3 SvgFile (org.apache.hop.core.svg.SvgFile)2 Image (org.eclipse.swt.graphics.Image)2 SwtUniversalImage (org.apache.hop.core.SwtUniversalImage)1 HopException (org.apache.hop.core.exception.HopException)1 Point (org.apache.hop.core.gui.Point)1 HopGuiExtensionPoint (org.apache.hop.ui.hopgui.HopGuiExtensionPoint)1 IHopFileType (org.apache.hop.ui.hopgui.file.IHopFileType)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1