1
/*******************************************************************************
2
* Copyright (c) 2009 STMicroelectronics.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* Marzia Maugeri <marzia.maugeri@st.com> - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.linuxtools.dataviewers.abstractviewers;
13
import java.net.MalformedURLException;
15
import java.util.HashMap;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.resource.ImageRegistry;
19
import org.eclipse.linuxtools.dataviewers.STDataViewersActivator;
20
import org.eclipse.swt.graphics.Image;
21
import org.eclipse.ui.ISharedImages;
22
import org.eclipse.ui.PlatformUI;
26
* This class handle the registration of all images used into org.eclipse.linuxtools.dataviewers
28
public class STDataViewersImages {
29
private static ImageRegistry imageRegistry;
32
* A table of all the <code>ImageDescriptor</code>s.
34
private static HashMap<String,ImageDescriptor> imageDescriptors;
36
/* Declare Common paths */
37
private static URL ICON_BASE_URL= null;
40
String pathSuffix = "icons/"; //$NON-NLS-1$
42
STDataViewersActivator activator = STDataViewersActivator.getDefault();
43
ICON_BASE_URL= activator.getBundle().getEntry(pathSuffix);
44
imageRegistry = activator.getImageRegistry();
45
if (imageRegistry == null)
46
imageRegistry= new ImageRegistry(PlatformUI.getWorkbench().getDisplay());
49
public final static String IMG_EXPORT = "export.gif";
50
public final static String IMG_EDIT_PROPERTIES = "prop_edt.gif";
51
public final static String IMG_PERCENTAGE = "percentage.gif";
53
public final static String IMG_SEARCH = "search.gif";
55
public final static String IMG_PRINT = "printer.gif";
56
public final static String IMG_LEFT = "left.gif";
57
public final static String IMG_LEFTEND = "left-end.gif";
58
public final static String IMG_RIGHT = "right.gif";
59
public final static String IMG_RIGHTEND = "right-end.gif";
60
public final static String IMG_SAVE_TXT = "IMG_SAVE_TXT";
62
public static final String IMG_EXPANDALL = "expand_all.gif";
63
public static final String IMG_COLLAPSEALL = "collapse_all.gif";
65
public static final String IMG_FILTER = "filter_ps.gif";
67
public static final String IMG_SORT = "sort.gif";
73
private static void declareImages() {
74
declareRegistryImage(IMG_EXPORT, "export.gif");
75
declareRegistryImage(IMG_EDIT_PROPERTIES, "prop_edt.gif");
76
declareRegistryImage(IMG_PERCENTAGE, "percentage.gif");
78
declareRegistryImage(ISharedImages.IMG_OBJS_INFO_TSK, "info_obj.gif");
79
declareRegistryImage(ISharedImages.IMG_TOOL_FORWARD, "forward_nav.gif");
80
declareRegistryImage(ISharedImages.IMG_TOOL_BACK, "backward_nav.gif");
82
declareRegistryImage(IMG_SEARCH, "search.gif");
84
declareRegistryImage(IMG_PRINT, "printer.gif");
85
declareRegistryImage(IMG_LEFT, "left.gif");
86
declareRegistryImage(IMG_LEFTEND, "left-end.gif");
87
declareRegistryImage(IMG_RIGHT, "right.gif");
88
declareRegistryImage(IMG_RIGHTEND, "right-end.gif");
90
declareRegistryImage(IMG_EXPANDALL, "expand_all.gif");
91
declareRegistryImage(IMG_COLLAPSEALL, "collapse_all.gif");
93
declareRegistryImage(IMG_FILTER, "filter_ps.gif");
95
declareRegistryImage(IMG_SORT, "sort.gif");
99
* Declare an Image in the registry table.
100
* @param key The key to use when registering the image
101
* @param path The path where the image can be found. This path is relative to where
102
* this plugin class is found (i.e. typically the packages directory)
104
private final static void declareRegistryImage(String key, URL path) {
105
ImageDescriptor desc= ImageDescriptor.getMissingImageDescriptor();
106
desc= ImageDescriptor.createFromURL(path);
107
imageRegistry.put(key, desc);
108
imageDescriptors.put(key, desc);
112
* Declare an Image in the registry table.
113
* @param key The key to use when registering the image
114
* @param path The path where the image can be found. This path is relative to where
115
* this plugin class is found (i.e. typically the packages directory)
117
private final static void declareRegistryImage(String key, String path) {
119
URL url = makeIconFileURL(path);
120
declareRegistryImage(key, url);
121
} catch (MalformedURLException me) {
127
* Returns the ImageRegistry.
129
public static ImageRegistry getImageRegistry() {
130
if (imageRegistry == null) {
131
initializeImageRegistry();
133
return imageRegistry;
137
* Initialize the image registry by declaring all of the required
138
* graphics. This involves creating JFace image descriptors describing
139
* how to create/find the image should it be needed.
140
* The image is not actually allocated until requested.
143
* Wizard Banners WIZBAN_
144
* Preference Banners PREF_BAN_
145
* Property Page Banners PROPBAN_
146
* Color toolbar CTOOL_
147
* Enable toolbar ETOOL_
148
* Disable toolbar DTOOL_
149
* Local enabled toolbar ELCL_
150
* Local Disable toolbar DLCL_
154
* Product images PROD_
157
* Where are the images?
158
* The images (typically gifs) are found in the same location as this plugin class.
159
* This may mean the same package directory as the package holding this class.
160
* The images are declared using this.getClass() to ensure they are looked up via
162
* @see org.eclipse.jface.resource.ImageRegistry
164
public static ImageRegistry initializeImageRegistry() {
165
imageDescriptors = new HashMap<String,ImageDescriptor>(30);
167
return imageRegistry;
171
* Returns the <code>Image</code> identified by the given key,
172
* or <code>null</code> if it does not exist.
174
public static Image getImage(String key) {
175
if (imageDescriptors == null) initializeImageRegistry();
176
return getImageRegistry().get(key);
180
* Returns the <code>ImageDescriptor</code> identified by the given key,
181
* or <code>null</code> if it does not exist.
183
public static ImageDescriptor getImageDescriptor(String key) {
184
if (imageDescriptors == null) {
185
initializeImageRegistry();
187
return imageDescriptors.get(key);
190
private static URL makeIconFileURL(String iconPath) throws MalformedURLException {
191
if (ICON_BASE_URL == null) {
192
throw new MalformedURLException();
195
return new URL(ICON_BASE_URL, iconPath);