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;
15 import java.util.HashMap;
16 import org.eclipse.swt.graphics.Image;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.jface.resource.ImageRegistry;
20 * Utility class to handle image resources.
22 public class ImageResource {
24 private static ImageRegistry imageRegistry;
26 // map of image descriptors since these
27 // will be lost by the image registry
28 private static Map imageDescriptors;
30 // base urls for images
31 private static URL ICON_BASE_URL;
35 String pathSuffix = "icons/";
36 ICON_BASE_URL = WebBrowserUIPlugin.getInstance().getBundle().getEntry(pathSuffix);
37 } catch (Exception e) {
38 Trace.trace(Trace.SEVERE, "Could not set icon base URL", e);
42 private static Image[] busyImages;
44 private static final String URL_CLCL = "clcl16/";
45 private static final String URL_ELCL = "elcl16/";
46 private static final String URL_DLCL = "dlcl16/";
48 private static final String URL_OBJ = "obj16/";
50 // --- constants for images ---
52 public static final String IMG_CLCL_NAV_BACKWARD = "IMG_CLCL_NAV_BACKWARD";
53 public static final String IMG_CLCL_NAV_FORWARD = "IMG_CLCL_NAV_FORWARD";
54 public static final String IMG_CLCL_NAV_STOP = "IMG_CLCL_NAV_STOP";
55 public static final String IMG_CLCL_NAV_REFRESH = "IMG_CLCL_NAV_REFRESH";
56 public static final String IMG_CLCL_NAV_GO = "IMG_CLCL_NAV_GO";
57 public static final String IMG_CLCL_NAV_FAVORITES = "cfavorites";
58 public static final String IMG_CLCL_NAV_HOME = "IMG_CLCL_NAV_HOME";
59 public static final String IMG_CLCL_NAV_PRINT = "IMG_CLCL_NAV_PRINT";
61 public static final String IMG_ELCL_NAV_BACKWARD = "IMG_ELCL_NAV_BACKWARD";
62 public static final String IMG_ELCL_NAV_FORWARD = "IMG_ELCL_NAV_FORWARD";
63 public static final String IMG_ELCL_NAV_STOP = "IMG_ELCL_NAV_STOP";
64 public static final String IMG_ELCL_NAV_REFRESH = "IMG_ELCL_NAV_REFRESH";
65 public static final String IMG_ELCL_NAV_GO = "IMG_ELCL_NAV_GO";
66 public static final String IMG_ELCL_NAV_FAVORITES = "efavorites";
67 public static final String IMG_ELCL_NAV_HOME = "IMG_ELCL_NAV_HOME";
68 public static final String IMG_ELCL_NAV_PRINT = "IMG_ELCL_NAV_PRINT";
70 public static final String IMG_DLCL_NAV_BACKWARD = "IMG_DLCL_NAV_BACKWARD";
71 public static final String IMG_DLCL_NAV_FORWARD = "IMG_DLCL_NAV_FORWARD";
72 public static final String IMG_DLCL_NAV_STOP = "IMG_DLCL_NAV_STOP";
73 public static final String IMG_DLCL_NAV_REFRESH = "IMG_DLCL_NAV_REFRESH";
74 public static final String IMG_DLCL_NAV_GO = "IMG_DLCL_NAV_GO";
75 public static final String IMG_DLCL_NAV_FAVORITES = "dfavorites";
76 public static final String IMG_DLCL_NAV_HOME = "IMG_DLCL_NAV_HOME";
77 public static final String IMG_DLCL_NAV_PRINT = "IMG_DLCL_NAV_PRINT";
79 // general object images
80 public static final String IMG_INTERNAL_BROWSER = "internalBrowser";
81 public static final String IMG_EXTERNAL_BROWSER = "externalBrowser";
82 public static final String IMG_FAVORITE = "favorite";
85 * Cannot construct an ImageResource. Use static methods only.
87 private ImageResource() { }
90 * Returns the busy images for the Web browser.
92 * @return org.eclipse.swt.graphics.Image[]
94 public static Image[] getBusyImages() {
99 * Return the image with the given key.
101 * @param key java.lang.String
102 * @return org.eclipse.swt.graphics.Image
104 public static Image getImage(String key) {
105 if (imageRegistry == null)
106 initializeImageRegistry();
107 return imageRegistry.get(key);
111 * Return the image descriptor with the given key.
113 * @param key java.lang.String
114 * @return org.eclipse.jface.resource.ImageDescriptor
116 public static ImageDescriptor getImageDescriptor(String key) {
117 if (imageRegistry == null)
118 initializeImageRegistry();
119 return (ImageDescriptor) imageDescriptors.get(key);
123 * Initialize the image resources.
125 protected static void initializeImageRegistry() {
126 imageRegistry = new ImageRegistry();
127 imageDescriptors = new HashMap();
129 // load Web browser images
130 registerImage(IMG_ELCL_NAV_BACKWARD, URL_ELCL + "nav_backward.gif");
131 registerImage(IMG_ELCL_NAV_FORWARD, URL_ELCL + "nav_forward.gif");
132 registerImage(IMG_ELCL_NAV_STOP, URL_ELCL + "nav_stop.gif");
133 registerImage(IMG_ELCL_NAV_REFRESH, URL_ELCL + "nav_refresh.gif");
134 registerImage(IMG_ELCL_NAV_GO, URL_ELCL + "nav_go.gif");
135 registerImage(IMG_ELCL_NAV_FAVORITES, URL_ELCL + "add_favorite.gif");
136 registerImage(IMG_ELCL_NAV_HOME, URL_ELCL + "nav_home.gif");
137 registerImage(IMG_ELCL_NAV_PRINT, URL_ELCL + "nav_print.gif");
139 registerImage(IMG_CLCL_NAV_BACKWARD, URL_CLCL + "nav_backward.gif");
140 registerImage(IMG_CLCL_NAV_FORWARD, URL_CLCL + "nav_forward.gif");
141 registerImage(IMG_CLCL_NAV_STOP, URL_CLCL + "nav_stop.gif");
142 registerImage(IMG_CLCL_NAV_REFRESH, URL_CLCL + "nav_refresh.gif");
143 registerImage(IMG_CLCL_NAV_GO, URL_CLCL + "nav_go.gif");
144 registerImage(IMG_CLCL_NAV_FAVORITES, URL_CLCL + "add_favorite.gif");
145 registerImage(IMG_CLCL_NAV_HOME, URL_CLCL + "nav_home.gif");
146 registerImage(IMG_CLCL_NAV_PRINT, URL_CLCL + "nav_print.gif");
148 registerImage(IMG_DLCL_NAV_BACKWARD, URL_DLCL + "nav_backward.gif");
149 registerImage(IMG_DLCL_NAV_FORWARD, URL_DLCL + "nav_forward.gif");
150 registerImage(IMG_DLCL_NAV_STOP, URL_DLCL + "nav_stop.gif");
151 registerImage(IMG_DLCL_NAV_REFRESH, URL_DLCL + "nav_refresh.gif");
152 registerImage(IMG_DLCL_NAV_GO, URL_DLCL + "nav_go.gif");
153 registerImage(IMG_DLCL_NAV_FAVORITES, URL_DLCL + "add_favorite.gif");
154 registerImage(IMG_DLCL_NAV_HOME, URL_DLCL + "nav_home.gif");
155 registerImage(IMG_DLCL_NAV_PRINT, URL_DLCL + "nav_print.gif");
157 registerImage(IMG_INTERNAL_BROWSER, URL_OBJ + "internal_browser.gif");
158 registerImage(IMG_EXTERNAL_BROWSER, URL_OBJ + "external_browser.gif");
160 registerImage(IMG_FAVORITE, URL_OBJ + "favorite.gif");
163 busyImages = new Image[13];
164 for (int i = 0; i < 13; i++) {
165 registerImage("busy" + i, URL_OBJ + "frames" + java.io.File.separator + "frame" + (i+1) + ".gif");
166 busyImages[i] = getImage("busy" + i);
171 * Register an image with the registry.
173 * @param key java.lang.String
174 * @param partialURL java.lang.String
176 private static void registerImage(String key, String partialURL) {
178 ImageDescriptor id = ImageDescriptor.createFromURL(new URL(ICON_BASE_URL, partialURL));
179 imageRegistry.put(key, id);
180 imageDescriptors.put(key, id);
181 } catch (Exception e) {
182 Trace.trace(Trace.WARNING, "Error registering image " + key + " from " + partialURL, e);