[Title] improved ImageUtil class
authorjihoon80.song <jihoon80.song@samsung.com>
Thu, 25 Aug 2011 07:27:41 +0000 (16:27 +0900)
committerjihoon80.song <jihoon80.song@samsung.com>
Thu, 25 Aug 2011 07:27:41 +0000 (16:27 +0900)
[Type] Enhancement
[Module] Sub
[Priority] Minor
[CQ#] --
[Redmine#] --
[Problem] --
[Cause] --
[Solution] --
[TestCase] call method directly

com.samsung.slp.common/src/com/samsung/slp/common/util/ImageUtils.java

index e47d5c1..ae436c2 100644 (file)
 
 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