1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.util;
19
20 import java.lang.reflect.Field;
21 import java.net.URL;
22
23 import org.apache.log4j.Logger;
24 import org.eclipse.core.runtime.FileLocator;
25 import org.eclipse.core.runtime.Path;
26 import org.eclipse.core.runtime.Platform;
27 import org.eclipse.jface.resource.ImageDescriptor;
28 import org.eclipse.jface.resource.ImageRegistry;
29 import org.eclipse.swt.graphics.Image;
30
31 import pl.edu.agh.cast.Activator;
32 import pl.edu.agh.cast.CastApplication;
33
34
35
36
37
38
39 public final class Images {
40
41 private static Logger log = Activator.getLogger();
42
43 private static URL baseURL = FileLocator.find(Platform.getBundle(CastApplication.ID), new Path("."), null);
44
45 private static ImageRegistry registry;
46
47 private static Images instance;
48
49 private static final String ICON_PATH = "icons/";
50
51
52
53
54
55
56
57
58 public static final String PROJECT = "prj_obj.gif";
59
60
61
62
63 public static final String FILE = "file_obj.gif";
64
65
66
67
68 public static final String FOLDER = "fldr_obj.gif";
69
70
71
72
73 public static final String TEMPLATE = "template.gif";
74
75
76
77
78 public static final String TEMPLATES = "templates.gif";
79
80
81
82
83 public static final String OTHER_FILE = "other_file.gif";
84
85
86
87
88 public static final String GROUP = "outline/group.gif";
89
90
91
92
93 public static final String NODE = "outline/clock.gif";
94
95
96
97
98 public static final String CONNECTION = "outline/connection.gif";
99
100
101
102
103 public static final String DATA = "bill.gif";
104
105
106
107
108
109 public static final String ENTITY_BIG = "people/entity.png";
110
111
112
113
114 public static final String ENTITY_SMALL = "people/entity_small.png";
115
116
117
118
119 public static final String FILTER = "view/data/filter.gif";
120
121
122
123
124 public static final String COMMON_CHECKBOX = "common/checkboxcleared.gif";
125
126
127
128
129 public static final String COMMON_CHECKBOX_SELECTED = "common/checkboxselected.gif";
130
131
132
133
134 public static final String FIT_ZOOM = "editor/fit_zoom.gif";
135
136
137
138
139 public static final String ZOOM_OUT = "editor/zoom_out.gif";
140
141
142
143
144
145
146 public static Images getInstance() {
147 if (instance == null) {
148 instance = new Images();
149 }
150 return instance;
151 }
152
153 private Images() {
154 log.debug("BASE_URL: " + baseURL);
155
156 String[] imageIDs = new String[] { PROJECT, FILE, FOLDER, GROUP, NODE, CONNECTION, DATA, ENTITY_BIG,
157 ENTITY_SMALL, FILTER, TEMPLATE, TEMPLATES, OTHER_FILE, COMMON_CHECKBOX, COMMON_CHECKBOX_SELECTED,
158 FIT_ZOOM, ZOOM_OUT };
159
160 registry = new ImageRegistry(CastApplication.getDisplay());
161
162 for (String imageId : imageIDs) {
163 ImageDescriptor descriptor = createImageDescriptor(ICON_PATH + imageId);
164 registry.put(imageId, descriptor);
165 }
166 }
167
168
169
170
171
172
173
174
175 public ImageDescriptor getDescriptor(String descriptorId) {
176 return registry.getDescriptor(descriptorId);
177 }
178
179
180
181
182
183
184
185
186 public Image get(String descriptorId) {
187 return registry.get(descriptorId);
188 }
189
190
191
192
193
194
195
196
197
198 public void put(String descriptorId, String path) {
199 registry.put(descriptorId, createImageDescriptor(path));
200 }
201
202
203
204
205
206
207
208
209
210 public void putDescriptor(String descriptorId, ImageDescriptor descriptor) {
211 registry.put(descriptorId, descriptor);
212 }
213
214
215
216
217 private ImageDescriptor createImageDescriptor(String path) {
218 ImageDescriptor result = ImageDescriptor.createFromFile(CastApplication.class, path);
219 return result;
220 }
221
222
223
224
225
226
227
228
229
230
231 @Deprecated
232 public String getFriendlyName(String imageId) {
233 String propertyImageId = imageId.replaceAll("[\\.\\/\\\\]", "_");
234 try {
235 Field friendlyName = Messages.class.getField("Image_FriendlyName_" + propertyImageId);
236 return friendlyName != null ? (String)friendlyName.get(null) : imageId;
237 } catch (Exception e) {
238 return imageId;
239 }
240 }
241
242 }