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;
}
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);
}
}
Aggregations