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

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

Introduction

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

Prototype

protected ImageDescriptor() 

Source Link

Document

Constructs an image descriptor.

Usage

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).
 * //from w w  w.  jav  a 2  s.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:org.amanzi.awe.catalog.neo.resource.GeoResourceInfo.java

License:Open Source License

GeoResourceInfo(final IGISModel sourceModel, final IProgressMonitor monitor) {
    name = sourceModel.getName();//  w  ww .  j  a  v a  2 s.  c o  m
    title = name;
    description = sourceModel.getName();
    bounds = sourceModel.getBounds();

    // taken from previous implementation
    icon = new ImageDescriptor() {
        private ImageData imageData;

        @Override
        public ImageData getImageData() {
            if (imageData == null) {
                imageData = IconManager.getInstance().getImage(sourceModel.getSourceType()).getImageData();
            }
            return imageData;
        }
    };
}

From source file:org.bonitasoft.studio.dependencies.ui.MissingDependenciesDecorator.java

License:Open Source License

protected Image getErrorDecoratedImage(Image image) {
    if (errorIcon == null) {
        errorIcon = new DecorationOverlayIcon(image, new ImageDescriptor() {

            @Override//www .  java 2s  . c o  m
            public ImageData getImageData() {
                return errorDecoratorImage.getImageData();
            }
        }, IDecoration.BOTTOM_RIGHT).createImage();
    }
    return errorIcon;
}

From source file:org.bonitasoft.studio.dependencies.ui.MissingDependenciesDecorator.java

License:Open Source License

protected Image getWarningDecoratedImage(Image image) {
    if (warningIcon == null) {

        warningIcon = new DecorationOverlayIcon(image, new ImageDescriptor() {

            @Override//from ww w . j ava2s . co m
            public ImageData getImageData() {
                return warningDecoratorImage.getImageData();
            }
        }, IDecoration.BOTTOM_RIGHT).createImage();
    }
    return warningIcon;
}

From source file:org.dawb.common.ui.image.IconUtils.java

License:Open Source License

public static ImageDescriptor createIconDescriptor(String iconText) {

    final ImageData data = new ImageData(16, 16, 16, new PaletteData(0x7C00, 0x3E0, 0x1F));
    final Image image = new Image(Display.getCurrent(), data);

    final GC gc = new GC(image);

    gc.setForeground(ColorConstants.white);
    gc.fillRectangle(new Rectangle(0, 0, 16, 16));
    gc.setForeground(ColorConstants.darkGray);
    gc.setFont(new Font(Display.getCurrent(), new FontData("Dialog", 6, SWT.BOLD)));
    gc.drawText(iconText, 4, 2);/*from  w  w  w  .  ja va2 s .c  o  m*/

    gc.dispose();

    return new ImageDescriptor() {
        @Override
        public ImageData getImageData() {
            return image.getImageData();
        }
    };
}

From source file:org.dawb.common.ui.image.IconUtils.java

License:Open Source License

public static ImageDescriptor createPenDescriptor(int penSize) {

    final ImageData data = new ImageData(16, 16, 16, new PaletteData(0x7C00, 0x3E0, 0x1F));
    final Image image = new Image(Display.getCurrent(), data);

    final GC gc = new GC(image);

    gc.setBackground(Display.getDefault().getActiveShell().getBackground());
    gc.fillRectangle(new Rectangle(0, 0, 16, 16));
    gc.setBackground(ColorConstants.gray);
    gc.fillRectangle(2, 2, penSize, penSize);

    gc.dispose();/*  w  w  w.java 2s.  co m*/

    return new ImageDescriptor() {
        @Override
        public ImageData getImageData() {
            return image.getImageData();
        }
    };
}

From source file:org.dawb.common.ui.image.IconUtils.java

License:Open Source License

/**
 * Icon for the actions to choose brush type.
 * @param size/*from  w w w .jav  a 2 s .  c  o  m*/
 * @param shape
 * @param maskRGB
 * @return
 */
