Search in sources :

Example 1 with SwingUniversalImageSvg

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

the class SwingGUIResource method loadActionImages.

private Map<String, SwingUniversalImageSvg> loadActionImages() {
    Map<String, SwingUniversalImageSvg> map = new HashMap<>();
    for (IPlugin plugin : PluginRegistry.getInstance().getPlugins(ActionPluginType.class)) {
        try {
            SwingUniversalImageSvg image = getUniversalImageIcon(plugin);
            if (image == null) {
                throw new HopException("Unable to find image file: " + plugin.getImageFile() + " for plugin: " + plugin);
            }
            map.put(plugin.getIds()[0], image);
        } catch (Exception e) {
            log.logError("Unable to load action icon image for plugin: " + plugin.getName() + " (id=" + plugin.getIds()[0] + ")", e);
        }
    }
    return map;
}
Also used : SwingUniversalImageSvg(org.apache.hop.core.SwingUniversalImageSvg) HashMap(java.util.HashMap) HopException(org.apache.hop.core.exception.HopException) HopException(org.apache.hop.core.exception.HopException) FileNotFoundException(java.io.FileNotFoundException) IPlugin(org.apache.hop.core.plugins.IPlugin)

Example 2 with SwingUniversalImageSvg

use of org.apache.hop.core.SwingUniversalImageSvg 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)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 SwingUniversalImageSvg (org.apache.hop.core.SwingUniversalImageSvg)2 HopException (org.apache.hop.core.exception.HopException)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 IPlugin (org.apache.hop.core.plugins.IPlugin)1 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)1 SvgImage (org.apache.hop.core.svg.SvgImage)1