1 11 package org.eclipse.ui.internal.navigator.resources.plugin; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 import java.util.Collections ; 16 17 import org.eclipse.core.runtime.FileLocator; 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 import org.eclipse.jface.resource.ImageRegistry; 22 import org.eclipse.swt.graphics.Image; 23 import org.eclipse.ui.internal.navigator.NavigatorPlugin; 24 25 36 public class NavigatorUIPluginImages { 37 38 private static URL fgIconLocation; 39 40 private final static ImageRegistry NAVIGATORUIPLUGIN_REGISTRY = NavigatorPlugin.getDefault().getImageRegistry(); 42 43 static { 45 String pathSuffix = "icons/full/"; fgIconLocation = FileLocator.find(NavigatorPlugin.getDefault().getBundle(), new Path(pathSuffix), Collections.EMPTY_MAP); 47 } 48 49 56 public static Image get(String key) { 57 return NAVIGATORUIPLUGIN_REGISTRY.get(key); 58 } 59 60 69 private static ImageDescriptor create(String prefix, String name) { 70 return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name)); 71 } 72 73 82 private static URL makeIconFileURL(String prefix, String name) { 83 StringBuffer buffer = new StringBuffer (prefix); 84 buffer.append(name); 85 try { 86 return new URL (fgIconLocation, buffer.toString()); 87 } catch (MalformedURLException ex) { 88 89 return null; 90 } 91 } 92 93 102 public static void setLocalImageDescriptors(IAction action, String iconName) { 103 setImageDescriptors(action, "lcl16/", iconName); } 105 106 116 public static void setImageDescriptors(IAction action, String type, String relPath) { 117 action.setImageDescriptor(create("e" + type, relPath)); } 124 125 } 126 | Popular Tags |