1 11 package org.eclipse.search.internal.ui; 12 13 import java.net.URL ; 14 15 import org.eclipse.core.runtime.FileLocator; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 19 import org.eclipse.swt.graphics.Image; 20 21 import org.eclipse.jface.action.IAction; 22 import org.eclipse.jface.resource.ImageDescriptor; 23 import org.eclipse.jface.resource.ImageRegistry; 24 25 import org.osgi.framework.Bundle; 26 27 30 public class SearchPluginImages { 31 32 private final static ImageRegistry PLUGIN_REGISTRY= SearchPlugin.getDefault().getImageRegistry(); 34 35 private static final IPath ICONS_PATH= new Path("$nl$/icons/full"); 37 public static final String T_OBJ= "obj16/"; public static final String T_WIZBAN= "wizban/"; public static final String T_LCL= "lcl16/"; public static final String T_TOOL= "tool16/"; public static final String T_EVIEW= "eview16/"; 43 private static final String NAME_PREFIX= "org.eclipse.search.ui."; private static final int NAME_PREFIX_LENGTH= NAME_PREFIX.length(); 45 46 public static final String IMG_TOOL_SEARCH= NAME_PREFIX + "search.gif"; 49 public static final String IMG_LCL_SEARCH_AGAIN= NAME_PREFIX + "search_again.gif"; public static final String IMG_LCL_PIN_VIEW= NAME_PREFIX + "pin_view.gif"; 52 public static final String IMG_LCL_SEARCH_REM= NAME_PREFIX + "search_rem.gif"; public static final String IMG_LCL_SEARCH_REM_ALL= NAME_PREFIX + "search_remall.gif"; public static final String IMG_LCL_SEARCH_NEXT= NAME_PREFIX + "search_next.gif"; public static final String IMG_LCL_SEARCH_PREV= NAME_PREFIX + "search_prev.gif"; public static final String IMG_LCL_SEARCH_GOTO= NAME_PREFIX + "search_goto.gif"; public static final String IMG_LCL_SEARCH_SORT= NAME_PREFIX + "search_sortmatch.gif"; public static final String IMG_LCL_SEARCH_HISTORY= NAME_PREFIX + "search_history.gif"; public static final String IMG_LCL_SEARCH_FLAT_LAYOUT= NAME_PREFIX + "flatLayout.gif"; public static final String IMG_LCL_SEARCH_HIERARCHICAL_LAYOUT= NAME_PREFIX + "hierarchicalLayout.gif"; public static final String IMG_LCL_SEARCH_HORIZONTAL_ORIENTATION= NAME_PREFIX + "horizontalOrientation.gif"; public static final String IMG_LCL_SEARCH_VERTICAL_ORIENTATION= NAME_PREFIX + "verticalOrientation.gif"; public static final String IMG_LCL_SEARCH_AUTOMATIC_ORIENTATION= NAME_PREFIX + "automaticOrientation.gif"; public static final String IMG_LCL_SEARCH_SINGLE_ORIENTATION= NAME_PREFIX + "singleOrientation.gif"; public static final String IMG_LCL_SEARCH_CANCEL= NAME_PREFIX + "stop.gif"; public static final String IMG_LCL_SEARCH_COLLAPSE_ALL= NAME_PREFIX + "collapseall.gif"; public static final String IMG_LCL_SEARCH_EXPAND_ALL= NAME_PREFIX + "expandall.gif"; public static final String IMG_LCL_SEARCH_FILTER= NAME_PREFIX + "filter_ps.gif"; public static final String IMG_VIEW_SEARCHRES= NAME_PREFIX + "searchres.gif"; 71 public static final String IMG_OBJ_TSEARCH_DPDN= NAME_PREFIX + "tsearch_dpdn_obj.gif"; public static final String IMG_OBJ_SEARCHMARKER= NAME_PREFIX + "searchm_obj.gif"; public static final String IMG_OBJ_TEXT_SEARCH_LINE= NAME_PREFIX + "line_match.gif"; 75 public static final ImageDescriptor DESC_OBJ_TSEARCH_DPDN= createManaged(T_OBJ, IMG_OBJ_TSEARCH_DPDN); 77 public static final ImageDescriptor DESC_OBJ_SEARCHMARKER= createManaged(T_OBJ, IMG_OBJ_SEARCHMARKER); 78 public static final ImageDescriptor DESC_OBJ_TEXT_SEARCH_LINE= createManaged(T_OBJ, IMG_OBJ_TEXT_SEARCH_LINE); 79 public static final ImageDescriptor DESC_VIEW_SEARCHRES= createManaged(T_EVIEW, IMG_VIEW_SEARCHRES); 80 81 public static Image get(String key) { 82 return PLUGIN_REGISTRY.get(key); 83 } 84 85 private static ImageDescriptor createManaged(String prefix, String name) { 86 ImageDescriptor result= create(prefix, name.substring(NAME_PREFIX_LENGTH), true); 87 PLUGIN_REGISTRY.put(name, result); 88 return result; 89 } 90 91 98 private static ImageDescriptor create(String prefix, String name, boolean useMissingImageDescriptor) { 99 IPath path= ICONS_PATH.append(prefix).append(name); 100 return createImageDescriptor(SearchPlugin.getDefault().getBundle(), path, useMissingImageDescriptor); 101 } 102 103 106 public static void setImageDescriptors(IAction action, String type, String relPath) { 107 relPath= relPath.substring(NAME_PREFIX_LENGTH); 108 109 action.setDisabledImageDescriptor(create("d" + type, relPath, false)); 111 ImageDescriptor desc= create("e" + type, relPath, true); action.setHoverImageDescriptor(desc); 113 action.setImageDescriptor(desc); 114 } 115 116 123 public static ImageDescriptor createImageDescriptor(Bundle bundle, IPath path, boolean useMissingImageDescriptor) { 124 URL url= FileLocator.find(bundle, path, null); 125 if (url != null) { 126 return ImageDescriptor.createFromURL(url); 127 } 128 if (useMissingImageDescriptor) { 129 return ImageDescriptor.getMissingImageDescriptor(); 130 } 131 return null; 132 } 133 134 } 135 | Popular Tags |