1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import java.net.URL ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 17 import org.eclipse.core.runtime.FileLocator; 18 import org.eclipse.core.runtime.IPath; 19 import org.eclipse.core.runtime.Path; 20 21 import org.eclipse.swt.graphics.Image; 22 23 import org.eclipse.jface.action.IAction; 24 import org.eclipse.jface.resource.ImageDescriptor; 25 import org.eclipse.jface.resource.ImageRegistry; 26 27 import org.osgi.framework.Bundle; 28 29 public class RefactoringPluginImages { 30 31 private static final String NAME_PREFIX= "org.eclipse.ltk.ui.refactoring"; private static final int NAME_PREFIX_LENGTH= NAME_PREFIX.length(); 33 34 private static final IPath ICONS_PATH= new Path("$nl$/icons/full"); 36 private static ImageRegistry fgImageRegistry= null; 37 private static HashMap fgAvoidSWTErrorMap= null; 38 39 private static final String T_WIZBAN= "wizban"; private static final String T_OBJ= "obj16"; private static final String T_OVR= "ovr16"; private static final String T_ELCL= "elcl16"; private static final String T_DLCL= "dlcl16"; 45 public static final ImageDescriptor DESC_WIZBAN_REFACTOR= createUnManaged(T_WIZBAN, "refactor_wiz.png"); 47 48 public static final ImageDescriptor DESC_WIZBAN_SHOW_HISTORY= createUnManaged(T_WIZBAN, "show_history_wiz.png"); 50 public static final ImageDescriptor DESC_WIZBAN_APPLY_SCRIPT= createUnManaged(T_WIZBAN, "apply_rescript_wiz.png"); 52 public static final ImageDescriptor DESC_WIZBAN_CREATE_SCRIPT= createUnManaged(T_WIZBAN, "create_rescript_wiz.png"); 54 public static final String IMG_OBJS_REFACTORING_FATAL= NAME_PREFIX + "fatalerror_obj.gif"; public static final String IMG_OBJS_REFACTORING_ERROR= NAME_PREFIX + "error_obj.gif"; public static final String IMG_OBJS_REFACTORING_WARNING= NAME_PREFIX + "warning_obj.gif"; public static final String IMG_OBJS_REFACTORING_INFO= NAME_PREFIX + "info_obj.gif"; 59 60 public static final String IMG_OBJS_REFACTORING_DATE= NAME_PREFIX + "date_obj.gif"; 62 public static final String IMG_OBJS_REFACTORING_TIME= NAME_PREFIX + "time_obj.gif"; 64 public static final ImageDescriptor DESC_ELCL_FILTER= createUnManaged(T_ELCL, "filter_ps.gif"); public static final ImageDescriptor DESC_DLCL_FILTER= createUnManaged(T_DLCL, "filter_ps.gif"); 67 68 public static final ImageDescriptor DESC_ELCL_SORT_PROJECT= createUnManaged(T_ELCL, "prj_mode.gif"); 70 public static final ImageDescriptor DESC_DLCL_SORT_PROJECT= createUnManaged(T_DLCL, "prj_mode.gif"); 72 public static final ImageDescriptor DESC_ELCL_SORT_DATE= createUnManaged(T_ELCL, "date_mode.gif"); 74 public static final ImageDescriptor DESC_DLCL_SORT_DATE= createUnManaged(T_DLCL, "date_mode.gif"); 76 public static final ImageDescriptor DESC_OBJS_REFACTORING_FATAL= createManaged(T_OBJ, IMG_OBJS_REFACTORING_FATAL); 77 public static final ImageDescriptor DESC_OBJS_REFACTORING_ERROR= createManaged(T_OBJ, IMG_OBJS_REFACTORING_ERROR); 78 public static final ImageDescriptor DESC_OBJS_REFACTORING_WARNING= createManaged(T_OBJ, IMG_OBJS_REFACTORING_WARNING); 79 public static final ImageDescriptor DESC_OBJS_REFACTORING_INFO= createManaged(T_OBJ, IMG_OBJS_REFACTORING_INFO); 80 81 82 public static final ImageDescriptor DESC_OBJS_REFACTORING_DATE= createUnManaged(T_OBJ, "date_obj.gif"); 84 public static final ImageDescriptor DESC_OBJS_REFACTORING_TIME= createUnManaged(T_OBJ, "time_obj.gif"); 86 public static final ImageDescriptor DESC_OBJS_REFACTORING= createUnManaged(T_OBJ, "refactoring_obj.gif"); 88 public static final ImageDescriptor DESC_OBJS_REFACTORING_COLL= createUnManaged(T_OBJ, "refactorings_obj.gif"); 90 public static final ImageDescriptor DESC_OVR_WORKSPACE= createUnManaged(T_OVR, "workspace_ovr.gif"); 92 public static final ImageDescriptor DESC_OBJS_DEFAULT_CHANGE= createUnManaged(T_OBJ, "change.gif"); public static final ImageDescriptor DESC_OBJS_COMPOSITE_CHANGE= createUnManaged(T_OBJ, "composite_change.gif"); public static final ImageDescriptor DESC_OBJS_FILE_CHANGE= createUnManaged(T_OBJ, "file_change.gif"); public static final ImageDescriptor DESC_OBJS_TEXT_EDIT= createUnManaged(T_OBJ, "text_edit.gif"); 97 103 public static Image get(String key) { 104 return getImageRegistry().get(key); 105 } 106 107 114 public static void setToolImageDescriptors(IAction action, String iconName) { 115 setImageDescriptors(action, "tool16", iconName); } 117 118 125 public static void setLocalImageDescriptors(IAction action, String iconName) { 126 setImageDescriptors(action, "lcl16", iconName); } 128 129 132 static ImageRegistry getImageRegistry() { 133 if (fgImageRegistry == null) { 134 fgImageRegistry= new ImageRegistry(); 135 for (Iterator iter= fgAvoidSWTErrorMap.keySet().iterator(); iter.hasNext();) { 136 String key= (String ) iter.next(); 137 fgImageRegistry.put(key, (ImageDescriptor) fgAvoidSWTErrorMap.get(key)); 138 } 139 fgAvoidSWTErrorMap= null; 140 } 141 return fgImageRegistry; 142 } 143 144 146 private static void setImageDescriptors(IAction action, String type, String relPath) { 147 ImageDescriptor id= create("d" + type, relPath, false); if (id != null) 149 action.setDisabledImageDescriptor(id); 150 151 ImageDescriptor descriptor= create("e" + type, relPath, true); action.setHoverImageDescriptor(descriptor); 153 action.setImageDescriptor(descriptor); 154 } 155 156 private static ImageDescriptor createManaged(String prefix, String name) { 157 ImageDescriptor result= create(prefix, name.substring(NAME_PREFIX_LENGTH), true); 158 if (fgAvoidSWTErrorMap == null) { 159 fgAvoidSWTErrorMap= new HashMap (); 160 } 161 fgAvoidSWTErrorMap.put(name, result); 162 if (fgImageRegistry != null) { 163 RefactoringUIPlugin.logErrorMessage("Image registry already defined"); } 165 return result; 166 } 167 168 private static ImageDescriptor createUnManaged(String prefix, String name) { 169 return create(prefix, name, true); 170 } 171 172 179 private static ImageDescriptor create(String prefix, String name, boolean useMissingImageDescriptor) { 180 IPath path= ICONS_PATH.append(prefix).append(name); 181 return createImageDescriptor(RefactoringUIPlugin.getDefault().getBundle(), path, useMissingImageDescriptor); 182 } 183 184 187 private static ImageDescriptor createImageDescriptor(Bundle bundle, IPath path, boolean useMissingImageDescriptor) { 188 URL url= FileLocator.find(bundle, path, null); 189 if (url != null) { 190 return ImageDescriptor.createFromURL(url); 191 } 192 if (useMissingImageDescriptor) { 193 return ImageDescriptor.getMissingImageDescriptor(); 194 } 195 return null; 196 } 197 } 198 | Popular Tags |