2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.model
;
12 import java
.net
.MalformedURLException
;
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
;
24 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
25 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
28 * <p>ImageResources class.</p>
34 public class ImageResources
{
36 private static ImageResources instance
;
39 * <p>Getter for the field <code>instance</code>.</p>
41 * @return a {@link eu.etaxonomy.taxeditor.model.ImageResources} object.
43 public static ImageResources
getInstance(){
45 instance
= new ImageResources();
51 /* ***************************************************************************************
53 ************************************************************************************** */
54 /** Constant <code>ADD_ICON="add_icon"</code> */
55 public static final String ADD_ICON
= "add_icon";
56 /** Constant <code>TRASH_ICON="trash_icon"</code> */
57 public static final String TRASH_ICON
= "trash_icon";
58 /** Constant <code>BROWSE_ICON="browse_icon"</code> */
59 public static final String BROWSE_ICON
= "browse_icon";
60 /** Constant <code>EDIT_ICON="edit_icon"</code> */
61 public static final String EDIT_ICON
= "edit_icon";
62 /** Constant <code>EDIT_LOGO_ICON="edit_logo_icon"</code> */
63 public static final String EDIT_LOGO_ICON
= "edit_logo_icon";
64 /** Constant <code>WARNING_ICON="warning_icon"</code> */
65 public static final String WARNING_ICON
= "warning_icon";
66 /** Constant <code>BLACK_SQUARE_ICON="black_square_icon"</code> */
67 public static final String BLACK_SQUARE_ICON
= "black_square_icon";
68 /** Constant <code>HOMOTYPIC_SYN_ICON="homotypic_syn_icon"</code> */
69 public static final String HOMOTYPIC_SYN_ICON
= "homotypic_syn_icon";
70 /** Constant <code>HOMOTYPIC_SYN_ORIGINAL_ICON="homotypic_syn_original_icon"</code> */
71 public static final String HOMOTYPIC_SYN_ORIGINAL_ICON
= "homotypic_syn_original_icon";
72 /** Constant <code>HETEROTYPIC_SYN_ICON="heterotypic_syn_icon"</code> */
73 public static final String HETEROTYPIC_SYN_ICON
= "heterotypic_syn_icon";
74 public static final String NOM_INVAL_NUD_SYN_ICON
= "nom_inval_nud_syn_icon";
75 public static final String HOMOTYPIC_SYNONYM_IN_HETEROTYPIC_GROUP_ICON
= "homotypic_synonym_in_heterotypic_group_icon";
76 /** Constant <code>HETEROTYPIC_SYN_ORIGINAL_ICON="heterotypic_syn_original_icon"</code> */
77 public static final String HETEROTYPIC_SYN_ORIGINAL_ICON
= "heterotypic_syn_original_icon";
78 /** Constant <code>MISAPPLIED_NAME_ICON="misapplied_icon"</code> */
79 public static final String MISAPPLIED_NAME_ICON
= "misapplied_icon";
80 /** Constant <code>CONCEPT_ICON="concept_icon"</code> */
81 public static final String CONCEPT_ICON
= "concept_icon";
82 /** Constant <code>AUTONYM_ICON="autonym_icon"</code> */
83 public static final String AUTONYM_ICON
= "autonym_icon";
84 /** Constant <code>BASIONYM_ICON="basionym_icon"</code> */
85 public static final String BASIONYM_ICON
= "basionym_icon";
86 /** Constant <code>ORTHOGRAPHIC_VARIANT_ICON="orthographic_variants_icon"</code> */
87 public static final String ORTHOGRAPHIC_VARIANT_ICON
= "orthographic_variants_icon";
88 /** Constant <code>DB_ICON="db_icon"</code> */
89 public static final String DB_ICON
= "db_icon";
90 /** Constant <code>MOVE_ICON="move_icon"</code> */
91 public static final String MOVE_ICON
= "move_icon";
92 /** Constant <code>ACTIVE_DELETE_ICON="active_delete_icon"</code> */
93 public static final String ACTIVE_DELETE_ICON
= "active_delete_icon";
94 /** Constant <code>SYNONYM_TO_TAXON_ICON="synoynm_to_taxon_icon"</code> */
95 public static final String SYNONYM_TO_TAXON_ICON
= "synoynm_to_taxon_icon";
96 /** Constant <code>OPEN_TAXON_ICON="open_taxon_icon"</code> */
97 public static final String OPEN_TAXON_ICON
= "open_taxon_icon";
98 /** Constant <code>ADD_CHILD_TAXON_ICON="add_taxon_icon"</code> */
99 public static final String ADD_CHILD_TAXON_ICON
= "add_taxon_icon";
100 /** Constant <code>SWAP_SYNONYM_AND_TAXON_ICON="swap_syn_and_tax_icon"</code> */
101 public static final String SWAP_SYNONYM_AND_TAXON_ICON
= "swap_syn_and_tax_icon";
102 /** Constant <code>QUICK_ADD_ICON="quick_add_icon"</code> */
103 public static final String QUICK_ADD_ICON
= "quick_add_icon";
104 /** Constant <code>TAXON_TO_SYNONYM_ICON="tax_to_syn_icon"</code> */
105 public static final String TAXON_TO_SYNONYM_ICON
= "tax_to_syn_icon";
106 /** Constant <code>ERROR_ANNOTATION_ICON="error_annotation_icon"</code> */
107 public static final String ERROR_ANNOTATION_ICON
= "error_annotation_icon";
108 /** Constant <code>EDIT_BITMAP_ICON="edit_bitmap_icon"</code> */
109 public static final String EDIT_BITMAP_ICON
= "edit_bitmap_icon";
110 /** Constant <code>IMG_DATASOURCE_CONNECTED="IMG_DATASOURCE_CONNECTED"</code> */
111 public static final String IMG_DATASOURCE_CONNECTED
= "IMG_DATASOURCE_CONNECTED";
112 /** Constant <code>IMG_DATASOURCE_DISCONNECTED="IMG_DATASOURCE_DISCONNECTED"</code> */
113 public static final String IMG_DATASOURCE_DISCONNECTED
= "IMG_DATASOURCE_DISCONNECTED";
114 /** Constant <code>IMG_NOT_FOUND="IMG_NOT_FOUND"</code> */
115 public static final String IMG_NOT_FOUND
= "IMG_NOT_FOUND";
116 /** Constant <code>WARNING_ANNOTATION_ICON="warning"</code> */
117 public static final String WARNING_ANNOTATION_ICON
= "warning";
118 /** Constant <code>THREE_PRONGED_EQUAL="3_pronged_equal"</code> */
119 public static final String THREE_PRONGED_EQUAL
= "3_pronged_equal";
120 /** Constant <code>TWO_PRONGED_EQUAL="2_pronged_equal"</code> */
121 public static final String TWO_PRONGED_EQUAL
= "2_pronged_equal";
122 /** Constant <code>MISAPPLIED_NAME="misapplied_name"</code> */
123 public static final String MISAPPLIED_NAME
= "misapplied_name";
124 /** Constant <code>ORPHANED_TAXON="orphaned_taxon"</code> */
125 public static final String ORPHANED_TAXON
= "orphaned_taxon";
126 /** Constant <code>EXPAND_ALL="expand_all"</code> */
127 public static final String EXPAND_ALL
= "expand_all";
128 /** Constant <code>COLLAPSE_ALL="collapse_all"</code> */
129 public static final String COLLAPSE_ALL
= "collapse_all";
133 /***************************************************************************
135 **************************************************************************/
136 private ImageRegistry imageRegistry
;
139 * <p>getImageDescriptor</p>
141 * @param key a {@link java.lang.String} object.
142 * @return a {@link org.eclipse.jface.resource.ImageDescriptor} object.
144 public static ImageDescriptor
getImageDescriptor(String key
) {
145 return getInstance().getImageRegistry().getDescriptor(key
);
151 * @param key a {@link java.lang.String} object.
152 * @return a {@link org.eclipse.swt.graphics.Image} object.
154 public static Image
getImage(String key
) {
155 return getInstance().getImageRegistry().get(key
);
159 * Gets an image for the given URL. Adds the image to the registry as needed.
161 * @param uri a {@link java.net.URI} object.
162 * @return a {@link org.eclipse.swt.graphics.Image} object.
164 public static Image
getImage(URI uri
) {
166 String key
= uri
.toString();
167 ImageRegistry registry
= getInstance().getImageRegistry();
169 Image image
= registry
.get(key
);
172 ImageDescriptor desc
;
174 desc
= ImageDescriptor
.createFromURL(new URL(key
));
175 registry
.put(key
, desc
);
176 image
= registry
.get(key
);
177 } catch (DeviceResourceException e
) {
178 return getImageNotFound();
179 } catch (MalformedURLException e
) {
180 // should never happen
181 } catch (Exception e
) {
182 StoreUtil
.error(ImageResources
.class, e
);
185 // logger.warn(ImageDescriptor.getMissingImageDescriptor().getClass());
186 // logger.warn(desc.getClass());
188 // if (ImageDescriptor.getMissingImageDescriptor().equals(desc)) {
189 // logger.warn("img not found");
198 * <p>getImageNotFound</p>
200 * @return a {@link org.eclipse.swt.graphics.Image} object.
202 public static Image
getImageNotFound() {
203 return getImage(ImageResources
.IMG_NOT_FOUND
);
207 * <p>Getter for the field <code>imageRegistry</code>.</p>
209 * @return a {@link org.eclipse.jface.resource.ImageRegistry} object.
211 public ImageRegistry
getImageRegistry() {
212 if (imageRegistry
== null) {
213 imageRegistry
= TaxeditorStorePlugin
.getDefault().createImageRegistry();
214 initializeImageRegistry(imageRegistry
);
216 return imageRegistry
;
220 * <p>initializeImageRegistry</p>
222 * @param registry a {@link org.eclipse.jface.resource.ImageRegistry} object.
224 protected void initializeImageRegistry(ImageRegistry registry
) {
225 registerImage(registry
, ADD_ICON
,
227 registerImage(registry
, TRASH_ICON
,
229 registerImage(registry
, EDIT_ICON
,
231 registerImage(registry
, EDIT_LOGO_ICON
,
233 registerImage(registry
, WARNING_ICON
,
235 registerImage(registry
, BLACK_SQUARE_ICON
,
236 "accepted_small.gif");
237 registerImage(registry
, HOMOTYPIC_SYN_ICON
,
238 "homosyn_no_bg.gif");
239 registerImage(registry
, HOMOTYPIC_SYN_ORIGINAL_ICON
,
240 "homosyn_original_no_bg.gif");
241 registerImage(registry
, HETEROTYPIC_SYN_ICON
,
242 "heterosyn_no_bg.gif");
243 registerImage(registry
, NOM_INVAL_NUD_SYN_ICON
,
244 "nominval_nud_no_bg.gif");
245 registerImage(registry
, HETEROTYPIC_SYN_ORIGINAL_ICON
,
246 "heterosyn_original_no_bg.gif");
247 registerImage(registry
, HOMOTYPIC_SYNONYM_IN_HETEROTYPIC_GROUP_ICON
,
248 "homotypic_syn_hetero_group.gif");
249 registerImage(registry
, MISAPPLIED_NAME_ICON
,
250 "misapplied_no_bg.gif");
251 registerImage(registry
, CONCEPT_ICON
,
252 "concept_no_bg.gif");
253 registerImage(registry
, AUTONYM_ICON
,
254 "autonym_no_bg.gif");
255 registerImage(registry
, BASIONYM_ICON
,
256 "basionym_no_bg.gif");
257 registerImage(registry
, ORTHOGRAPHIC_VARIANT_ICON
,
258 "orthovariant_no_bg.gif");
259 registerImage(registry
, DB_ICON
,
261 registerImage(registry
, MOVE_ICON
,
262 "correction_change.gif");
263 registerImage(registry
, ACTIVE_DELETE_ICON
,
265 registerImage(registry
, SYNONYM_TO_TAXON_ICON
,
267 registerImage(registry
, OPEN_TAXON_ICON
,
269 registerImage(registry
, ADD_CHILD_TAXON_ICON
,
271 registerImage(registry
,
272 SWAP_SYNONYM_AND_TAXON_ICON
, "swap2.gif");
273 registerImage(registry
, QUICK_ADD_ICON
,
275 registerImage(registry
, TAXON_TO_SYNONYM_ICON
,
277 registerImage(registry
, ERROR_ANNOTATION_ICON
,
279 registerImage(registry
, EDIT_BITMAP_ICON
,
280 "256color_16x16.bmp");
281 registerImage(registry
, IMG_DATASOURCE_CONNECTED
,
283 registerImage(registry
, IMG_DATASOURCE_DISCONNECTED
,
285 registerImage(registry
, IMG_NOT_FOUND
,
286 "pic_not_found.PNG");
287 registerImage(registry
, WARNING_ANNOTATION_ICON
,
289 registerImage(registry
, THREE_PRONGED_EQUAL
,
290 "3_pronged_equal_small.GIF");
291 registerImage(registry
, TWO_PRONGED_EQUAL
,
292 "2_pronged_equal_small.GIF");
293 registerImage(registry
, MISAPPLIED_NAME
,
295 registerImage(registry
, ORPHANED_TAXON
,
297 registerImage(registry
, EXPAND_ALL
,
299 registerImage(registry
, COLLAPSE_ALL
,
301 registerImage(registry
, BROWSE_ICON
,
305 private void registerImage(ImageRegistry registry
, String key
,
308 IPath path
= new Path("icons/" + fileName
); //$NON-NLS-1$
309 URL url
= FileLocator
.find(TaxeditorStorePlugin
.getDefault().getBundle(), path
, null);
311 ImageDescriptor desc
= ImageDescriptor
.createFromURL(url
);
312 registry
.put(key
, desc
);
314 } catch (Exception e
) {