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

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

Introduction

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

Prototype

public Image createImage() 

Source Link

Document

Creates and returns a new SWT image for this image descriptor.

Usage

From source file:net.refractions.udig.catalog.internal.wms.WMSGeoResourceImpl.java

License:Open Source License

/**
 * This method will fetch the Icon associated with this url (if such is available).
 * /*from  w  ww. j  a  v  a  2s.c o  m*/
 * @see WMSFolder
 * @param monitor
 * @return Requested Icon or ISharedImages.GRID_OBJ
 */
protected static ImageDescriptor fetchIcon(IProgressMonitor monitor, Layer layer, WMSServiceImpl service) {
    try {
        if (monitor != null)
            monitor.beginTask(Messages.WMSGeoResourceImpl_acquiring_task, 3);
        if (monitor != null)
            monitor.worked(1);

        if (layer.getChildren() != null && layer.getChildren().length != 0) {
            // Do not request "parent" layer graphics - this kills Mapserver
            return CatalogUIPlugin.getDefault().getImageDescriptor(ISharedImages.GRID_OBJ);
        }

        ImageDescriptor imageDescriptor = requestImage(monitor, layer, service);

        Image image = null;
        Image swatch = null;
        try {
            if (monitor != null)
                monitor.worked(2);
            if (monitor != null)
                monitor.subTask(Messages.WMSGeoResourceImpl_downloading_icon);
            image = imageDescriptor.createImage();
            Rectangle bound = image.getBounds();
            if (bound.width == 16 && bound.height == 16) {
                // perfect! it did what was expected!
                //
                final ImageData data = (ImageData) image.getImageData().clone();
                return new ImageDescriptor() {
                    public ImageData getImageData() {
                        return (ImageData) data.clone();
                    }
                };
            }
            if (bound.height < 16 || bound.width < 16) {
                // the image is smaller than what we asked for
                // perhaps we should display nothing?
                // in stead we will try scaling it up
                if (WmsPlugin.getDefault().isDebugging()) {
                    System.out.println("Icon scaled up to requested size"); //$NON-NLS-1$                                        
                }
                final ImageData data = image.getImageData().scaledTo(16, 16);
                return new ImageDescriptor() {
                    public ImageData getImageData() {
                        return (ImageData) data.clone();
                    }
                };
            }
            // the image is larger than the size we asked for
            // (so this WMS is not being nice!)
            // we will try and decide what to do here ...
            // let us select the image we want ...

            swatch = new Image(null, 16, 16);
            GC gc = new GC(swatch);
            int sy = 0; // (bound.height / 2 ) - 8;
            int sx = 0;
            int sw = 0;
            int sh = 0;
            ImageData contents = image.getImageData();
            if (contents == null) {
                return CatalogUIPlugin.getDefault().getImageDescriptor(ISharedImages.GRID_MISSING);
            }
            if (contents.maskData != null) {
                // ((width + 7) / 8 + (maskPad - 1)) / maskPad * maskPad
                int maskPad = contents.maskPad;
                int scanLine = ((contents.width + 7) / 8 + (maskPad - 1)) / maskPad * maskPad;
                // skip leading mask ...
                SKIPY: for (int y = 0; y < contents.height / 2; y++) {
                    sy = y;
                    for (int x = 0; x < contents.width / 2; x++) {
                        int mask = contents.maskData[y * scanLine + x];
                        if (mask != 0)
                            break SKIPY;
                    }
                }
                SKIPX: for (int x = 0; x < contents.width / 2; x++) {
                    sx = x;
                    for (int y = sy; y < contents.height / 2; y++) {
                        int mask = contents.maskData[y * scanLine + x];
                        if (mask != 0)
                            break SKIPX;
                    }
                }
                sh = Math.min(contents.height - sy, 16);
                sw = Math.min(contents.width - sx, 16);
                if (WmsPlugin.getDefault().isDebugging())
                    System.out.println("Mask offset to " + sx + "x" + sy); //$NON-NLS-1$ //$NON-NLS-2$                        
            } else if (contents.alphaData != null) {
                SKIPY: for (int y = 0; y < contents.height / 2; y++) {
                    sy = y;
                    for (int x = 0; x < contents.width / 2; x++) {
                        int alpha = contents.alphaData[y * contents.width + x];
                        if (alpha != 0)
                            break SKIPY;
                    }
                }
                SKIPX: for (int x = 0; x < contents.width / 2; x++) {
                    sx = x;
                    for (int y = sy; y < contents.height / 2; y++) {
                        int alpha = contents.alphaData[y * contents.width + x];
                        if (alpha != 0)
                            break SKIPX;
                    }
                }
                sh = Math.min(contents.height - sy, 16);
                sw = Math.min(contents.width - sx, 16);
                if (WmsPlugin.getDefault().isDebugging())
                    System.out.println("Alpha offset to " + sx + "x" + sy); //$NON-NLS-1$ //$NON-NLS-2$                        
            } else {
                // try ignoring "white"
                int depth = contents.depth;
                int scanLine = contents.bytesPerLine;
                SKIPY: for (int y = 0; y < contents.height / 2; y++) {
                    sy = y;
                    for (int x = 0; x < contents.width / 2; x++) {
                        int datum = contents.data[y * scanLine + x * depth];
                        if (datum != 0)
                            break SKIPY;
                    }
                }
                SKIPX: for (int x = 0; x < contents.width / 2; x++) {
                    sx = x;
                    for (int y = sy; y < contents.height / 2; y++) {
                        int datum = contents.data[y * scanLine + x * depth];
                        if (datum != 0)
                            break SKIPX;
                    }
                }
                sh = Math.min(contents.height - sy, 16);
                sw = Math.min(contents.width - sx, 16);
                if (WmsPlugin.getDefault().isDebugging())
                    System.out.println("Alpha offset to " + sx + "x" + sy); //$NON-NLS-1$ //$NON-NLS-2$                        
            }
            // else {
            // sh = Math.min( bound.height, bound.width );
            // sw = Math.min( bound.height, bound.width );
            // }
            if (WmsPlugin.getDefault().isDebugging())
                System.out.println("Image resized to " + sh + "x" + sw); //$NON-NLS-1$ //$NON-NLS-2$

            // gc.drawImage(image, sx, sy, sw, sh, 0, 0, 16, 16);

            // chances are this has a label or category view or something
            // grab the gply from the bottom left corner and we are good to
            // (based on mapserver example)
            //
            gc.drawImage(image, 0, bound.height - 16, 16, 16, 0, 0, 16, 16);

            final ImageData data = (ImageData) swatch.getImageData().clone();
            return new ImageDescriptor() {
                public ImageData getImageData() {
                    return (ImageData) data.clone();
                }
            };
        } finally {
            if (image != null) {
                image.dispose();
            }
            if (swatch != null) {
                swatch.dispose();
            }
            if (monitor != null)
                monitor.worked(3);
        }
    } catch (IOException t) {
        WmsPlugin.trace("Could not get icon", t); //$NON-NLS-1$
        return CatalogUIPlugin.getDefault().getImageDescriptor(ISharedImages.GRID_MISSING);
    }
}

