1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.model;
|
11
|
|
12
|
import java.net.MalformedURLException;
|
13
|
import java.net.URI;
|
14
|
import java.net.URL;
|
15
|
|
16
|
import org.eclipse.core.runtime.FileLocator;
|
17
|
import org.eclipse.core.runtime.IPath;
|
18
|
import org.eclipse.core.runtime.Path;
|
19
|
import org.eclipse.jface.resource.DeviceResourceException;
|
20
|
import org.eclipse.jface.resource.ImageDescriptor;
|
21
|
import org.eclipse.jface.resource.ImageRegistry;
|
22
|
import org.eclipse.swt.graphics.Image;
|
23
|
|
24
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
25
|
|
26
|
/**
|
27
|
* <p>ImageResources class.</p>
|
28
|
*
|
29
|
* @author n.hoffmann
|
30
|
* @created 24.03.2009
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class ImageResources {
|
34
|
|
35
|
private static ImageResources instance;
|
36
|
|
37
|
/**
|
38
|
* <p>Getter for the field <code>instance</code>.</p>
|
39
|
*
|
40
|
* @return a {@link eu.etaxonomy.taxeditor.model.ImageResources} object.
|
41
|
*/
|
42
|
public static ImageResources getInstance(){
|
43
|
if(instance == null){
|
44
|
instance = new ImageResources();
|
45
|
}
|
46
|
return instance;
|
47
|
}
|
48
|
|
49
|
|
50
|
/* ***************************************************************************************
|
51
|
ICONS
|
52
|
************************************************************************************** */
|
53
|
/** Constant <code>ADD_ICON="add_icon"</code> */
|
54
|
public static final String ADD_ICON = "add_icon";
|
55
|
/** Constant <code>TRASH_ICON="trash_icon"</code> */
|
56
|
public static final String TRASH_ICON = "trash_icon";
|
57
|
/** Constant <code>BROWSE_ICON="browse_icon"</code> */
|
58
|
public static final String BROWSE_ICON = "browse_icon";
|
59
|
/** Constant <code>EDIT_ICON="edit_icon"</code> */
|
60
|
public static final String EDIT_ICON = "edit_icon";
|
61
|
/** Constant <code>EDIT_LOGO_ICON="edit_logo_icon"</code> */
|
62
|
public static final String EDIT_LOGO_ICON = "edit_logo_icon";
|
63
|
/** Constant <code>WARNING_ICON="warning_icon"</code> */
|
64
|
public static final String WARNING_ICON = "warning_icon";
|
65
|
/** Constant <code>BLACK_SQUARE_ICON="black_square_icon"</code> */
|
66
|
public static final String BLACK_SQUARE_ICON = "black_square_icon";
|
67
|
/** Constant <code>HOMOTYPIC_SYN_ICON="homotypic_syn_icon"</code> */
|
68
|
public static final String HOMOTYPIC_SYN_ICON = "homotypic_syn_icon";
|
69
|
/** Constant <code>HOMOTYPIC_SYN_ORIGINAL_ICON="homotypic_syn_original_icon"</code> */
|
70
|
public static final String HOMOTYPIC_SYN_ORIGINAL_ICON = "homotypic_syn_original_icon";
|
71
|
/** Constant <code>HETEROTYPIC_SYN_ICON="heterotypic_syn_icon"</code> */
|
72
|
public static final String HETEROTYPIC_SYN_ICON = "heterotypic_syn_icon";
|
73
|
/** Constant <code>HETEROTYPIC_SYN_ORIGINAL_ICON="heterotypic_syn_original_icon"</code> */
|
74
|
public static final String HETEROTYPIC_SYN_ORIGINAL_ICON = "heterotypic_syn_original_icon";
|
75
|
/** Constant <code>MISAPPLIED_NAME_ICON="misapplied_icon"</code> */
|
76
|
public static final String MISAPPLIED_NAME_ICON = "misapplied_icon";
|
77
|
/** Constant <code>CONCEPT_ICON="concept_icon"</code> */
|
78
|
public static final String CONCEPT_ICON = "concept_icon";
|
79
|
/** Constant <code>AUTONYM_ICON="autonym_icon"</code> */
|
80
|
public static final String AUTONYM_ICON = "autonym_icon";
|
81
|
/** Constant <code>BASIONYM_ICON="basionym_icon"</code> */
|
82
|
public static final String BASIONYM_ICON = "basionym_icon";
|
83
|
/** Constant <code>ORTHOGRAPHIC_VARIANT_ICON="orthographic_variants_icon"</code> */
|
84
|
public static final String ORTHOGRAPHIC_VARIANT_ICON = "orthographic_variants_icon";
|
85
|
/** Constant <code>DB_ICON="db_icon"</code> */
|
86
|
public static final String DB_ICON = "db_icon";
|
87
|
/** Constant <code>MOVE_ICON="move_icon"</code> */
|
88
|
public static final String MOVE_ICON = "move_icon";
|
89
|
/** Constant <code>ACTIVE_DELETE_ICON="active_delete_icon"</code> */
|
90
|
public static final String ACTIVE_DELETE_ICON = "active_delete_icon";
|
91
|
/** Constant <code>SYNONYM_TO_TAXON_ICON="synoynm_to_taxon_icon"</code> */
|
92
|
public static final String SYNONYM_TO_TAXON_ICON = "synoynm_to_taxon_icon";
|
93
|
/** Constant <code>OPEN_TAXON_ICON="open_taxon_icon"</code> */
|
94
|
public static final String OPEN_TAXON_ICON = "open_taxon_icon";
|
95
|
/** Constant <code>ADD_CHILD_TAXON_ICON="add_taxon_icon"</code> */
|
96
|
public static final String ADD_CHILD_TAXON_ICON = "add_taxon_icon";
|
97
|
/** Constant <code>SWAP_SYNONYM_AND_TAXON_ICON="swap_syn_and_tax_icon"</code> */
|
98
|
public static final String SWAP_SYNONYM_AND_TAXON_ICON = "swap_syn_and_tax_icon";
|
99
|
/** Constant <code>QUICK_ADD_ICON="quick_add_icon"</code> */
|
100
|
public static final String QUICK_ADD_ICON = "quick_add_icon";
|
101
|
/** Constant <code>TAXON_TO_SYNONYM_ICON="tax_to_syn_icon"</code> */
|
102
|
public static final String TAXON_TO_SYNONYM_ICON = "tax_to_syn_icon";
|
103
|
/** Constant <code>ERROR_ANNOTATION_ICON="error_annotation_icon"</code> */
|
104
|
public static final String ERROR_ANNOTATION_ICON = "error_annotation_icon";
|
105
|
/** Constant <code>EDIT_BITMAP_ICON="edit_bitmap_icon"</code> */
|
106
|
public static final String EDIT_BITMAP_ICON = "edit_bitmap_icon";
|
107
|
/** Constant <code>IMG_DATASOURCE_CONNECTED="IMG_DATASOURCE_CONNECTED"</code> */
|
108
|
public static final String IMG_DATASOURCE_CONNECTED = "IMG_DATASOURCE_CONNECTED";
|
109
|
/** Constant <code>IMG_DATASOURCE_DISCONNECTED="IMG_DATASOURCE_DISCONNECTED"</code> */
|
110
|
public static final String IMG_DATASOURCE_DISCONNECTED = "IMG_DATASOURCE_DISCONNECTED";
|
111
|
/** Constant <code>IMG_NOT_FOUND="IMG_NOT_FOUND"</code> */
|
112
|
public static final String IMG_NOT_FOUND = "IMG_NOT_FOUND";
|
113
|
/** Constant <code>WARNING_ANNOTATION_ICON="warning"</code> */
|
114
|
public static final String WARNING_ANNOTATION_ICON = "warning";
|
115
|
/** Constant <code>THREE_PRONGED_EQUAL="3_pronged_equal"</code> */
|
116
|
public static final String THREE_PRONGED_EQUAL = "3_pronged_equal";
|
117
|
/** Constant <code>TWO_PRONGED_EQUAL="2_pronged_equal"</code> */
|
118
|
public static final String TWO_PRONGED_EQUAL = "2_pronged_equal";
|
119
|
/** Constant <code>MISAPPLIED_NAME="misapplied_name"</code> */
|
120
|
public static final String MISAPPLIED_NAME = "misapplied_name";
|
121
|
/** Constant <code>EXPAND_ALL="expand_all"</code> */
|
122
|
public static final String EXPAND_ALL = "expand_all";
|
123
|
/** Constant <code>COLLAPSE_ALL="collapse_all"</code> */
|
124
|
public static final String COLLAPSE_ALL = "collapse_all";
|
125
|
|
126
|
|
127
|
|
128
|
/***************************************************************************
|
129
|
* IMAGE REGISTRY
|
130
|
**************************************************************************/
|
131
|
private ImageRegistry imageRegistry;
|
132
|
|
133
|
/**
|
134
|
* <p>getImageDescriptor</p>
|
135
|
*
|
136
|
* @param key a {@link java.lang.String} object.
|
137
|
* @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
|
138
|
*/
|
139
|
public static ImageDescriptor getImageDescriptor(String key) {
|
140
|
return getInstance().getImageRegistry().getDescriptor(key);
|
141
|
}
|
142
|
|
143
|
/**
|
144
|
* <p>getImage</p>
|
145
|
*
|
146
|
* @param key a {@link java.lang.String} object.
|
147
|
* @return a {@link org.eclipse.swt.graphics.Image} object.
|
148
|
*/
|
149
|
public static Image getImage(String key) {
|
150
|
return getInstance().getImageRegistry().get(key);
|
151
|
}
|
152
|
|
153
|
/**
|
154
|
* Gets an image for the given URL. Adds the image to the registry as needed.
|
155
|
*
|
156
|
* @param uri a {@link java.net.URI} object.
|
157
|
* @return a {@link org.eclipse.swt.graphics.Image} object.
|
158
|
*/
|
159
|
public static Image getImage(URI uri) {
|
160
|
|
161
|
String key = uri.toString();
|
162
|
ImageRegistry registry = getInstance().getImageRegistry();
|
163
|
|
164
|
Image image = registry.get(key);
|
165
|
|
166
|
if (image == null) {
|
167
|
ImageDescriptor desc;
|
168
|
try {
|
169
|
desc = ImageDescriptor.createFromURL(new URL(key));
|
170
|
registry.put(key, desc);
|
171
|
image = registry.get(key);
|
172
|
} catch (DeviceResourceException e) {
|
173
|
return getImageNotFound();
|
174
|
} catch (MalformedURLException e) {
|
175
|
// should never happen
|
176
|
} catch (Exception e) {
|
177
|
// TODO Auto-generated catch block
|
178
|
e.printStackTrace();
|
179
|
}
|
180
|
|
181
|
// logger.warn(ImageDescriptor.getMissingImageDescriptor().getClass());
|
182
|
// logger.warn(desc.getClass());
|
183
|
//
|
184
|
// if (ImageDescriptor.getMissingImageDescriptor().equals(desc)) {
|
185
|
// logger.warn("img not found");
|
186
|
// }
|
187
|
|
188
|
}
|
189
|
|
190
|
return image;
|
191
|
}
|
192
|
|
193
|
/**
|
194
|
* <p>getImageNotFound</p>
|
195
|
*
|
196
|
* @return a {@link org.eclipse.swt.graphics.Image} object.
|
197
|
*/
|
198
|
public static Image getImageNotFound() {
|
199
|
return getImage(ImageResources.IMG_NOT_FOUND);
|
200
|
}
|
201
|
|
202
|
/**
|
203
|
* <p>Getter for the field <code>imageRegistry</code>.</p>
|
204
|
*
|
205
|
* @return a {@link org.eclipse.jface.resource.ImageRegistry} object.
|
206
|
*/
|
207
|
public ImageRegistry getImageRegistry() {
|
208
|
if (imageRegistry == null) {
|
209
|
imageRegistry = TaxeditorStorePlugin.getDefault().createImageRegistry();
|
210
|
initializeImageRegistry(imageRegistry);
|
211
|
}
|
212
|
return imageRegistry;
|
213
|
}
|
214
|
|
215
|
/**
|
216
|
* <p>initializeImageRegistry</p>
|
217
|
*
|
218
|
* @param registry a {@link org.eclipse.jface.resource.ImageRegistry} object.
|
219
|
*/
|
220
|
protected void initializeImageRegistry(ImageRegistry registry) {
|
221
|
registerImage(registry, ADD_ICON,
|
222
|
"add.gif");
|
223
|
registerImage(registry, TRASH_ICON,
|
224
|
"trash.gif");
|
225
|
registerImage(registry, EDIT_ICON,
|
226
|
"text.gif");
|
227
|
registerImage(registry, EDIT_LOGO_ICON, "edit_16x16.ico");
|
228
|
registerImage(registry, WARNING_ICON,
|
229
|
"warn_tsk.gif");
|
230
|
registerImage(registry, BLACK_SQUARE_ICON,
|
231
|
"accepted_small.gif");
|
232
|
registerImage(registry, HOMOTYPIC_SYN_ICON,
|
233
|
"homosyn_no_bg.gif");
|
234
|
registerImage(registry,
|
235
|
HOMOTYPIC_SYN_ORIGINAL_ICON,
|
236
|
"homosyn_original_no_bg.gif");
|
237
|
registerImage(registry, HETEROTYPIC_SYN_ICON,
|
238
|
"heterosyn_no_bg.gif");
|
239
|
registerImage(registry,
|
240
|
HETEROTYPIC_SYN_ORIGINAL_ICON,
|
241
|
"heterosyn_original_no_bg.gif");
|
242
|
registerImage(registry, MISAPPLIED_NAME_ICON,
|
243
|
"misapplied_no_bg.gif");
|
244
|
registerImage(registry, CONCEPT_ICON,
|
245
|
"concept_no_bg.gif");
|
246
|
registerImage(registry, AUTONYM_ICON,
|
247
|
"autonym_no_bg.gif");
|
248
|
registerImage(registry, BASIONYM_ICON,
|
249
|
"basionym_no_bg.gif");
|
250
|
registerImage(registry, ORTHOGRAPHIC_VARIANT_ICON,
|
251
|
"orthovariant_no_bg.gif");
|
252
|
registerImage(registry, DB_ICON, "db.gif");
|
253
|
registerImage(registry, MOVE_ICON,
|
254
|
"correction_change.gif");
|
255
|
registerImage(registry, ACTIVE_DELETE_ICON,
|
256
|
"delete_edit.gif");
|
257
|
registerImage(registry, SYNONYM_TO_TAXON_ICON,
|
258
|
"change.gif");
|
259
|
registerImage(registry, OPEN_TAXON_ICON, "open.gif");
|
260
|
registerImage(registry, ADD_CHILD_TAXON_ICON,
|
261
|
"new_child.gif");
|
262
|
registerImage(registry,
|
263
|
SWAP_SYNONYM_AND_TAXON_ICON, "swap2.gif");
|
264
|
registerImage(registry, QUICK_ADD_ICON,
|
265
|
"quick_add.gif");
|
266
|
registerImage(registry, TAXON_TO_SYNONYM_ICON,
|
267
|
"tax_to_syn.gif");
|
268
|
registerImage(registry, ERROR_ANNOTATION_ICON,
|
269
|
"error_co.gif");
|
270
|
registerImage(registry, EDIT_BITMAP_ICON,
|
271
|
"256color_16x16.bmp");
|
272
|
registerImage(registry, IMG_DATASOURCE_CONNECTED,
|
273
|
"prj_obj.gif");
|
274
|
registerImage(registry, IMG_DATASOURCE_DISCONNECTED,
|
275
|
"cprj_obj.gif");
|
276
|
registerImage(registry, IMG_NOT_FOUND,
|
277
|
"pic_not_found.PNG");
|
278
|
registerImage(registry, WARNING_ANNOTATION_ICON,
|
279
|
"warning_co.gif");
|
280
|
registerImage(registry, THREE_PRONGED_EQUAL,
|
281
|
"3_pronged_equal_small.GIF");
|
282
|
registerImage(registry, TWO_PRONGED_EQUAL,
|
283
|
"2_pronged_equal_small.GIF");
|
284
|
registerImage(registry, MISAPPLIED_NAME,
|
285
|
"ma_12x12.gif");
|
286
|
registerImage(registry, EXPAND_ALL,
|
287
|
"expandAll.jpg");
|
288
|
registerImage(registry, COLLAPSE_ALL,
|
289
|
"collapseall.gif");
|
290
|
registerImage(registry, BROWSE_ICON,
|
291
|
"prj_obj.gif");
|
292
|
}
|
293
|
|
294
|
private void registerImage(ImageRegistry registry, String key,
|
295
|
String fileName) {
|
296
|
try {
|
297
|
IPath path = new Path("icons/" + fileName); //$NON-NLS-1$
|
298
|
URL url = FileLocator.find(TaxeditorStorePlugin.getDefault().getBundle(), path, null);
|
299
|
if (url != null) {
|
300
|
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
|
301
|
registry.put(key, desc);
|
302
|
}
|
303
|
} catch (Exception e) {
|
304
|
}
|
305
|
}
|
306
|
}
|