Search in sources :

Example 1 with SvgImage

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

the class SwingGUIResource method getUniversalImageIcon.

private SwingUniversalImageSvg getUniversalImageIcon(IPlugin plugin) throws HopException {
    try {
        PluginRegistry registry = PluginRegistry.getInstance();
        String filename = plugin.getImageFile();
        ClassLoader classLoader = registry.getClassLoader(plugin);
        SwingUniversalImageSvg image = null;
        if (SvgSupport.isSvgEnabled() && SvgSupport.isSvgName(filename)) {
            // Try to use the plugin class loader to get access to the icon
            // 
            InputStream inputStream = classLoader.getResourceAsStream(filename);
            if (inputStream == null) {
                inputStream = classLoader.getResourceAsStream("/" + filename);
            }
            // 
            if (inputStream == null) {
                inputStream = registry.getClass().getResourceAsStream(filename);
            }
            if (inputStream == null) {
                inputStream = registry.getClass().getResourceAsStream("/" + filename);
            }
            // 
            if (inputStream == null) {
                try {
                    inputStream = new FileInputStream(filename);
                } catch (FileNotFoundException e) {
                // Ignore, throws error below
                }
            }
            if (inputStream != null) {
                try {
                    SvgImage svg = SvgSupport.loadSvgImage(inputStream);
                    image = new SwingUniversalImageSvg(svg);
                } finally {
                    IOUtils.closeQuietly(inputStream);
                }
            }
        }
        if (image == null) {
            throw new HopException("Unable to find file: " + plugin.getImageFile() + " for plugin: " + plugin);
        }
        return image;
    } catch (Throwable e) {
        throw new HopException("Unable to load image from file : '" + plugin.getImageFile() + "' for plugin: " + plugin, e);
    }
}
Also used : SwingUniversalImageSvg(org.apache.hop.core.SwingUniversalImageSvg) HopException(org.apache.hop.core.exception.HopException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) FileNotFoundException(java.io.FileNotFoundException) SvgImage(org.apache.hop.core.svg.SvgImage) FileInputStream(java.io.FileInputStream)

Example 2 with SvgImage

use of org.apache.hop.core.svg.SvgImage 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 3 with SvgImage

use of org.apache.hop.core.svg.SvgImage 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 4 with SvgImage

use of org.apache.hop.core.svg.SvgImage 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

SvgImage (org.apache.hop.core.svg.SvgImage)4 SwtUniversalImageSvg (org.apache.hop.core.SwtUniversalImageSvg)3 SvgCacheEntry (org.apache.hop.core.svg.SvgCacheEntry)3 HopException (org.apache.hop.core.exception.HopException)2 SvgFile (org.apache.hop.core.svg.SvgFile)2 Image (org.eclipse.swt.graphics.Image)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SwingUniversalImageSvg (org.apache.hop.core.SwingUniversalImageSvg)1 SwtUniversalImage (org.apache.hop.core.SwtUniversalImage)1 Point (org.apache.hop.core.gui.Point)1 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)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