From source file:net.refractions.udig.internal.ui.operations.OperationLabelProvider.java

License:Open Source License

Image cacheImage(ImageDescriptor desc) {
    if (images == null)
        images = new HashMap(21);
    Image image = (Image) images.get(desc);
    if (image == null) {
        image = desc.createImage();
        images.put(desc, image);//from ww  w.  ja v a2  s .co m
    }
    return image;
}

From source file:net.refractions.udig.internal.ui.SendLogDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    setTitle(Messages.SendLogDialog_description);
    ImageDescriptor image = UiPlugin.getDefault().getImageDescriptor(ImageConstants.LOG_WIZ);
    if (image != null)
        setTitleImage(image.createImage());

    // create a composite with standard margins and spacing
    Composite composite = new Composite(parent, SWT.RESIZE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);//  w  w w .  ja v a 2s .co  m
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    applyDialogFont(composite);

    contactLabel = new Label(composite, SWT.NONE);
    contactLabel.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false));
    contactLabel.setText(Messages.SendLogDialog_contact);

    contact = new Text(composite, SWT.BORDER);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
    gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
    gridData.horizontalSpan = 2;
    contact.setLayoutData(gridData);
    contact.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            refreshButtons();
        }

    });

    noteLabel = new Label(composite, SWT.NONE);
    noteLabel.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false));
    noteLabel.setText(Messages.SendLogDialog_notes);

    notes = new Text(composite, SWT.WRAP | SWT.BORDER | SWT.MULTI);
    gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
    gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
    gridData.heightHint = notes.getLineHeight() * 2;
    gridData.horizontalSpan = 2;
    notes.setLayoutData(gridData);
    notes.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            refreshButtons();
        }

    });

    logLabel = new Label(composite, SWT.NONE);
    gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
    gridData.verticalAlignment = SWT.END;
    logLabel.setLayoutData(gridData);
    logLabel.setText(Messages.SendLogDialog_log);

    log = new Text(composite, SWT.WRAP | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    log.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalSpan = 2;
    log.setLayoutData(gridData);
    log.setText(Messages.SendLogDialog_reading);
    log.setEnabled(false);

    //start a thread to acquire the log file
    PopulateLogRunnable populateLog = new PopulateLogRunnable();
    PlatformGIS.run(populateLog);
    contact.setFocus();

    return composite;
}

From source file:net.refractions.udig.wps.WPSProcessImpl.java

License:Open Source License

/**
 * This method will fetch the Icon associated with this url (if such is available).
 * //  w  ww . j a  va2s  .  c o m
 * @see WPSFolder
 * @param monitor
 * @return Requested Icon or ISharedImages.GRID_OBJ
 */
protected static ImageDescriptor fetchIcon(IProgressMonitor monitor, ProcessFactory processFactory,
        WPSServiceImpl service) {
    try {
        if (monitor != null)
            monitor.beginTask(Messages.WPSProcessImpl_acquiring_task, 3);
        if (monitor != null)
            monitor.worked(1);

        //            if (process.getChildren() != null && process.getChildren().length != 0) {
        //                // Do not request "parent" layer graphics - this kills Mapserver
        //                return CatalogUIPlugin.getDefault().getImages().getImageDescriptor(
        //                        ISharedImages.GRID_OBJ);
        //            }

        ImageDescriptor imageDescriptor = requestImage(monitor, processFactory, service);

        Image image = null;
        Image swatch = null;
        try {
            if (monitor != null)
                monitor.worked(2);
            if (monitor != null)
                monitor.subTask(Messages.WPSProcessImpl_downloading_icon);
            image = imageDescriptor.createImage();
            Rectangle bound = image.getBounds();
            if (bound.width == 16 && bound.height == 16) {
                final ImageData data = (ImageData) image.getImageData().clone();
                return new ImageDescriptor() {
                    public ImageData getImageData() {
                        return (ImageData) data.clone();
                    }
                };
            }
            if (bound.height < 16 || bound.width < 16) {
                if (WpsPlugin.getDefault().isDebugging())
                    System.out.println("Icon scaled up to requested size"); //$NON-NLS-1$                                        
                final ImageData data = image.getImageData().scaledTo(16, 16);
                return new ImageDescriptor() {
                    public ImageData getImageData() {
                        return (ImageData) data.clone();
                    }
                };
            }
            swatch = new Image(null, 16, 16);
            GC gc = new GC(swatch);
            int sy = 0; // (bound.height / 2 ) - 8;
            int sx = 0;
            int sw = 0;
            int sh = 0;
            ImageData contents = image.getImageData();
            if (contents == null) {
                return CatalogUIPlugin.getDefault().getImageDescriptor(ISharedImages.GRID_MISSING);
            }
            if (contents.maskData != null) {
                // ((width + 7) / 8 + (maskPad - 1)) / maskPad * maskPad
                int maskPad = contents.maskPad;
                int scanLine = ((contents.width + 7) / 8 + (maskPad - 1)) / maskPad * maskPad;
                // skip leading mask ...
                SKIPY: for (int y = 0; y < contents.height / 2; y++) {
                    sy = y;
                    for (int x = 0; x < contents.width / 2; x++) {
                        int mask = contents.maskData[y * scanLine + x];
                        if (mask != 0)
                            break SKIPY;
                    }
                }
                SKIPX: for (int x = 0; x < contents.width / 2; x++) {
                    sx = x;
                    for (int y = sy; y < contents.height / 2; y++) {
                        int mask = contents.maskData[y * scanLine + x];
                        if (mask != 0)
                            break SKIPX;
                    }
                }
                sh = Math.min(contents.height - sy, 16);
                sw = Math.min(contents.width - sx, 16);
                if (WpsPlugin.getDefault().isDebugging())
                    System.out.println("Mask offset to " + sx + "x" + sy); //$NON-NLS-1$ //$NON-NLS-2$                        
            } else if (contents.alphaData != null) {
                SKIPY: for (int y = 0; y < contents.height / 2; y++) {
                    sy = y;
                    for (int x = 0; x < contents.width / 2; x++) {
                        int alpha = contents.alphaData[y * contents.width + x];
                        if (alpha != 0)
                            break SKIPY;
                    }
                }
                SKIPX: for (int x = 0; x < contents.width / 2; x++) {
                    sx = x;
                    for (int y = sy; y < contents.height / 2; y++) {
                        int alpha = contents.alphaData[y * contents.width + x];
                        if (alpha != 0)
                            break SKIPX;
                    }
                }
                sh = Math.min(contents.height - sy, 16);
                sw = Math.min(contents.width - sx, 16);
                if (WpsPlugin.getDefault().isDebugging())
                    System.out.println("Alpha offset to " + sx + "x" + sy); //$NON-NLS-1$ //$NON-NLS-2$                        
            } else {
                // try ignoring "white"
                int depth = contents.depth;
                int scanLine = contents.bytesPerLine;
                SKIPY: for (int y = 0; y < contents.height / 2; y++) {
                    sy = y;
                    for (int x = 0; x < contents.width / 2; x++) {
                        int datum = contents.data[y * scanLine + x * depth];
                        if (datum != 0)
                            break SKIPY;
                    }
                }
                SKIPX: for (int x = 0; x < contents.width / 2; x++) {
                    sx = x;
                    for (int y = sy; y < contents.height / 2; y++) {
                        int datum = contents.data[y * scanLine + x * depth];
                        if (datum != 0)
                            break SKIPX;
                    }
                }
                sh = Math.min(contents.height - sy, 16);
                sw = Math.min(contents.width - sx, 16);
                if (WpsPlugin.getDefault().isDebugging())
                    System.out.println("Alpha offset to " + sx + "x" + sy); //$NON-NLS-1$ //$NON-NLS-2$                        
            }
            // else {
            // sh = Math.min( bound.height, bound.width );
            // sw = Math.min( bound.height, bound.width );
            // }
            if (WpsPlugin.getDefault().isDebugging())
                System.out.println("Image resized to " + sh + "x" + sw); //$NON-NLS-1$ //$NON-NLS-2$

            gc.drawImage(image, sx, sy, sw, sh, 0, 0, 16, 16);
            final ImageData data = (ImageData) swatch.getImageData().clone();
            return new ImageDescriptor() {
                public ImageData getImageData() {
                    return (ImageData) data.clone();
                }
            };
        } finally {
            if (image != null) {
                image.dispose();
            }
            if (swatch != null) {
                swatch.dispose();
            }
            if (monitor != null)
                monitor.worked(3);
        }
    } catch (IOException t) {
        WpsPlugin.trace("Could not get icon", t); //$NON-NLS-1$
        return CatalogUIPlugin.getDefault().getImageDescriptor(ISharedImages.GRID_MISSING);
    }
}

