use of org.eclipse.jface.resource.ImageRegistry in project archi by archimatetool.
the class ImageFactory method getCompositeImageDescriptor.
/**
* Return a composite image consisting of many images
*
* @param imageNames
* @return
*/
public CompositeImageDescriptor getCompositeImageDescriptor(String[] imageNames) {
// Make a registry name, cached
// $NON-NLS-1$
String key_name = "@";
for (String name : imageNames) {
key_name += name;
}
ImageRegistry registry = fPlugin.getImageRegistry();
CompositeImageDescriptor cid = (CompositeImageDescriptor) registry.getDescriptor(key_name);
// Make it and cache it
if (cid == null) {
ImageDescriptor[] desc = new ImageDescriptor[imageNames.length];
for (int i = 0; i < imageNames.length; i++) {
desc[i] = getImageDescriptor(imageNames[i]);
}
cid = new CompositeMultiImageDescriptor(desc);
registry.put(key_name, cid);
}
return cid;
}
use of org.eclipse.jface.resource.ImageRegistry in project archi by archimatetool.
the class ImageFactory method getImageDescriptor.
/**
* Returns the shared image description represented by the given key.
*
* @param imageName
* the logical name of the image description to retrieve
* @return the shared image description represented by the given name
*/
public ImageDescriptor getImageDescriptor(String imageName) {
if (imageName == null) {
// $NON-NLS-1$
throw new IllegalArgumentException("Image name cannot be null");
}
ImageRegistry registry = fPlugin.getImageRegistry();
ImageDescriptor id = registry.getDescriptor(imageName);
if (id == null) {
id = AbstractUIPlugin.imageDescriptorFromPlugin(fPlugin.getBundle().getSymbolicName(), imageName);
if (id != null) {
// The image will be created next when registry.get(imageName) is called
registry.put(imageName, id);
} else {
// Can be null in the case of overlay images where the image name is a composite name
// System.err.println("Could not get Image Descriptor for: " + imageName); //$NON-NLS-1$
}
}
return id;
}
use of org.eclipse.jface.resource.ImageRegistry in project eclipse.platform.text by eclipse.
the class AnnotationsConfigurationBlock method dispose.
@Override
public void dispose() {
ImageRegistry registry = EditorsPlugin.getDefault().getImageRegistry();
for (Iterator<String> it = fImageKeys.iterator(); it.hasNext(); ) {
String string = it.next();
registry.remove(string);
}
fImageKeys.clear();
}
use of org.eclipse.jface.resource.ImageRegistry in project eclipse.platform.text by eclipse.
the class AnnotationsConfigurationBlock method getImage.
/**
* Returns the image for the given annotation and the given annotation preferences or
* <code>null</code> if there is no such image.
*
* @param preference the annotation preference
* @return the image or <code>null</code>
* @since 3.1
*/
private Image getImage(AnnotationPreference preference) {
ImageRegistry registry = EditorsPlugin.getDefault().getImageRegistry();
String annotationType = (String) preference.getAnnotationType();
if (annotationType == null)
return null;
// $NON-NLS-1$
String customImage = annotationType + "__AnnotationsConfigurationBlock_Image";
Image image;
image = registry.get(customImage);
if (image != null)
return image;
image = registry.get(annotationType);
if (image == null) {
AnnotationPreference delegatingPreference = EditorsPlugin.getDefault().getAnnotationPreferenceLookup().getAnnotationPreference(annotationType);
ImageDescriptor descriptor = delegatingPreference.getImageDescriptor();
if (descriptor != null) {
registry.put(annotationType, descriptor);
image = registry.get(annotationType);
} else {
String symbolicImageName = preference.getSymbolicImageName();
if (symbolicImageName != null) {
String key = DefaultMarkerAnnotationAccess.getSharedImageName(symbolicImageName);
if (key != null) {
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
image = sharedImages.getImage(key);
}
}
}
}
if (image == null)
return null;
// create custom image
// square images
final int SIZE = 16;
ImageData data = image.getImageData();
Image copy;
if (data.height > SIZE || data.width > SIZE) {
// scale down to icon size
copy = new Image(Display.getCurrent(), data.scaledTo(SIZE, SIZE));
} else if (data.height == SIZE && data.width == SIZE) {
// nothing to scale, return the image
return image;
} else {
// don't scale up, but rather copy into the middle and mark everything else transparent
ImageData mask = data.getTransparencyMask();
ImageData resized = new ImageData(SIZE, SIZE, data.depth, data.palette);
ImageData resizedMask = new ImageData(SIZE, SIZE, mask.depth, mask.palette);
int xo = Math.max(0, (SIZE - data.width) / 2);
int yo = Math.max(0, (SIZE - data.height) / 2);
for (int y = 0; y < SIZE; y++) {
for (int x = 0; x < SIZE; x++) {
if (y >= yo && x >= xo && y < yo + data.height && x < xo + data.width) {
resized.setPixel(x, y, data.getPixel(x - xo, y - yo));
resizedMask.setPixel(x, y, mask.getPixel(x - xo, y - yo));
}
}
}
copy = new Image(Display.getCurrent(), resized, resizedMask);
}
fImageKeys.add(customImage);
registry.put(customImage, copy);
return copy;
}
use of org.eclipse.jface.resource.ImageRegistry in project eclipse.platform.text by eclipse.
the class DefaultMarkerAnnotationAccess method getImage.
/**
* Returns the image for the given annotation and the given annotation preferences or
* <code>null</code> if there is no such image.
*
* @param annotation the annotation
* @param preference the annotation preference
* @param annotationType the annotation type
* @return the image or <code>null</code>
* @since 3.0
*/
private Image getImage(Annotation annotation, AnnotationPreference preference, String annotationType) {
if (annotation instanceof AnnotationBag) {
AnnotationBag bag = (AnnotationBag) annotation;
if (!bag.isEmpty())
annotation = bag.iterator().next();
}
ImageRegistry registry = EditorsPlugin.getDefault().getImageRegistry();
IAnnotationImageProvider annotationImageProvider = preference.getAnnotationImageProvider();
if (annotationImageProvider != null) {
Image image = annotationImageProvider.getManagedImage(annotation);
if (image != null)
return image;
String id = annotationImageProvider.getImageDescriptorId(annotation);
if (id != null) {
image = registry.get(id);
if (image == null) {
ImageDescriptor descriptor = annotationImageProvider.getImageDescriptor(id);
registry.put(id, descriptor);
image = registry.get(id);
}
return image;
}
}
if (annotationType == null)
return null;
if (hasQuickFix(annotation)) {
ImageDescriptor quickFixImageDesc = preference.getQuickFixImageDescriptor();
if (quickFixImageDesc != null) {
Image image = registry.get(quickFixImageDesc.toString());
if (image == null) {
registry.put(quickFixImageDesc.toString(), quickFixImageDesc);
image = registry.get(quickFixImageDesc.toString());
}
if (image != null)
return image;
}
}
Image image = registry.get(annotationType);
if (image == null) {
ImageDescriptor descriptor = preference.getImageDescriptor();
if (descriptor != null) {
registry.put(annotationType, descriptor);
image = registry.get(annotationType);
} else {
String symbolicImageName = preference.getSymbolicImageName();
if (symbolicImageName != null) {
String key = getSharedImageName(preference.getSymbolicImageName());
if (key != null) {
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
image = sharedImages.getImage(key);
}
}
}
}
return image;
}
Aggregations