Search in sources :

Example 6 with ImageRegistry

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;
}
Also used : ImageRegistry(org.eclipse.jface.resource.ImageRegistry) CompositeImageDescriptor(org.eclipse.jface.resource.CompositeImageDescriptor) CompositeImageDescriptor(org.eclipse.jface.resource.CompositeImageDescriptor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) CompositeMultiImageDescriptor(com.archimatetool.editor.ui.components.CompositeMultiImageDescriptor) CompositeMultiImageDescriptor(com.archimatetool.editor.ui.components.CompositeMultiImageDescriptor)

Example 7 with ImageRegistry

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;
}
Also used : ImageRegistry(org.eclipse.jface.resource.ImageRegistry) CompositeImageDescriptor(org.eclipse.jface.resource.CompositeImageDescriptor) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) CompositeMultiImageDescriptor(com.archimatetool.editor.ui.components.CompositeMultiImageDescriptor)

Example 8 with ImageRegistry

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();
}
Also used : ImageRegistry(org.eclipse.jface.resource.ImageRegistry)

Example 9 with ImageRegistry

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;
}
Also used : ImageRegistry(org.eclipse.jface.resource.ImageRegistry) ISharedImages(org.eclipse.ui.ISharedImages) ImageData(org.eclipse.swt.graphics.ImageData) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference)

Example 10 with ImageRegistry

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;
}
Also used : AnnotationBag(org.eclipse.jface.text.source.projection.AnnotationBag) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) ISharedImages(org.eclipse.ui.ISharedImages) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image)

Aggregations

ImageRegistry (org.eclipse.jface.resource.ImageRegistry)63 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)25 Image (org.eclipse.swt.graphics.Image)22 URL (java.net.URL)4 ResourceBundle (java.util.ResourceBundle)4 Before (org.junit.Before)4 CoreRuntimePlugin (org.talend.core.runtime.CoreRuntimePlugin)4 CompositeMultiImageDescriptor (com.archimatetool.editor.ui.components.CompositeMultiImageDescriptor)3 ResourceImageDescriptor (de.jaret.util.ui.ResourceImageDescriptor)3 CompositeImageDescriptor (org.eclipse.jface.resource.CompositeImageDescriptor)3 Label (org.eclipse.swt.widgets.Label)3 RepositoryContext (org.talend.core.context.RepositoryContext)3 Project (org.talend.core.model.general.Project)3 User (org.talend.core.model.properties.User)3 IRepositoryFactory (org.talend.core.repository.model.IRepositoryFactory)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 XmiResourceManager (org.talend.core.repository.utils.XmiResourceManager)3 IRepositoryNodeConfiguration (org.talend.mdm.repository.core.IRepositoryNodeConfiguration)3 IRepositoryNodeResourceProvider (org.talend.mdm.repository.core.IRepositoryNodeResourceProvider)3 RecycleBinNodeConfiguration (org.talend.mdm.repository.core.impl.recyclebin.RecycleBinNodeConfiguration)3