1 12 package org.eclipse.ant.internal.ui.model; 13 14 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import org.eclipse.jface.action.IAction; 21 import org.eclipse.jface.resource.CompositeImageDescriptor; 22 import org.eclipse.jface.resource.ImageDescriptor; 23 import org.eclipse.jface.resource.ImageRegistry; 24 import org.eclipse.swt.graphics.Image; 25 26 29 public class AntUIImages { 30 31 34 private static ImageRegistry imageRegistry; 35 36 39 private static ImageDescriptorRegistry imageDescriptorRegistry; 40 41 44 private static Map imageDescriptors; 45 46 47 private static URL ICON_BASE_URL= null; 48 49 static { 50 String pathSuffix = "icons/full/"; ICON_BASE_URL= AntUIPlugin.getDefault().getBundle().getEntry(pathSuffix); 52 } 53 54 private final static String LOCALTOOL= "elcl16/"; private final static String OBJECT= "obj16/"; private final static String OVR= "ovr16/"; private final static String WIZ= "wizban/"; 60 63 private static void declareImages() { 64 declareRegistryImage(IAntUIConstants.IMG_PROPERTY, OBJECT + "property_obj.gif"); declareRegistryImage(IAntUIConstants.IMG_TASK_PROPOSAL, OBJECT + "task_obj.gif"); declareRegistryImage(IAntUIConstants.IMG_TEMPLATE_PROPOSAL, OBJECT + "template_obj.gif"); 69 declareRegistryImage(IAntUIConstants.IMG_ANT, OBJECT + "ant.gif"); declareRegistryImage(IAntUIConstants.IMG_REMOVE, LOCALTOOL + "remove_co.gif"); declareRegistryImage(IAntUIConstants.IMG_REMOVE_ALL, LOCALTOOL + "removeAll_co.gif"); declareRegistryImage(IAntUIConstants.IMG_ADD, LOCALTOOL + "add_co.gif"); declareRegistryImage(IAntUIConstants.IMG_RUN, LOCALTOOL + "run_tool.gif"); declareRegistryImage(IAntUIConstants.IMG_SEARCH, LOCALTOOL + "search.gif"); declareRegistryImage(IAntUIConstants.IMG_FILTER_INTERNAL_TARGETS, LOCALTOOL + "filter_internal_targets.gif"); declareRegistryImage(IAntUIConstants.IMG_FILTER_IMPORTED_ELEMENTS, LOCALTOOL + "filter_imported_elements.gif"); declareRegistryImage(IAntUIConstants.IMG_FILTER_PROPERTIES, LOCALTOOL + "filter_properties.gif"); declareRegistryImage(IAntUIConstants.IMG_FILTER_TOP_LEVEL, LOCALTOOL + "filter_top_level.gif"); declareRegistryImage(IAntUIConstants.IMG_LINK_WITH_EDITOR, LOCALTOOL + "synced.gif"); 82 declareRegistryImage(IAntUIConstants.IMG_SORT_OUTLINE, LOCALTOOL + "alpha_mode.gif"); declareRegistryImage(IAntUIConstants.IMG_REFRESH, LOCALTOOL + "refresh.gif"); declareRegistryImage(IAntUIConstants.IMG_ANT_PROJECT, OBJECT + "ant_buildfile.gif"); declareRegistryImage(IAntUIConstants.IMG_ANT_TARGET, OBJECT + "targetpublic_obj.gif"); declareRegistryImage(IAntUIConstants.IMG_ANT_TARGET_INTERNAL, OBJECT + "targetinternal_obj.gif"); declareRegistryImage(IAntUIConstants.IMG_ANT_DEFAULT_TARGET, OBJECT + "defaulttarget_obj.gif"); declareRegistryImage(IAntUIConstants.IMG_ANT_TARGET_ERROR, OBJECT + "ant_target_err.gif"); declareRegistryImage(IAntUIConstants.IMG_ANT_MACRODEF, OBJECT + "macrodef_obj.gif"); declareRegistryImage(IAntUIConstants.IMG_ANT_IMPORT, OBJECT + "import_obj.gif"); declareRegistryImage(IAntUIConstants.IMG_ANT_BUILD_TAB, OBJECT + "build_tab.gif"); declareRegistryImage(IAntUIConstants.IMG_TAB_ANT_TARGETS, LOCALTOOL + "ant_targets.gif"); declareRegistryImage(IAntUIConstants.IMG_TAB_CLASSPATH, OBJECT + "classpath.gif"); declareRegistryImage(IAntUIConstants.IMG_JAR_FILE, OBJECT + "jar_l_obj.gif"); declareRegistryImage(IAntUIConstants.IMG_ANT_TYPE, OBJECT + "type.gif"); 99 declareRegistryImage(IAntUIConstants.IMG_IMPORT_WIZARD_BANNER, WIZ + "importbuildfile_wiz.gif"); 101 declareRegistryImage(IAntUIConstants.IMG_OVR_ERROR, OVR + "error_co.gif"); declareRegistryImage(IAntUIConstants.IMG_OVR_WARNING, OVR + "warning_co.gif"); declareRegistryImage(IAntUIConstants.IMG_OVR_IMPORT, OVR + "import_co.gif"); } 106 107 113 private final static void declareRegistryImage(String key, String path) { 114 ImageDescriptor desc= ImageDescriptor.getMissingImageDescriptor(); 115 try { 116 desc= ImageDescriptor.createFromURL(makeIconFileURL(path)); 117 } catch (MalformedURLException me) { 118 } 119 imageRegistry.put(key, desc); 120 imageDescriptors.put(key, desc); 121 } 122 123 126 public static ImageRegistry getImageRegistry() { 127 if (imageRegistry == null) { 128 initializeImageRegistry(); 129 } 130 return imageRegistry; 131 } 132 133 161 public static ImageRegistry initializeImageRegistry() { 162 imageRegistry= new ImageRegistry(AntUIPlugin.getStandardDisplay()); 163 imageDescriptors = new HashMap (30); 164 declareImages(); 165 return imageRegistry; 166 } 167 168 172 public static Image getImage(String key) { 173 return getImageRegistry().get(key); 174 } 175 176 180 public static ImageDescriptor getImageDescriptor(String key) { 181 if (imageDescriptors == null) { 182 initializeImageRegistry(); 183 } 184 return (ImageDescriptor)imageDescriptors.get(key); 185 } 186 187 private static URL makeIconFileURL(String iconPath) throws MalformedURLException { 188 if (ICON_BASE_URL == null) { 189 throw new MalformedURLException (); 190 } 191 192 return new URL (ICON_BASE_URL, iconPath); 193 } 194 195 199 public static void setLocalImageDescriptors(IAction action, String iconName) { 200 setImageDescriptors(action, "lcl16", iconName); } 202 203 private static void setImageDescriptors(IAction action, String type, String relPath) { 204 205 try { 206 ImageDescriptor id= ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath)); if (id != null) 208 action.setDisabledImageDescriptor(id); 209 } catch (MalformedURLException e) { 210 AntUIPlugin.log(e); 211 } 212 213 try { 214 ImageDescriptor id= ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath)); if (id != null) 216 action.setHoverImageDescriptor(id); 217 } catch (MalformedURLException e) { 218 AntUIPlugin.log(e); 219 } 220 221 action.setImageDescriptor(create("e" + type, relPath)); } 223 224 private static URL makeIconFileURL(String prefix, String name) throws MalformedURLException { 225 if (ICON_BASE_URL == null) { 226 throw new MalformedURLException (); 227 } 228 229 StringBuffer buffer= new StringBuffer (prefix); 230 buffer.append('/'); 231 buffer.append(name); 232 return new URL (ICON_BASE_URL, buffer.toString()); 233 } 234 235 private static ImageDescriptor create(String prefix, String name) { 236 try { 237 return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name)); 238 } catch (MalformedURLException e) { 239 AntUIPlugin.log(e); 240 return ImageDescriptor.getMissingImageDescriptor(); 241 } 242 } 243 244 247 public static Image getImage(CompositeImageDescriptor imageDescriptor) { 248 if (imageDescriptorRegistry == null) { 249 imageDescriptorRegistry = new ImageDescriptorRegistry(); 250 } 251 return imageDescriptorRegistry.get(imageDescriptor); 252 } 253 254 public static void disposeImageDescriptorRegistry() { 255 if (imageDescriptorRegistry != null) { 256 imageDescriptorRegistry.dispose(); 257 } 258 } 259 } | Popular Tags |