001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.project.ui.internal;
018:
019: import java.net.MalformedURLException;
020: import java.net.URL;
021:
022: import org.eclipse.jface.resource.ImageDescriptor;
023: import org.eclipse.jface.resource.ImageRegistry;
024: import org.eclipse.swt.graphics.Image;
025:
026: /**
027: * Utility class managing ImageDescriptors for the plugin.
028: */
029: public class Images {
030:
031: /** Hashtable of ImageDescriptors */
032: private ImageRegistry imageCache;
033: private URL baseURL;
034:
035: /**
036: * Creates an image descriptor for later use.
037: */
038: synchronized ImageDescriptor create(String id) {
039: URL url = null;
040: try {
041: url = new URL(baseURL, id);
042: } catch (MalformedURLException e) {
043: return null;
044: }
045: ImageDescriptor image = ImageDescriptor.createFromURL(url);
046: imageCache.put(id, image);
047: return image;
048: }
049:
050: /**
051: * Returns the image descriptor for ID, or null if not found.
052: * <p>
053: * Images are from CatalogUIPlugin.getDefault().getImages()
054: * </p>
055: *
056: * @param id
057: * @return ImageDescriptor, or null if there is no such image.
058: */
059: public static ImageDescriptor getDescriptor(String id) {
060: Images images = ProjectUIPlugin.getDefault().getImages();
061: ImageDescriptor found = images.imageCache.getDescriptor(id);
062: if (found != null) {
063: return found;
064: }
065: return images.create(id);
066: }
067:
068: /**
069: * Returns the image associated with the given key, or <code>null</code> if none.
070: *
071: * @param id the key
072: * @return the image, or <code>null</code> if none
073: */
074: public static Image get(String id) {
075: Images images = ProjectUIPlugin.getDefault().getImages();
076: return images.imageCache.get(id);
077: }
078:
079: /**
080: * Initializes the table of images used in this plugin.
081: * <p>
082: * The Images from ISharedImages will be registered with
083: * CatalogUIPlugin.getDefault().getImageRegistry().
084: *
085: * @param url
086: * @param shared
087: */
088: public synchronized void initializeImages(URL url,
089: ImageRegistry shared) {
090: imageCache = shared;
091: baseURL = url;
092:
093: // objects
094: create(ISharedImages.MAP_OBJ);
095: create(ISharedImages.PAGE_OBJ);
096: create(ISharedImages.PROJECT_OBJ);
097: create(ISharedImages.COLLAPSE_ALL);
098: create(ISharedImages.LINK);
099: create(ISharedImages.ADD_CO);
100: create(ISharedImages.D_ADD_CO);
101: create(ISharedImages.D_COLLAPSE_ALL);
102: create(ISharedImages.D_LINK);
103: create(ISharedImages.ACTIVE_LINK);
104: create(ISharedImages.LAYER_OBJ);
105: create(ISharedImages.MAP_FOLDER_OBJ);
106: create(ISharedImages.COLLAPSE_ALL);
107: create(ISharedImages.NEW_PROJECT);
108: create(ImageConstants.UP_CO);
109: create(ImageConstants.DOWN_CO);
110: create(ImageConstants.NEW_WIZBAN);
111: create(ImageConstants.NEWFOLDER_WIZBAN);
112: create(ImageConstants.NEWLAYER_WIZBAN);
113: create(ImageConstants.DROP_DOWN_BUTTON);
114: create(ImageConstants.NEWMAP_WIZBAN);
115: create(ImageConstants.NEWPAGE_WIZBAN);
116: create(ImageConstants.NEWPROJECT_WIZBAN);
117: create(ImageConstants.NEWTEMPLATE_WIZBAN);
118:
119: create(ImageConstants.PRIORITY_CRITICAL);
120: create(ImageConstants.PRIORITY_HIGH);
121: create(ImageConstants.PRIORITY_LOW);
122: create(ImageConstants.PRIORITY_TRIVIAL);
123: create(ImageConstants.PRIORITY_WARNING);
124:
125: create(ImageConstants.RESOLUTION_RESOLVED);
126: create(ImageConstants.RESOLUTION_UNKNOWN);
127: create(ImageConstants.RESOLUTION_UNRESOLVED);
128: create(ImageConstants.RESOLUTION_VIEWED);
129:
130: create(ImageConstants.GOTO_ISSUE);
131: create(ImageConstants.DELETE);
132: create(ImageConstants.DELETE_GROUP);
133:
134: create(ImageConstants.LINKED_DISABLED_CO);
135: create(ImageConstants.LINKED_ENABLED_CO);
136: }
137:
138: /**
139: * Clean up Images during plugin shutdown.
140: */
141: public void cleanUp() {
142: imageCache = null; // Display shutdown will clear imageCache
143: }
144: }
|