package com.samsung.slp.common.util;
-import java.net.MalformedURLException;
import java.net.URL;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
+
public class ImageUtils {
+ // get ImageDescriptor from Plugin ID (ID -> ImageDescriptor)
+ public static ImageDescriptor getImageDescriptor(String pluginID, String filePath) {
+ URL url = Platform.getBundle(pluginID).getEntry(filePath);
+ return ImageDescriptor.createFromURL(url);
+ }
+
+ // get ImageDescriptor from Activator Plugin (Activator -> ImageDescriptor)
public static ImageDescriptor getImageDescriptor(Plugin plugin, String filePath) {
- ImageDescriptor descriptor = null;
+ URL url = plugin.getBundle().getEntry(filePath); // $NON-NLS-1$
+ return ImageDescriptor.createFromURL(url);
+ }
- try {
- URL mBaseUrl = plugin.getBundle().getEntry("/"); // $NON-NLS-1$
- URL newUrl = new URL(mBaseUrl, "/" + filePath); // $NON-NLS-1$
- descriptor = ImageDescriptor.createFromURL(newUrl);
- } catch (MalformedURLException e) {
- }
+ // get Image from ImageDescriptor (ImageDescriptor -> Image)
+ public static Image getImage(ImageDescriptor descriptor) {
+ return (descriptor != null) ? descriptor.createImage() : null;
+ }
- return descriptor;
+ // get ImageData from ImageDescriptor (ImageDescriptor -> ImageData)
+ public static ImageData getImageData(ImageDescriptor descriptor) {
+ return (descriptor != null) ? descriptor.getImageData() : null;
}
+ // get Image from Activator Plugin (Activator -> ImageDescriptor -> Image)
public static Image getImage(Plugin plugin, String filePath) {
ImageDescriptor descriptor = getImageDescriptor(plugin, filePath);
-
- return (descriptor != null) ? descriptor.createImage() : null;
+ return getImage(descriptor);
}
+ // get ImageData from Activator Plugin (Activator -> ImageDescriptor -> ImageData)
public static ImageData getImageData(Plugin plugin, String filePath) {
ImageDescriptor descriptor = getImageDescriptor(plugin, filePath);
+ return getImageData(descriptor);
+ }
- return (descriptor != null) ? descriptor.getImageData() : null;
+ // get Image from Plugin ID (ID -> ImageDescriptor -> Image)
+ public static Image getImage(String pluginID, String filePath) {
+ ImageDescriptor descriptor = getImageDescriptor(pluginID, filePath);
+ return getImage(descriptor);
+ }
+
+ // get Image from Plugin ID (ID -> ImageDescriptor -> ImageData)
+ public static ImageData getImageData(String pluginID, String filePath) {
+ ImageDescriptor descriptor = getImageDescriptor(pluginID, filePath);
+ return getImageData(descriptor);
}
-}
+}
\ No newline at end of file