ResourceManager parentResourceManager = JFaceResources.getResources();
if (widget instanceof ToolItem) {
if (USE_COLOR_ICONS) {
ImageDescriptor image = action.getHoverImageDescriptor();
if (image == null) {
image = action.getImageDescriptor();
}
ImageDescriptor disabledImage = action
.getDisabledImageDescriptor();
// Make sure there is a valid image.
if (image == null && forceImage) {
image = ImageDescriptor.getMissingImageDescriptor();
}
LocalResourceManager localManager = new LocalResourceManager(
parentResourceManager);
// performance: more efficient in SWT to set disabled and hot
// image before regular image
((ToolItem) widget)
.setDisabledImage(disabledImage == null ? null
: localManager
.createImageWithDefault(disabledImage));
((ToolItem) widget).setImage(image == null ? null
: localManager.createImageWithDefault(image));
disposeOldImages();
imageManager = localManager;
return image != null;
}
ImageDescriptor image = action.getImageDescriptor();
ImageDescriptor hoverImage = action.getHoverImageDescriptor();
ImageDescriptor disabledImage = action.getDisabledImageDescriptor();
// If there is no regular image, but there is a hover image,
// convert the hover image to gray and use it as the regular image.
if (image == null && hoverImage != null) {
image = ImageDescriptor.createWithFlags(action
.getHoverImageDescriptor(), SWT.IMAGE_GRAY);
} else {
// If there is no hover image, use the regular image as the
// hover image,
// and convert the regular image to gray
if (hoverImage == null && image != null) {
hoverImage = image;
image = ImageDescriptor.createWithFlags(action
.getImageDescriptor(), SWT.IMAGE_GRAY);
}
}
// Make sure there is a valid image.
if (hoverImage == null && image == null && forceImage) {
image = ImageDescriptor.getMissingImageDescriptor();
}
// Create a local resource manager to remember the images we've
// allocated for this tool item
LocalResourceManager localManager = new LocalResourceManager(
parentResourceManager);
// performance: more efficient in SWT to set disabled and hot image
// before regular image
((ToolItem) widget).setDisabledImage(disabledImage == null ? null
: localManager.createImageWithDefault(disabledImage));
((ToolItem) widget).setHotImage(hoverImage == null ? null
: localManager.createImageWithDefault(hoverImage));
((ToolItem) widget).setImage(image == null ? null : localManager
.createImageWithDefault(image));
// Now that we're no longer referencing the old images, clear them
// out.
disposeOldImages();
imageManager = localManager;
return image != null;
} else if (widget instanceof Item || widget instanceof Button) {
// Use hover image if there is one, otherwise use regular image.
ImageDescriptor image = action.getHoverImageDescriptor();
if (image == null) {
image = action.getImageDescriptor();
}
// Make sure there is a valid image.
if (image == null && forceImage) {