public static ImageDescriptor getBrushIcon(int size, ShapeType shape, RGB maskRGB) {

    if (shape == ShapeType.NONE)
        return null;

    final ImageData data = new ImageData(16, 16, 16, new PaletteData(0x7C00, 0x3E0, 0x1F));
    final Image image = new Image(Display.getCurrent(), data);

    final GC gc = new GC(image);

    if (Display.getDefault() == null)
        return ImageDescriptor.createFromImage(image);
    if (Display.getDefault().getActiveShell() == null)
        return ImageDescriptor.createFromImage(image);
    gc.setBackground(Display.getDefault().getActiveShell().getBackground());
    gc.fillRectangle(new Rectangle(0, 0, 16, 16));
    gc.setForeground(ColorConstants.gray);
    gc.setLineWidth(2);
    if (maskRGB != null) {
        final Color maskColour = new Color(null, maskRGB);
        gc.setBackground(maskColour);
    }
    switch (shape) {
    case SQUARE:
        if (maskRGB != null)
            gc.fillRectangle(2, 2, size, size);
        gc.drawRectangle(2, 2, size, size);
        break;
    case TRIANGLE:
        final PointList pl = new PointList();
        pl.addPoint(2 + (size / 2), 2);
        pl.addPoint(2 + size, 2 + size);
        pl.addPoint(2, 2 + size);
        if (maskRGB != null)
            gc.fillPolygon(pl.toIntArray());
        gc.drawPolygon(pl.toIntArray());
        break;
    case CIRCLE:
        if (maskRGB != null)
            gc.fillOval(2, 2, size, size);
        gc.drawOval(2, 2, size, size);
        break;
    default:
        break;
    }

    gc.dispose();

    return new ImageDescriptor() {
        @Override
        public ImageData getImageData() {
            return image.getImageData();
        }
    };
}

From source file:org.dawnsci.plotting.system.LightWeightPlotActions.java

License:Open Source License

public void createZoomActions(final XYRegionGraph xyGraph, final int flags) {

    actionBarManager.registerToolBarGroup(ToolbarConfigurationConstants.ZOOM.getId());

    final Action autoScale = new Action("Perform Auto Scale",
            PlottingSystemActivator.getImageDescriptor("icons/AutoScale.png")) {
        public void run() {
            xyGraph.performAutoScale();/*  ww w  .  j  a  va  2  s  . c o m*/
        }
    };
    autoScale.setId(BasePlottingConstants.AUTO_SCALE);
    actionBarManager.registerAction(ToolbarConfigurationConstants.ZOOM.getId(), autoScale,
            ActionType.XYANDIMAGE);

    final CheckableActionGroup zoomG = new CheckableActionGroup();
    Action none = null;
    for (final ZoomType zoomType : ZoomType.values()) {
        if (!zoomType.useWithFlags(flags))
            continue;

        final ImageDescriptor icon = new ImageDescriptor() {
            @Override
            public ImageData getImageData() {
                return zoomType.getIconImage().getImageData();
            }
        };
        final Action zoomAction = new Action(zoomType.getDescription(), IAction.AS_CHECK_BOX) {
            public void run() {
                xyGraph.setZoomType(zoomType);
            }
        };
        zoomAction.setImageDescriptor(icon);
        zoomAction.setId(zoomType.getId());
        zoomG.add(zoomAction);

        if (zoomType == ZoomType.NONE)
            none = zoomAction;

        actionBarManager.registerAction(ToolbarConfigurationConstants.ZOOM.getId(), zoomAction,
                ActionType.XYANDIMAGE);
    }
    none.setChecked(true);

    // Add more actions
    // Rescale      
    final Action rescaleAction = new Action("Rescale axis when plotted data changes",
            PlottingSystemActivator.getImageDescriptor("icons/rescale.png")) {
        public void run() {
            viewer.getSystem().setRescale(!viewer.getSystem().isRescale());
        }
    };
    rescaleAction.setChecked(viewer.getSystem().isRescale());
    rescaleAction.setId(BasePlottingConstants.RESCALE);
    actionBarManager.addXYAction(rescaleAction);
    actionBarManager.addImageAction(rescaleAction);

    actionBarManager.registerAction(ToolbarConfigurationConstants.ZOOM.getId(), rescaleAction,
            ActionType.XYANDIMAGE);

}

