Example usage for org.eclipse.jface.resource ImageRegistry remove

List of usage examples for org.eclipse.jface.resource ImageRegistry remove

Introduction

In this page you can find the example usage for org.eclipse.jface.resource ImageRegistry remove.

Prototype

public void remove(String key) 

Source Link

Document

Removes an image from this registry.

Usage

From source file:com.agynamix.simidude.clipboard.FileClipboardItem.java

License:Open Source License

public IClipboardItem deleteContents() {
    sourceData.deleteContents();/*from w  ww.  ja  va2  s .c om*/
    ImageRegistry imReg = ApplicationBase.getContext().getImageRegistry();
    imReg.remove(sourceData.getSourceId().toString());
    imReg.remove(sourceData.getSourceId().toString() + "-download-needed");
    return this;
}

From source file:com.agynamix.simidude.clipboard.ImageClipboardItem.java

License:Open Source License

public IClipboardItem deleteContents() {
    sourceData.deleteContents();/*ww  w .  j a  va  2 s.  c om*/
    if (cachedThumbnail != null) {
        cachedThumbnail = null;
        ImageRegistry imReg = ApplicationBase.getContext().getImageRegistry();
        imReg.remove(sourceData.getSourceId().toString());
    }
    tooltip = "";
    return this;
}

From source file:com.aptana.ide.ui.io.ImageUtils.java

License:Open Source License

public static ImageDescriptor getImageDescriptor(File file) {
    if (file.isFile()) {
        ImageDescriptor imageDescriptor = PlatformUI.getWorkbench().getEditorRegistry()
                .getImageDescriptor(file.getName());
        if (imageDescriptor != null) {
            return imageDescriptor;
        }//from www  .ja va 2  s.  com
    }
    if (file.exists()) {
        if (jFileChooser == null) {
            jFileChooser = new javax.swing.JFileChooser();
        }
        String fileType = jFileChooser.getTypeDescription(file);
        if (fileType == null || fileType.length() == 0 || "Directory".equals(fileType) //$NON-NLS-1$
                || "System Folder".equals(fileType) || "Generic File".equals(fileType)) { //$NON-NLS-1$ //$NON-NLS-2$
            String name = file.getName();
            try {
                name = file.getCanonicalFile().getName();
            } catch (IOException e) {
                name = file.getName();
            }
            if (name.equals((new Path(DESKTOP)).lastSegment())) {
                fileType = "Desktop"; //$NON-NLS-1$
            } else if (!file.isDirectory()) {
                int index = name.lastIndexOf('.');
                if (index >= 0 && index < name.length() - 1) {
                    fileType = name.substring(index + 1);
                } else {
                    fileType = "unknown"; //$NON-NLS-1$
                }
            } else if ("Directory".equals(fileType) || name.length() == 0) { //$NON-NLS-1$
                fileType = file.getAbsolutePath();
            } else if ("System Folder".equals(fileType)) { //$NON-NLS-1$
                if (file.getAbsolutePath().equals(USER_HOME)) {
                    fileType = "UserHome"; //$NON-NLS-1$
                }
            }
        }
        String imageKey = "os.fileType_" + fileType; //$NON-NLS-1$

        ImageRegistry imageRegistry = JFaceResources.getImageRegistry();
        if (resetMap.get(imageKey) != null && resetMap.get(imageKey)) {
            imageRegistry.remove(imageKey);
            resetMap.remove(imageKey);
        }
        ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(imageKey);
        if (imageDescriptor != null) {
            return imageDescriptor;
        }

        Icon icon;
        if (ON_WINDOWS) {
            icon = FileSystemView.getFileSystemView().getSystemIcon(file);
        } else {
            icon = jFileChooser.getIcon(file);
        }
        if (icon != null) {
            String existingImageKey = iconToKeyMap.get(icon);
            if (existingImageKey != null) {
                imageDescriptor = imageRegistry.getDescriptor(existingImageKey);
                if (imageDescriptor != null) {
                    return imageDescriptor;
                }
            }
            ImageData imageData = awtImageIconToSWTImageData(icon, null);
            if (imageData != null) {
                imageDescriptor = ImageDescriptor.createFromImageData(imageData);
                imageRegistry.put(imageKey, imageDescriptor);
                iconToKeyMap.put(icon, imageKey);
                resetMap.put(imageKey, false);
                return imageRegistry.getDescriptor(imageKey);
            }
        }
    }
    return getImageDescriptor(file.getName());
}

From source file:com.rcpcompany.utils.jface.ActivatorUtils.java

License:Open Source License

/**
 * Removes a single image from JFaceResources.
 * //from   w ww.ja  va2  s  .c o m
 * @param name the name of the image
 */
public static void removeImage(final String name) {
    asyncExec(new Runnable() {
        @Override
        public void run() {
            final ImageRegistry ir = JFaceResources.getImageRegistry();
            ir.remove(name);
        }
    });
}

From source file:com.sonatype.buildserver.eclipse.ui.HudsonImages.java

License:Open Source License

public static ImageDescriptor createImageDescriptor(String key, ImageData imageData) {
    try {/* w w  w  .j a  v  a2s. co  m*/
        ImageRegistry imageRegistry = getImageRegistry();
        if (imageRegistry != null) {
            ImageDescriptor imageDescriptor = imageRegistry.getDescriptor(key);
            if (imageDescriptor != null) {
                imageRegistry.remove(key);
            }
            {
                imageDescriptor = ImageDescriptor.createFromImageData(imageData);
                imageRegistry.put(key, imageDescriptor);
            }
            return imageDescriptor;
        }
    } catch (Exception ex) {
        log.error(key, ex);
    }
    return null;
}

From source file:gov.nasa.ensemble.common.ui.image.CheckboxImages.java

License:Open Source License

private static void put(ImageRegistry registry, String key, Image image) {
    registry.remove(key);
    registry.put(key, image);
}

From source file:net.refractions.udig.catalog.ui.ResolveTitlesDecorator.java

License:Open Source License

public Image decorateImage(Image image, Object element) {
    if (disposed)
        return null;
    if (!(element instanceof IResolve))
        return null;

    IResolve resolve = (IResolve) element;

    if (images.containsKey(element)) {
        LabelData data = images.get(element);
        // if data is null then it is being loaded already so return
        if (data == null)
            return null;
    }//www.j av a  2s .  c  om

    // look image up in registry to see if it is already loaded
    ImageRegistry imageRegistry = CatalogUIPlugin.getDefault().getImageRegistry();
    Image i;
    synchronized (imageRegistry) {
        i = imageRegistry.get(resolve.getIdentifier().toString());
        // if it is loaded and not disposed then we're good, return it.
        if (i != null && !i.isDisposed()) {
            return i;
        }

        if (i != null && i.isDisposed())
            imageRegistry.remove(resolve.getIdentifier().toString());
    }

    // we tried to look up a cached version... If not around and viewer doesn't want decorated images then we'll return.

    if (!resolve.getID().isLocal() && !decorateImages) {
        return null;
    }

    // put an element in the map so that it will not be loaded again.
    images.put(resolve, null);

    // put resolve in queue for loading
    imagesToDecorate.offer(resolve);
    synchronized (imageRegistry) {
        // get a worker for loading images and schedule it.  
        // If pool is empty then don't worry request will be processed.
        UpdateLabel imageWorker = availableImageWorkers.poll();
        if (imageWorker != null)
            imageWorker.schedule();
    }
    return null;

}

From source file:org.bonitasoft.studio.pics.Pics.java

License:Open Source License

public static Image getImage(String imageName, AbstractUIPlugin plugin) {
    ImageRegistry reg = plugin.getImageRegistry();

    Image result = reg.get(imageName);

    if (result != null && !result.isDisposed()) {//prevent from bad dispose
        return result;
    }/*from ww w.  j a  va2  s .c om*/

    ImageDescriptor descriptor = getImageDescriptor(imageName, plugin);
    if (descriptor != null) {
        result = descriptor.createImage();
    }

    reg.remove(imageName);
    if (result != null) {
        reg.put(imageName, result);
    }

    return result;
}

From source file:org.bonitasoft.studio.pics.Pics.java

License:Open Source License

/**
 *  get the system image resized in 16x16 (only used in connectors label provider)
 * @param id/*from w ww  .  ja  va  2 s .c om*/
 * @return
 */
public static Image getSystemImage(int id) {
    ImageRegistry reg = plugin.getImageRegistry();

    String imageName = id + "";
    Image result = reg.get(imageName);

    if (result != null && !result.isDisposed()) {//prevent from bad dispose
        return result;
    }
    result = Display.getCurrent().getSystemImage(id);
    Image scaled = new Image(Display.getDefault(), 16, 16);
    GC gc = new GC(scaled);
    gc.setAntialias(SWT.ON);
    gc.setInterpolation(SWT.HIGH);
    gc.drawImage(result, 0, 0, result.getBounds().width, result.getBounds().height, 0, 0, 16, 16);
    gc.dispose();
    result = scaled;
    reg.remove(imageName);
    reg.put(imageName, result);
    return result;
}

From source file:org.eclipse.bpel.common.ui.CommonUIPlugin.java

License:Open Source License

/**
 * Initializes the table of images used in this plugin.
 *///w  ww .ja  va  2s.  c  o  m
private void initializeImages(Display display) {
    URL baseURL = getBundle().getEntry("/"); //$NON-NLS-1$

    // A little reflection magic ... so that we don't
    // have to add the createImageDescriptor every time
    // we add it to the IBPELUIConstants ..
    Field fields[] = ICommonUIConstants.class.getFields();
    for (int i = 0; i < fields.length; i++) {
        Field f = fields[i];
        if (f.getType() != String.class) {
            continue;
        }
        String name = f.getName();
        if (name.startsWith("ICON_") || name.startsWith("CURSOR_")) { //$NON-NLS-1$ //$NON-NLS-2$
            try {
                String value = (String) f.get(null);
                createImageDescriptor(value, baseURL);
            } catch (Exception e) {
                log(e);
            }
        }
    }

    //   tray buttons
    ImageRegistry registry = getImageRegistry();
    ImageDescriptor desc = registry.getDescriptor(ICommonUIConstants.ICON_TRAY_EXPAND_ARROW);

    registry.remove(ICommonUIConstants.ICON_KEY_TRAY_COLLAPSE_BUTTON);
    registry.remove(ICommonUIConstants.ICON_KEY_TRAY_EXPAND_BUTTON);

    registry.put(ICommonUIConstants.ICON_KEY_TRAY_COLLAPSE_BUTTON, desc.createImage());
    ImageData data = ImageUtils.flip(desc.getImageData());
    registry.put(ICommonUIConstants.ICON_KEY_TRAY_EXPAND_BUTTON, new Image(display, data));
}