~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to profiling/org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersImages.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *    Marzia Maugeri <marzia.maugeri@st.com> - initial API and implementation
 
10
 *******************************************************************************/
 
11
package org.eclipse.linuxtools.dataviewers.abstractviewers;
 
12
 
 
13
import java.net.MalformedURLException;
 
14
import java.net.URL;
 
15
import java.util.HashMap;
 
16
 
 
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;
 
23
 
 
24
 
 
25
/*
 
26
 * This class handle the registration of all images used into org.eclipse.linuxtools.dataviewers
 
27
 */
 
28
public class STDataViewersImages {
 
29
        private static ImageRegistry imageRegistry;
 
30
        
 
31
        /**
 
32
         * A table of all the <code>ImageDescriptor</code>s.
 
33
         */
 
34
        private static HashMap<String,ImageDescriptor> imageDescriptors;
 
35
 
 
36
        /* Declare Common paths */
 
37
        private static URL ICON_BASE_URL= null;
 
38
 
 
39
        static {
 
40
                String pathSuffix = "icons/"; //$NON-NLS-1$
 
41
 
 
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());
 
47
        }
 
48
 
 
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";
 
52
        
 
53
        public final static String IMG_SEARCH = "search.gif";
 
54
        
 
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";
 
61
 
 
62
        public static final String IMG_EXPANDALL = "expand_all.gif";
 
63
        public static final String IMG_COLLAPSEALL = "collapse_all.gif";
 
64
 
 
65
        public static final String IMG_FILTER = "filter_ps.gif";
 
66
        
 
67
        public static final String IMG_SORT = "sort.gif";
 
68
        
 
69
 
 
70
        /**
 
71
         * Declare all images
 
72
         */
 
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");
 
77
                
 
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");
 
81
        
 
82
        declareRegistryImage(IMG_SEARCH, "search.gif");
 
83
        
 
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");
 
89
        
 
90
        declareRegistryImage(IMG_EXPANDALL, "expand_all.gif");
 
91
        declareRegistryImage(IMG_COLLAPSEALL, "collapse_all.gif");
 
92
        
 
93
        declareRegistryImage(IMG_FILTER, "filter_ps.gif");
 
94
        
 
95
        declareRegistryImage(IMG_SORT, "sort.gif");
 
96
        }
 
97
        
 
98
        /**
 
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)
 
103
         */
 
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);
 
109
        }
 
110
        
 
111
        /**
 
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)
 
116
         */
 
117
        private final static void declareRegistryImage(String key, String path) {
 
118
                try {
 
119
                        URL url = makeIconFileURL(path);
 
120
                        declareRegistryImage(key, url);
 
121
                } catch (MalformedURLException me) {
 
122
                }
 
123
                
 
124
        }
 
125
        
 
126
        /**
 
127
         * Returns the ImageRegistry.
 
128
         */
 
129
        public static ImageRegistry getImageRegistry() {
 
130
                if (imageRegistry == null) {
 
131
                        initializeImageRegistry();
 
132
                }
 
133
                return imageRegistry;
 
134
        }
 
135
 
 
136
        /**
 
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.
 
141
         *
 
142
         *      Prefix conventions
 
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_
 
151
         *              Object large                    OBJL_
 
152
         *              Object small                    OBJS_
 
153
         *              View                                    VIEW_
 
154
         *              Product images                  PROD_
 
155
         *              Misc images                             MISC_
 
156
         *
 
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
 
161
         *              this plugin class.
 
162
         * @see org.eclipse.jface.resource.ImageRegistry
 
163
         */
 
164
        public static ImageRegistry initializeImageRegistry() {
 
165
                imageDescriptors = new HashMap<String,ImageDescriptor>(30);
 
166
                declareImages();
 
167
                return imageRegistry;
 
168
        }
 
169
 
 
170
        /**
 
171
         * Returns the <code>Image</code> identified by the given key,
 
172
         * or <code>null</code> if it does not exist.
 
173
         */
 
174
        public static Image getImage(String key) {
 
175
                if (imageDescriptors == null) initializeImageRegistry();
 
176
                return getImageRegistry().get(key);
 
177
        }
 
178
        
 
179
        /**
 
180
         * Returns the <code>ImageDescriptor</code> identified by the given key,
 
181
         * or <code>null</code> if it does not exist.
 
182
         */
 
183
        public static ImageDescriptor getImageDescriptor(String key) {
 
184
                if (imageDescriptors == null) {
 
185
                        initializeImageRegistry();
 
186
                }
 
187
                return imageDescriptors.get(key);
 
188
        }
 
189
        
 
190
        private static URL makeIconFileURL(String iconPath) throws MalformedURLException {
 
191
                if (ICON_BASE_URL == null) {
 
192
                        throw new MalformedURLException();
 
193
                }
 
194
                        
 
195
                return new URL(ICON_BASE_URL, iconPath);
 
196
        }
 
197
}