Skip to content

Instantly share code, notes, and snippets.

@theanuradha
Created May 13, 2011 09:26
Show Gist options
  • Select an option

  • Save theanuradha/970249 to your computer and use it in GitHub Desktop.

Select an option

Save theanuradha/970249 to your computer and use it in GitHub Desktop.
Eclipse Image/Overlay Helper
public class AEclipsePluginImages{
private final static ImageRegistry PLUGIN_REGISTRY = new ImageRegistry();
public final static String ICONS_PATH = "icons/"; //$NON-NLS-1$
private static final String PATH_OBJ = ICONS_PATH + "obj16/"; //$NON-NLS-1$
private static final String PATH_LCL = ICONS_PATH + "elcl16/"; //$NON-NLS-1$
private static final String PATH_LCL_DISABLED = ICONS_PATH + "dlcl16/"; //$NON-NLS-1$
public static final ImageDescriptor DESC_MODEL_OVERVIEW = create(PATH_OBJ,
"some_obj.gif"); //$NON-NLS-1$
//..... rest of default image descriptors
private static ImageDescriptor create(String prefix, String name) {
return ImageDescriptor.createFromURL(makeImageURL(prefix, name));
}
public static ImageDescriptor createOverlay(ImageDescriptor base,
ImageDescriptor overlay, int quadrant) {
return new DecorationOverlayIcon(getImage(base), overlay, quadrant);
}
private static URL makeImageURL(String prefix, String name) {
String path = "$nl$/" + prefix + name; //$NON-NLS-1$
return FileLocator.find(APDEditorPlugin.getDefault().getBundle(),
new Path(path), null);
}
public static Image getImage(ImageDescriptor desc) {
String key = String.valueOf(desc.hashCode());
Image image = PLUGIN_REGISTRY.get(key);
if (image == null) {
image = desc.createImage();
PLUGIN_REGISTRY.put(key, image);
}
return image;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment