Example usage for org.eclipse.jface.resource ImageDescriptor createFromImageData

List of usage examples for org.eclipse.jface.resource ImageDescriptor createFromImageData

Introduction

In this page you can find the example usage for org.eclipse.jface.resource ImageDescriptor createFromImageData.

Prototype

@Deprecated
public static ImageDescriptor createFromImageData(ImageData data) 

Source Link

Document

Creates and returns a new image descriptor given ImageData describing the image.

Usage

From source file:com.nokia.tools.screen.ui.views.ResourcePositionViewer.java

License:Open Source License

protected ImageDescriptor createImageDescriptor(IContentData data) {
    if (rectProvider == null) {
        return null;
    } else {/*from w  ww .  j  a  va  2s .c o m*/
        IContentData firstChild = data.getChildren()[0];
        IContentData screen = ScreenUtil.getScreenForData(firstChild, false);

        java.awt.Rectangle awtRec;
        if (screen != null) {
            awtRec = (java.awt.Rectangle) screen.getAttribute(ContentAttribute.BOUNDS.name());
        } else {
            awtRec = rectProvider.getResolution(data);
        }
        double scale = awtRec.width / (double) width;
        Rectangle resolutionRectangle = changeRec(awtRec, scale);

        java.awt.Rectangle dataRec = (java.awt.Rectangle) firstChild
                .getAttribute(ContentAttribute.BOUNDS.name());
        if (dataRec == null) {
            dataRec = rectProvider.getCategoryHighlightRect(data);
        }
        Rectangle rec = changeRec(dataRec, scale);
        rec.width = Math.max(2, rec.width);
        rec.height = Math.max(2, rec.height);

        Rectangle recSize = new Rectangle(0, 0, resolutionRectangle.width + 2, resolutionRectangle.height + 2);
        Rectangle border1 = new Rectangle(1, 1, resolutionRectangle.width, resolutionRectangle.height);

        Image image = new Image(Display.getDefault(), recSize);
        GC gc = new GC(image);
        gc.setBackground(Display.getDefault()
                .getSystemColor(new Boolean((String) data.getAttribute(ContentAttribute.MODIFIED.name()))
                        ? IIDEConstants.COLOR_OVERRIDE
                        : COLOR));
        gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));
        gc.fillRectangle(rec);
        gc.drawRectangle(border1);
        gc.dispose();
        ImageData imageData = image.getImageData();
        image.dispose();

        ImageDescriptor descriptor = ImageDescriptor.createFromImageData(imageData);
        addImageDescriptorToDispose(descriptor);
        return descriptor;
    }

}

From source file:com.nokia.tools.ui.branding.defaultimpl.BrandingManager.java

License:Open Source License

/**
 * //from  www  .ja  va2 s. co m
 * @see com.nokia.tools.screen.ui.branding.IBrandingManager#getBannerImageDescriptor(org.eclipse.jface.resource.ImageDescriptor)
 */
public ImageDescriptor getBannerImageDescriptor(ImageDescriptor icon) {
    ImageDescriptor desc = Activator.getImageDescriptor("icons/dialog_banner_150x66.bmp");

    if (icon != null) {
        Image bannerImage = null;
        Image iconImage = null;
        GC imageGC = null;

        try {
            bannerImage = desc.createImage();
            iconImage = icon.createImage();
            imageGC = new GC(bannerImage);
            imageGC.drawImage(iconImage,
                    (int) ((bannerImage.getBounds().width - 17) - iconImage.getBounds().width),
                    (int) (33 - (iconImage.getBounds().height / 2)));
            return ImageDescriptor.createFromImageData(bannerImage.getImageData());
        } finally {
            if (imageGC != null) {
                imageGC.dispose();
            }
            if (bannerImage != null) {
                bannerImage.dispose();
            }
            if (iconImage != null) {
                iconImage.dispose();
            }
        }
    }
    return desc;
}

From source file:com.nokia.tools.variant.preview.PluginImages.java

License:Open Source License

/**
 * Preloads image into backbuffer and then wraps into
 * {@link ImageDescriptor}//from   w ww  .ja va  2s .c om
 * 
 * @param name
 *            image name
 * @return
 */
private static ImageDescriptor loadImage(String name) {
    URL entry = null;
    ImageData id = null;
    try {
        entry = ContentPreviewPlugin.getDefault().getBundle().getEntry("icons/player/" + name);
        id = new ImageData(entry.openStream());
        return ImageDescriptor.createFromImageData(id);
    } catch (Exception ex) {
        ContentPreviewPlugin.logError("Failed to load icon " + name, ex);
        return null;
    } finally {
        if (id != null) {
            id = null;
        }
        if (entry != null) {
            entry = null;
        }
    }
}

From source file:com.sap.dirigible.ide.workspace.wizard.project.create.ProjectTemplateType.java

License:Open Source License

private static Image createImage(byte[] data) {
    ImageDescriptor imageDescriptor = ImageDescriptor
            .createFromImageData(new ImageData(new ByteArrayInputStream(data)));
    return resourceManager.createImage(imageDescriptor);
}

From source file:com.siteview.mde.internal.ui.util.SharedLabelProvider.java

License:Open Source License

public Image getImageFromPlugin(IMonitorModelBase model, String relativePath) {
    String platform = "platform:/plugin/"; //$NON-NLS-1$
    if (relativePath.startsWith(platform)) {
        relativePath = relativePath.substring(platform.length());
        int index = relativePath.indexOf('/');
        if (index == -1)
            return null;
        model = MonitorRegistry.findModel(relativePath.substring(0, index));
        if (model == null)
            return null;
        relativePath = relativePath.substring(index + 1);
    }/*from   w ww. j  a va2 s  . co m*/

    String location = model.getInstallLocation();
    if (location == null)
        return null;

    File pluginLocation = new File(location);
    InputStream stream = null;
    ZipFile jarFile = null;
    try {
        if (pluginLocation.isDirectory()) {
            File file = new File(pluginLocation, relativePath);
            if (file.exists())
                stream = new FileInputStream(file);
            else if (relativePath.length() > 5 && relativePath.startsWith("$nl$/")) { //$NON-NLS-1$
                file = new File(pluginLocation, relativePath.substring(5));
                if (file.exists())
                    stream = new FileInputStream(file);
            }
        } else {
            jarFile = new ZipFile(pluginLocation, ZipFile.OPEN_READ);
            ZipEntry manifestEntry = jarFile.getEntry(relativePath);
            if (manifestEntry != null) {
                stream = jarFile.getInputStream(manifestEntry);
            } else if (relativePath.length() > 5 && relativePath.startsWith("$nl$/")) { //$NON-NLS-1$
                manifestEntry = jarFile.getEntry(relativePath.substring(5));
                if (manifestEntry != null) {
                    stream = jarFile.getInputStream(manifestEntry);
                }
            }
        }
        if (stream != null) {
            ImageDescriptor desc = ImageDescriptor.createFromImageData(new ImageData(stream));
            return get(desc);
        }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    } finally {
        try {
            if (stream != null)
                stream.close();
            if (jarFile != null)
                jarFile.close();
        } catch (IOException e) {
        }
    }
    return getBlankImage();
}

From source file:com.smartmonkey.recrep.actions.ImageHelper.java

License:Apache License

public static ImageDescriptor loadImageDescriptorFromResource(String path) {
    InputStream is = ImageHelper.class.getClassLoader().getResourceAsStream(path);
    if (is != null) {
        ImageData[] data = null;// w  w  w . j  ava 2s  .c o  m
        try {
            data = new ImageLoader().load(is);
        } catch (SWTException e) {
        }
        if (data != null && data.length > 0) {
            return ImageDescriptor.createFromImageData(data[0]);
        }
    }
    return null;
}

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

License:Open Source License

public static ImageDescriptor createImageDescriptor(String key, ImageData imageData) {
    try {//from   w w w.  j  av a2  s  . c  o 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:de.fhg.igd.swingrcp.ActionAdapter.java

License:Open Source License

/**
 * Set the actions icon as {@link ImageDescriptor} if possible
 *//*ww  w. ja  va2  s  .  co m*/
@SuppressWarnings("deprecation")
private void loadImage() {
    Object icon = action.getValue(javax.swing.Action.SMALL_ICON);

    if (icon instanceof ImageIcon) {
        try {
            setImageDescriptor(
                    ImageDescriptor.createFromImageData(SwingRCPUtilities.convertToSWT((ImageIcon) icon)));
        } catch (Exception e) {
            log.warn("Error converting action icon", e);
        }
    }
}

From source file:eu.esdihumboldt.hale.ui.util.swing.RcpActionAdapter.java

License:Open Source License

/**
 * Set the actions icon as {@link ImageDescriptor} if possible
 *///www .j  ava  2 s .  co  m
private void loadImage() {
    Object icon = action.getValue(javax.swing.Action.SMALL_ICON);

    if (icon instanceof ImageIcon) {
        try {
            setImageDescriptor(
                    ImageDescriptor.createFromImageData(SwingRcpUtilities.convertToSWT((ImageIcon) icon)));
        } catch (Exception e) {
            _log.warn("Error converting action icon", e); //$NON-NLS-1$
        }
    }
}

From source file:hydrograph.ui.common.util.ImagePathConstant.java

License:Apache License

/**
 * Returns Image from image registry//ww  w  . ja  v a 2  s  .c  o  m
 * 
 * @return
 */
public Image getImageFromRegistry() {
    Image image = IMAGE_REGISTRY.get(this.value);
    if (image == null) {
        ImageData imageData = new ImageData(XMLConfigUtil.CONFIG_FILES_PATH + this.value);
        IMAGE_REGISTRY.put(this.value, ImageDescriptor.createFromImageData(imageData));
    }
    return IMAGE_REGISTRY.get(value);
}