package org.bundlemaker.core.ui.view.transformationhistory.internal;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
/**
* @author Nils Hartmann (nils@nilshartmann.net)
*
*/
public enum TransformationHistoryImages {
/**
* the "reset history" icon
*/
RESET_ICON("icons/reset.png"),
/** Pin selection */
PIN_SELECTION("icons/pin-selection.png"),
/** Pin Selection */
PIN_SELECTION_DISABLED("icons/pin-selection-add.png"),
/** Undo last Transformation */
UNDO_TRANSFORMATION("icons/undo-transformation.png")
;
/**
* The bundle-relative path to the icon
*/
private final String path;
private TransformationHistoryImages(final String path) {
this.path = path;
}
/**
* Returns an image. Clients do not need to dispose the image, it will be disposed automatically.
*
* @return an {@link Image}
*/
public Image getImage() {
final ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry();
Image image = imageRegistry.get(this.path);
if (image == null) {
addImageDescriptor();
image = imageRegistry.get(this.path);
}
return image;
}
/**
* Returns an image descriptor.
*
* @return an {@link ImageDescriptor}
*/
public ImageDescriptor getImageDescriptor() {
final ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry();
ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(this.path);
if (imageDescriptor == null) {
addImageDescriptor();
imageDescriptor = imageRegistry.getDescriptor(this.path);
}
return imageDescriptor;
}
private void addImageDescriptor() {
final Activator plugin = Activator.getDefault();
final ImageDescriptor id = ImageDescriptor.createFromURL(plugin.getBundle().getEntry(this.path));
plugin.getImageRegistry().put(this.path, id);
}
}