2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
11 package net.sourceforge.phpeclipse.webbrowser.internal;
14 import java.util.HashMap;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.jface.resource.ImageRegistry;
19 import org.eclipse.swt.graphics.Image;
22 * Utility class to handle image resources.
24 public class ImageResource {
26 private static ImageRegistry imageRegistry;
28 // map of image descriptors since these
29 // will be lost by the image registry
30 private static Map imageDescriptors;
32 // base urls for images
33 private static URL ICON_BASE_URL;
37 String pathSuffix = "icons/";
38 ICON_BASE_URL = WebBrowserUIPlugin.getInstance().getBundle()
39 .getEntry(pathSuffix);
40 } catch (Exception e) {
41 Trace.trace(Trace.SEVERE, "Could not set icon base URL", e);
45 private static Image[] busyImages;
47 private static final String URL_CLCL = "clcl16/";
49 private static final String URL_ELCL = "elcl16/";
51 private static final String URL_DLCL = "dlcl16/";
53 private static final String URL_OBJ = "obj16/";
55 // --- constants for images ---
57 public static final String IMG_CLCL_NAV_BACKWARD = "IMG_CLCL_NAV_BACKWARD";
59 public static final String IMG_CLCL_NAV_FORWARD = "IMG_CLCL_NAV_FORWARD";
61 public static final String IMG_CLCL_NAV_STOP = "IMG_CLCL_NAV_STOP";
63 public static final String IMG_CLCL_NAV_REFRESH = "IMG_CLCL_NAV_REFRESH";
65 public static final String IMG_CLCL_NAV_GO = "IMG_CLCL_NAV_GO";
67 public static final String IMG_CLCL_NAV_FAVORITES = "cfavorites";
69 public static final String IMG_CLCL_NAV_HOME = "IMG_CLCL_NAV_HOME";
71 public static final String IMG_CLCL_NAV_PRINT = "IMG_CLCL_NAV_PRINT";
73 public static final String IMG_ELCL_NAV_BACKWARD = "IMG_ELCL_NAV_BACKWARD";
75 public static final String IMG_ELCL_NAV_FORWARD = "IMG_ELCL_NAV_FORWARD";
77 public static final String IMG_ELCL_NAV_STOP = "IMG_ELCL_NAV_STOP";
79 public static final String IMG_ELCL_NAV_REFRESH = "IMG_ELCL_NAV_REFRESH";
81 public static final String IMG_ELCL_NAV_GO = "IMG_ELCL_NAV_GO";
83 public static final String IMG_ELCL_NAV_FAVORITES = "efavorites";
85 public static final String IMG_ELCL_NAV_HOME = "IMG_ELCL_NAV_HOME";
87 public static final String IMG_ELCL_NAV_PRINT = "IMG_ELCL_NAV_PRINT";
89 public static final String IMG_DLCL_NAV_BACKWARD = "IMG_DLCL_NAV_BACKWARD";
91 public static final String IMG_DLCL_NAV_FORWARD = "IMG_DLCL_NAV_FORWARD";
93 public static final String IMG_DLCL_NAV_STOP = "IMG_DLCL_NAV_STOP";
95 public static final String IMG_DLCL_NAV_REFRESH = "IMG_DLCL_NAV_REFRESH";
97 public static final String IMG_DLCL_NAV_GO = "IMG_DLCL_NAV_GO";
99 public static final String IMG_DLCL_NAV_FAVORITES = "dfavorites";
101 public static final String IMG_DLCL_NAV_HOME = "IMG_DLCL_NAV_HOME";
103 public static final String IMG_DLCL_NAV_PRINT = "IMG_DLCL_NAV_PRINT";
105 // general object images
106 public static final String IMG_INTERNAL_BROWSER = "internalBrowser";
108 public static final String IMG_EXTERNAL_BROWSER = "externalBrowser";
110 public static final String IMG_FAVORITE = "favorite";
113 * Cannot construct an ImageResource. Use static methods only.
115 private ImageResource() {
119 * Returns the busy images for the Web browser.
121 * @return org.eclipse.swt.graphics.Image[]
123 public static Image[] getBusyImages() {
128 * Return the image with the given key.
132 * @return org.eclipse.swt.graphics.Image
134 public static Image getImage(String key) {
135 if (imageRegistry == null)
136 initializeImageRegistry();
137 return imageRegistry.get(key);
141 * Return the image descriptor with the given key.
145 * @return org.eclipse.jface.resource.ImageDescriptor
147 public static ImageDescriptor getImageDescriptor(String key) {
148 if (imageRegistry == null)
149 initializeImageRegistry();
150 return (ImageDescriptor) imageDescriptors.get(key);
154 * Initialize the image resources.
156 protected static void initializeImageRegistry() {
157 imageRegistry = new ImageRegistry();
158 imageDescriptors = new HashMap();
160 // load Web browser images
161 registerImage(IMG_ELCL_NAV_BACKWARD, URL_ELCL + "nav_backward.gif");
162 registerImage(IMG_ELCL_NAV_FORWARD, URL_ELCL + "nav_forward.gif");
163 registerImage(IMG_ELCL_NAV_STOP, URL_ELCL + "nav_stop.gif");
164 registerImage(IMG_ELCL_NAV_REFRESH, URL_ELCL + "nav_refresh.gif");
165 registerImage(IMG_ELCL_NAV_GO, URL_ELCL + "nav_go.gif");
166 registerImage(IMG_ELCL_NAV_FAVORITES, URL_ELCL + "add_favorite.gif");
167 registerImage(IMG_ELCL_NAV_HOME, URL_ELCL + "nav_home.gif");
168 registerImage(IMG_ELCL_NAV_PRINT, URL_ELCL + "nav_print.gif");
170 registerImage(IMG_CLCL_NAV_BACKWARD, URL_CLCL + "nav_backward.gif");
171 registerImage(IMG_CLCL_NAV_FORWARD, URL_CLCL + "nav_forward.gif");
172 registerImage(IMG_CLCL_NAV_STOP, URL_CLCL + "nav_stop.gif");
173 registerImage(IMG_CLCL_NAV_REFRESH, URL_CLCL + "nav_refresh.gif");
174 registerImage(IMG_CLCL_NAV_GO, URL_CLCL + "nav_go.gif");
175 registerImage(IMG_CLCL_NAV_FAVORITES, URL_CLCL + "add_favorite.gif");
176 registerImage(IMG_CLCL_NAV_HOME, URL_CLCL + "nav_home.gif");
177 registerImage(IMG_CLCL_NAV_PRINT, URL_CLCL + "nav_print.gif");
179 registerImage(IMG_DLCL_NAV_BACKWARD, URL_DLCL + "nav_backward.gif");
180 registerImage(IMG_DLCL_NAV_FORWARD, URL_DLCL + "nav_forward.gif");
181 registerImage(IMG_DLCL_NAV_STOP, URL_DLCL + "nav_stop.gif");
182 registerImage(IMG_DLCL_NAV_REFRESH, URL_DLCL + "nav_refresh.gif");
183 registerImage(IMG_DLCL_NAV_GO, URL_DLCL + "nav_go.gif");
184 registerImage(IMG_DLCL_NAV_FAVORITES, URL_DLCL + "add_favorite.gif");
185 registerImage(IMG_DLCL_NAV_HOME, URL_DLCL + "nav_home.gif");
186 registerImage(IMG_DLCL_NAV_PRINT, URL_DLCL + "nav_print.gif");
188 registerImage(IMG_INTERNAL_BROWSER, URL_OBJ + "internal_browser.gif");
189 registerImage(IMG_EXTERNAL_BROWSER, URL_OBJ + "external_browser.gif");
191 registerImage(IMG_FAVORITE, URL_OBJ + "favorite.gif");
194 busyImages = new Image[13];
195 for (int i = 0; i < 13; i++) {
196 registerImage("busy" + i, URL_OBJ + "frames/frame" + (i + 1) + ".gif");
197 busyImages[i] = getImage("busy" + i);
202 * Register an image with the registry.
209 private static void registerImage(String key, String partialURL) {
211 ImageDescriptor id = ImageDescriptor.createFromURL(new URL(
212 ICON_BASE_URL, partialURL));
213 imageRegistry.put(key, id);
214 imageDescriptors.put(key, id);
215 } catch (Exception e) {
216 Trace.trace(Trace.WARNING, "Error registering image " + key
217 + " from " + partialURL, e);