1 11 package org.eclipse.help.ui.internal; 12 import java.net.URL ; 13 14 import org.eclipse.core.runtime.FileLocator; 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.core.runtime.Path; 17 import org.eclipse.core.runtime.Platform; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.resource.ImageRegistry; 20 import org.eclipse.swt.graphics.Image; 21 import org.osgi.framework.Bundle; 22 26 public class HelpUIResources { 27 30 public HelpUIResources() { 31 super(); 32 } 33 36 public static URL getImagePath(String name) { 37 IPath path = new Path("$nl$/icons/").append(name); return FileLocator.find(HelpUIPlugin.getDefault().getBundle(), path, null); 39 } 40 41 46 47 public static ImageDescriptor getImageDescriptor(String name) { 48 URL imagePath = getImagePath(name); 49 ImageRegistry registry = HelpUIPlugin.getDefault().getImageRegistry(); 50 ImageDescriptor desc = registry.getDescriptor(name); 51 if (desc==null) { 52 desc = ImageDescriptor.createFromURL(imagePath); 53 registry.put(name, desc); 54 } 55 return desc; 56 } 57 58 public static ImageDescriptor getImageDescriptor(String bundleId, String name) { 59 ImageRegistry registry = HelpUIPlugin.getDefault().getImageRegistry(); 60 ImageDescriptor desc = registry.getDescriptor(name); 61 if (desc==null) { 62 Bundle bundle = Platform.getBundle(bundleId); 63 if (bundle==null) return null; 64 URL url = FileLocator.find(bundle, new Path(name), null); 65 desc = ImageDescriptor.createFromURL(url); 66 registry.put(name, desc); 67 } 68 return desc; 69 } 70 71 77 78 public static Image getImage(String name) { 79 ImageRegistry registry = HelpUIPlugin.getDefault().getImageRegistry(); 80 getImageDescriptor(name); 82 return registry.get(name); 83 } 84 85 public static Image getImage(URL url) { 86 ImageRegistry registry = HelpUIPlugin.getDefault().getImageRegistry(); 87 String name = url.toString(); 88 ImageDescriptor desc = registry.getDescriptor(name); 89 if (desc==null) { 90 desc = ImageDescriptor.createFromURL(url); 91 registry.put(name, desc); 92 } 93 return registry.get(name); 94 } 95 } 96 | Popular Tags |