From source file:org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramGenerator.java

License:Open Source License

final public ImageDescriptor createSWTImageDescriptorForParts(List editparts,
        org.eclipse.swt.graphics.Rectangle sourceRect) {

    // initialize imageDesc to the error icon
    ImageDescriptor imageDesc = new ImageDescriptor() {

        /*/*from   w ww  . j  av a  2  s . co m*/
         * (non-Javadoc)
         * 
         * @see org.eclipse.jface.resource.ImageDescriptor#getImageData()
         */
        public ImageData getImageData() {
            return SharedImages.get(SharedImages.IMG_ERROR).getImageData();
        }
    };

    Graphics graphics = null;
    try {
        IMapMode mm = getMapMode();

        PrecisionRectangle rect = new PrecisionRectangle();
        rect.setX(sourceRect.x);
        rect.setY(sourceRect.y);
        rect.setWidth(sourceRect.width);
        rect.setHeight(sourceRect.height);

        mm.LPtoDP(rect);

        // Create the graphics and wrap it with the HiMetric graphics object
        graphics = setUpGraphics((int) Math.round(rect.preciseWidth), (int) Math.round(rect.preciseHeight));

        RenderedMapModeGraphics mapModeGraphics = new RenderedMapModeGraphics(graphics, getMapMode());

        renderToGraphics(mapModeGraphics, new Point(sourceRect.x, sourceRect.y), editparts);
        imageDesc = getImageDescriptor(graphics);
    } finally {
        if (graphics != null)
            disposeGraphics(graphics);
    }

    return imageDesc;
}

From source file:org.eclipse.gmf.runtime.diagram.ui.render.clipboard.DiagramGenerator.java

License:Open Source License

/**
 * Creates an SWT image descriptor for editparts. Editparts are scaled to fit in maxDeviceWidth and maxDeviceHeight
 * frame/*  w  w w .  j a  v a2s . c  o  m*/
 * 
 * @param editParts editparts
 * @param maxDeviceWidth max width for the image
 * @param maxDeviceHeight max height for the image
 * @param useMargins true if 10 pisels margins are required to bound the editparts image
 * @return the image descriptor
 */
final public ImageDescriptor createConstrainedSWTImageDecriptorForParts(List editParts, int maxDeviceWidth,
        int maxDeviceHeight, boolean useMargins) {
    ImageDescriptor imageDesc = new ImageDescriptor() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.jface.resource.ImageDescriptor#getImageData()
         */
        public ImageData getImageData() {
            return SharedImages.get(SharedImages.IMG_ERROR).getImageData();
        }
    };

    Graphics graphics = null;
    try {
        IMapMode mm = getMapMode();

        ConstrainedImageRenderingData data = getConstrainedImageRenderingData(editParts, maxDeviceWidth,
                maxDeviceHeight, useMargins);

        // Create the graphics and wrap it with the HiMetric graphics object
        graphics = setUpGraphics(data.imageWidth, data.imageHeight);

        ScaledGraphics scaledGraphics = new RenderedScaledGraphics(graphics);

        RenderedMapModeGraphics mapModeGraphics = new RenderedMapModeGraphics(scaledGraphics, getMapMode());

        graphics.translate(data.margin, data.margin);
        mapModeGraphics.scale(data.scalingFactor);

        Point location = new PrecisionPoint(data.imageOriginalBounds.preciseX(),
                data.imageOriginalBounds.preciseY());
        mm.DPtoLP(location);
        renderToGraphics(mapModeGraphics, location, editParts);
        imageDesc = getImageDescriptor(graphics);
    } finally {
        if (graphics != null)
            disposeGraphics(graphics);
    }

    return imageDesc;
}