1 11 package org.eclipse.ui.internal.browser; 12 13 import java.net.URL ; 14 import java.util.Map ; 15 import java.util.HashMap ; 16 import org.eclipse.swt.graphics.Image; 17 import org.eclipse.core.runtime.FileLocator; 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jface.resource.ImageRegistry; 21 24 public class ImageResource { 25 private static ImageRegistry imageRegistry; 27 28 private static Map imageDescriptors; 31 32 private static Image[] busyImages; 33 34 private static final String URL_PREFIX = "$nl$/icons/"; private static final String URL_CLCL = URL_PREFIX + "clcl16/"; private static final String URL_ELCL = URL_PREFIX + "elcl16/"; private static final String URL_DLCL = URL_PREFIX + "dlcl16/"; private static final String URL_OBJ = URL_PREFIX + "obj16/"; 40 public static final String IMG_CLCL_NAV_BACKWARD = "IMG_CLCL_NAV_BACKWARD"; public static final String IMG_CLCL_NAV_FORWARD = "IMG_CLCL_NAV_FORWARD"; public static final String IMG_CLCL_NAV_STOP = "IMG_CLCL_NAV_STOP"; public static final String IMG_CLCL_NAV_REFRESH = "IMG_CLCL_NAV_REFRESH"; public static final String IMG_CLCL_NAV_GO = "IMG_CLCL_NAV_GO"; public static final String IMG_CLCL_NAV_HOME = "IMG_CLCL_NAV_HOME"; public static final String IMG_CLCL_NAV_PRINT = "IMG_CLCL_NAV_PRINT"; 50 public static final String IMG_ELCL_NAV_BACKWARD = "IMG_ELCL_NAV_BACKWARD"; public static final String IMG_ELCL_NAV_FORWARD = "IMG_ELCL_NAV_FORWARD"; public static final String IMG_ELCL_NAV_STOP = "IMG_ELCL_NAV_STOP"; public static final String IMG_ELCL_NAV_REFRESH = "IMG_ELCL_NAV_REFRESH"; public static final String IMG_ELCL_NAV_GO = "IMG_ELCL_NAV_GO"; public static final String IMG_ELCL_NAV_HOME = "IMG_ELCL_NAV_HOME"; public static final String IMG_ELCL_NAV_PRINT = "IMG_ELCL_NAV_PRINT"; 58 public static final String IMG_DLCL_NAV_BACKWARD = "IMG_DLCL_NAV_BACKWARD"; public static final String IMG_DLCL_NAV_FORWARD = "IMG_DLCL_NAV_FORWARD"; public static final String IMG_DLCL_NAV_STOP = "IMG_DLCL_NAV_STOP"; public static final String IMG_DLCL_NAV_REFRESH = "IMG_DLCL_NAV_REFRESH"; public static final String IMG_DLCL_NAV_GO = "IMG_DLCL_NAV_GO"; public static final String IMG_DLCL_NAV_HOME = "IMG_DLCL_NAV_HOME"; public static final String IMG_DLCL_NAV_PRINT = "IMG_DLCL_NAV_PRINT"; 66 public static final String IMG_INTERNAL_BROWSER = "internalBrowser"; public static final String IMG_EXTERNAL_BROWSER = "externalBrowser"; public static final String IMG_SYSTEM_BROWSER = "systemBrowser"; 71 74 private ImageResource() { 75 } 77 78 83 public static Image[] getBusyImages() { 84 return busyImages; 85 } 86 87 93 public static Image getImage(String key) { 94 if (imageRegistry == null) 95 initializeImageRegistry(); 96 return imageRegistry.get(key); 97 } 98 99 105 public static ImageDescriptor getImageDescriptor(String key) { 106 if (imageRegistry == null) 107 initializeImageRegistry(); 108 return (ImageDescriptor) imageDescriptors.get(key); 109 } 110 111 114 protected static void initializeImageRegistry() { 115 imageRegistry = new ImageRegistry(); 116 imageDescriptors = new HashMap (); 117 118 registerImage(IMG_ELCL_NAV_BACKWARD, URL_ELCL + "nav_backward.gif"); registerImage(IMG_ELCL_NAV_FORWARD, URL_ELCL + "nav_forward.gif"); registerImage(IMG_ELCL_NAV_STOP, URL_ELCL + "nav_stop.gif"); registerImage(IMG_ELCL_NAV_REFRESH, URL_ELCL + "nav_refresh.gif"); registerImage(IMG_ELCL_NAV_GO, URL_ELCL + "nav_go.gif"); registerImage(IMG_ELCL_NAV_HOME, URL_ELCL + "nav_home.gif"); registerImage(IMG_ELCL_NAV_PRINT, URL_ELCL + "nav_print.gif"); 127 registerImage(IMG_CLCL_NAV_BACKWARD, URL_CLCL + "nav_backward.gif"); registerImage(IMG_CLCL_NAV_FORWARD, URL_CLCL + "nav_forward.gif"); registerImage(IMG_CLCL_NAV_STOP, URL_CLCL + "nav_stop.gif"); registerImage(IMG_CLCL_NAV_REFRESH, URL_CLCL + "nav_refresh.gif"); registerImage(IMG_CLCL_NAV_GO, URL_CLCL + "nav_go.gif"); registerImage(IMG_CLCL_NAV_HOME, URL_CLCL + "nav_home.gif"); registerImage(IMG_CLCL_NAV_PRINT, URL_CLCL + "nav_print.gif"); 135 registerImage(IMG_DLCL_NAV_BACKWARD, URL_DLCL + "nav_backward.gif"); registerImage(IMG_DLCL_NAV_FORWARD, URL_DLCL + "nav_forward.gif"); registerImage(IMG_DLCL_NAV_STOP, URL_DLCL + "nav_stop.gif"); registerImage(IMG_DLCL_NAV_REFRESH, URL_DLCL + "nav_refresh.gif"); registerImage(IMG_DLCL_NAV_GO, URL_DLCL + "nav_go.gif"); registerImage(IMG_DLCL_NAV_HOME, URL_DLCL + "nav_home.gif"); registerImage(IMG_DLCL_NAV_PRINT, URL_DLCL + "nav_print.gif"); 143 registerImage(IMG_INTERNAL_BROWSER, URL_OBJ + "internal_browser.gif"); registerImage(IMG_EXTERNAL_BROWSER, URL_OBJ + "external_browser.gif"); 146 busyImages = new Image[13]; 148 for (int i = 0; i < 13; i++) { 149 registerImage("busy" + i, URL_OBJ + "busy/" + (i+1) + ".gif"); busyImages[i] = getImage("busy" + i); } 152 } 153 154 160 private static void registerImage(String key, String partialURL) { 161 try { 162 URL url = FileLocator.find(WebBrowserUIPlugin.getInstance().getBundle(), new Path(partialURL), null); 163 ImageDescriptor id = ImageDescriptor.createFromURL(url); 164 imageRegistry.put(key, id); 165 imageDescriptors.put(key, id); 166 } catch (Exception e) { 167 Trace.trace(Trace.WARNING, "Error registering image " + key + " from " + partialURL, e); } 169 } 170 } 171 | Popular Tags |