From source file:net.rim.ejde.internal.codeassisstant.PreprocessDirectiveCompletionProposalComputer.java

License:Open Source License

public Image getPreprocessDefineImage() {
    if (_preprocessImage == null) {
        ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(ContextManager.PLUGIN_ID,
                "icons" + File.separator + "bb_perspective.gif");
        _preprocessImage = imageDescriptor.createImage();
    }//from  w  ww. j  a v a2s  . c o  m
    return _preprocessImage;
}

From source file:net.rim.ejde.internal.core.BlackBerryLibMainMarkerResolution.java

License:Open Source License

@Override
public Image getImage() {
    ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(ContextManager.PLUGIN_ID,
            "icons" + File.separator + "bb_perspective.gif");
    final Image image = imageDescriptor.createImage();
    return image;
}

From source file:net.rim.ejde.internal.core.ContextManager.java

License:Open Source License

/**
 * Gets the./* w  w w . ja v  a  2 s .  c  o m*/
 *
 * @param desc
 *            the desc
 *
 * @return the image
 */
public Image get(ImageDescriptor desc) {
    Object key = desc;

    Image image = _images.get(key);
    if (image == null) {
        image = desc.createImage();
        _images.put(key, image);
    }
    return image;
}

From source file:net.rim.ejde.internal.signing.CodeSignMarkerResolution.java

License:Open Source License

public Image getImage() {
    ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(ContextManager.PLUGIN_ID,
            "icons" + File.separator + "bb_perspective.gif");
    final Image image = imageDescriptor.createImage();
    return image;
}

From source file:net.rim.ejde.internal.ui.launchers.ProjectsTab.java

License:Open Source License

/**
 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
 *///from w  w  w .j  a  v  a2s .c o  m
public Image getImage() {
    ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(ContextManager.PLUGIN_ID,
            "icons" + File.separator + "activated.gif");
    final Image image = imageDescriptor.createImage();
    return image;
}

From source file:net.rim.ejde.internal.ui.launchers.SimulatorConfigurationTabBase.java

License:Open Source License

/**
 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
 *//*from ww  w.jav a 2s. co  m*/
public Image getImage() {
    ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(ContextManager.PLUGIN_ID,
            "icons" + File.separator + "obj16" + File.separator + "fledge.gif");
    final Image image = imageDescriptor.createImage();
    return image;
}