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

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

Introduction

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

Prototype

@Deprecated
public ImageData getImageData() 

Source Link

Document

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

Usage

From source file:fr.obeo.dsl.debug.ide.ui.DSLDebugModelPresentation.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  w w .  j  ava2s.c o m*/
 * 
 * @see org.eclipse.debug.ui.IDebugModelPresentation#getImage(java.lang.Object)
 */
public Image getImage(final Object element) {
    final Image res;

    final Object unwrapped = unwrapp(element);
    if (unwrapped instanceof Variable) {
        res = getImage(((Variable) unwrapped).getValue());
    } else if (element instanceof DSLBreakpoint) {
        final Object image = ((DSLBreakpoint) element).getImage();
        if (image instanceof ComposedImage) {
            ((ComposedImage) image).getImages()
                    .add(DebugIdeUiPlugin.INSTANCE.getImage("full/deco16/breakpoint_enabled"));
        }
        final ImageDescriptor descriptor = ExtendedImageRegistry.getInstance().getImageDescriptor(image);
        Image cachedImage = imagesCache.get(descriptor);
        if (cachedImage == null) {
            cachedImage = new Image(Display.getDefault(), descriptor.getImageData());
            imagesCache.put(descriptor, cachedImage);
        }
        res = cachedImage;
    } else {
        res = eLabelProvider.getImage(unwrapped);
    }

    return res;
}

From source file:io.usethesource.impulse.editor.SourceEntityImageDescriptor.java

License:Open Source License

private ImageData getImageData(ImageDescriptor descriptor) {
    ImageData data = descriptor.getImageData(); // see bug 51965: getImageData can return null
    if (data == null) {
        data = DEFAULT_IMAGE_DATA;/*from ww w . j a  v a  2s.c  o m*/
        RuntimePlugin.getInstance().writeErrorMsg("Image data not available: " + descriptor.toString()); //$NON-NLS-1$
    }
    return data;
}

From source file:jsceneviewer.inventor.qt.SoQtIcons.java

License:Open Source License

public static ImageDescriptor getIcon(int number) {
    if (number < 0 || number >= IconNum.ICON_COUNT.ordinal()) {
        return null;
    }//  ww w. j  ava  2s  . c o  m
    if (cachedIcons[number] == null) {
        final Point size = new Point(so_qt_icon_width, so_qt_icon_height);
        short[] data = null;
        String resourceName = "";
        //QBitmap bits;
        switch (IconNum.values()[number]) {
        case ICON_PICK:
            resourceName = "icons/pickMode.png";
            data = so_qt_pick_bits;
            break;
        case ICON_VIEW:
            resourceName = "icons/viewMode.png";
            data = so_qt_view_bits;
            break;
        case ICON_HELP:
            resourceName = "icons/help.png";
            data = so_qt_help_bits;
            break;
        case ICON_HOME:
            resourceName = "icons/gotoHome.png";
            data = so_qt_home_bits;
            break;
        case ICON_SET_HOME:
            resourceName = "icons/setHome.png";
            data = so_qt_set_home_bits;
            break;
        case ICON_VIEW_ALL:
            resourceName = "icons/viewAll.png";
            data = so_qt_see_all_bits;
            break;
        case ICON_SEEK:
            resourceName = "icons/seek.png";
            data = so_qt_seek_bits;
            break;
        case ICON_ORTHO:
            resourceName = "icons/ortho.png";
            data = so_qt_ortho_bits;
            break;
        case ICON_PERSP:
            resourceName = "icons/persp.png";
            data = so_qt_persp_bits;
            break;
        case ICON_X:
            data = so_qt_X_bits;
            break;
        case ICON_Y:
            data = so_qt_Y_bits;
            break;
        case ICON_Z:
            data = so_qt_Z_bits;
            break;
        case ICON_COUNT:
            throw new IllegalArgumentException();
        default:
            throw new IllegalArgumentException();
        }
        ImageDescriptor imageDescriptor = Activator.getImageDescriptor(resourceName);
        ImageData icon = null;
        if (imageDescriptor != null) {
            icon = imageDescriptor.getImageData();
            icon = resize(icon, 27, 27);
        }
        //QIcon icon (resourceName);
        if (icon == null) {
            icon = fromData(size, data);
            //                   QPixmap pix (size);
            //                   pix.fill (Qt::black);
            //                   pix.setMask (bits);
            //                   icon = QIcon (pix);
        }
        cachedIcons[number] = ImageDescriptor.createFromImageData(icon);
    }
    return cachedIcons[number];
}

From source file:melnorme.util.swt.jface.resources.CompositeImageDescriptorExt.java

License:Open Source License

protected ImageData getImageData(ImageDescriptor desc) {
    ImageData imageData = desc.getImageData();
    if (imageData == null) {
        LangCore.logError("Could not get ImageData.");
        return new ImageData(1, 1, 32, DEFAULT_IMAGE_DATA.palette);
    }/*  w  ww .j a  va  2 s  .  c  om*/
    return imageData;
}

From source file:mt.com.southedge.jclockwork.plugin.treeview.cellrenderer.ClockWorkCellRenderer.java

License:Open Source License

private static void init() {

    ImageDescriptor leafDes = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
            "icons/method_public_object.png");

    ImageDescriptor branchDes = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
            "icons/class_obj.gif");

    ImageIcon leafIcon = new ImageIcon(ImageConverter.convertToAWT(leafDes.getImageData()));
    ImageIcon branchIcon = new ImageIcon(ImageConverter.convertToAWT(branchDes.getImageData()));

    UIManager.put("Tree.leafIcon", leafIcon);
    UIManager.put("Tree.openIcon", branchIcon);
    UIManager.put("Tree.closedIcon", branchIcon);
}

From source file:net.mldonkey.g2gui.view.resource.G2GuiResources.java

License:Open Source License

/**
 * @param imageDescriptor/*w ww  . ja v  a  2 s. c  om*/
 * @return Image
 */
private static Image createActiveImage(ImageDescriptor imageDescriptor) {
    ImageData imageData = imageDescriptor.getImageData();
    Image result = new Image(null, imageData);

    GC gc = new GC(result);

    for (int w = 0; w < imageData.width; w++) {
        for (int h = 0; h < imageData.height; h++) {
            int pixel = imageData.getPixel(w, h);
            PaletteData paletteData = imageData.palette;
            RGB oldRGB = paletteData.getRGB(pixel);

            // add 20 for a brighter colour
            if (pixel != imageData.transparentPixel) {
                RGB newRGB = new RGB(((oldRGB.red + 20) <= 255) ? (oldRGB.red + 20) : 255,
                        ((oldRGB.green + 20) <= 255) ? (oldRGB.green + 20) : 255,
                        ((oldRGB.blue + 20) <= 255) ? (oldRGB.blue + 20) : 255);
                Color foregroundColor = new Color(null, newRGB);
                gc.setForeground(foregroundColor);
                gc.drawPoint(w, h);
                foregroundColor.dispose();
            }
        }
    }

    gc.dispose();

    return result;
}

From source file:net.refractions.udig.document.ui.DocumentImageProvider.java

License:Open Source License

private ImageData getDefaultImageData(ContentType contentType) {

    ImageDescriptor descriptor = null;
    switch (contentType) {
    case FILE:/* www  .java  2  s .  c  o  m*/
        descriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
        break;
    case WEB:
        descriptor = InfoPlugin.getDefault().getImageRegistry().getDescriptor(InfoPlugin.IMG_OBJ_LINK);
        break;
    case ACTION:
        descriptor = InfoPlugin.getDefault().getImageRegistry().getDescriptor(InfoPlugin.IMG_OBJ_ACTION);
        break;
    default:
        descriptor = PlatformUI.getWorkbench().getSharedImages()
                .getImageDescriptor(ISharedImages.IMG_OBJ_ELEMENT);
        break;
    }

    if (descriptor != null) {
        return descriptor.getImageData();
    }
    return null;

}

From source file:net.refractions.udig.legend.ui.LegendGraphic.java

License:Open Source License

public void draw(MapGraphicContext context) {

    IBlackboard blackboard = context.getLayer().getStyleBlackboard();
    LegendStyle legendStyle = (LegendStyle) blackboard.get(LegendStyleContent.ID);
    if (legendStyle == null) {
        legendStyle = LegendStyleContent.createDefault();
        blackboard.put(LegendStyleContent.ID, legendStyle);
    }//from   ww w. ja  va 2s . co  m

    Rectangle locationStyle = (Rectangle) blackboard.get(LocationStyleContent.ID);
    if (locationStyle == null) {
        locationStyle = new Rectangle(-1, -1, -1, -1);
        blackboard.put(LocationStyleContent.ID, locationStyle);
    }

    FontStyle fontStyle = (FontStyle) blackboard.get(FontStyleContent.ID);
    if (fontStyle == null) {
        fontStyle = new FontStyle();
        blackboard.put(FontStyleContent.ID, fontStyle);
    }

    this.backgroundColour = legendStyle.backgroundColour;
    this.foregroundColour = legendStyle.foregroundColour;
    this.horizontalMargin = legendStyle.horizontalMargin;
    this.verticalMargin = legendStyle.verticalMargin;
    this.horizontalSpacing = legendStyle.horizontalSpacing;
    this.verticalSpacing = legendStyle.verticalSpacing;
    this.indentSize = legendStyle.indentSize;
    this.imageHeight = legendStyle.imageHeight;
    this.imageWidth = legendStyle.imageWidth;

    final ViewportGraphics graphics = context.getGraphics();

    if (fontStyle.getFont() != null) {
        graphics.setFont(fontStyle.getFont());
    }

    List<Map<ILayer, LegendEntry[]>> layers = new ArrayList<Map<ILayer, LegendEntry[]>>();

    int longestRow = 0; // used to calculate the width of the graphic
    final int[] numberOfEntries = new int[1]; // total number of entries to
    // draw
    numberOfEntries[0] = 0;

    /*
     * Set up the layers that we want to draw so we can operate just on
     * those ones. Layers at index 0 are on the bottom of the map, so we
     * must iterate in reverse.
     * 
     * While we are doing this, determine the longest row so we can properly
     * draw the graphic's border.
     */
    Dimension imageSize = new Dimension(imageWidth, imageHeight);
    Dimension textSize = new Dimension(0, graphics.getFontHeight());

    for (int i = context.getMapLayers().size() - 1; i >= 0; i--) {
        ILayer layer = context.getMapLayers().get(i);

        if (!(layer.getGeoResource() instanceof MapGraphicResource) && layer.isVisible()) {

            if (layer.hasResource(MapGraphic.class)) {
                // don't include mapgraphics
                continue;
            }
            String layerName = layer.getName();
            if (layerName == null) {
                layerName = null;
            }
            LegendEntry layerEntry = new LegendEntry(layerName);

            FeatureTypeStyle[] styles = locateStyle(layer);
            LegendEntry[] entries = null;
            if (styles == null) {
                // we should have a label but no style
                entries = new LegendEntry[] { layerEntry };
            } else {
                List<Rule> rules = rules(styles);
                int ruleCount = rules.size();

                if (ruleCount == 1 && layer.getGeoResource().canResolve(GridCoverage.class)) {
                    // grid coverage with single rule; lets see if it is a
                    // theming style
                    List<LegendEntry> cmEntries = ColorMapLegendCreator.findEntries(styles, imageSize,
                            textSize);
                    if (cmEntries != null) {
                        cmEntries.add(0, layerEntry); // add layer legend
                        // entry
                        entries = cmEntries.toArray(new LegendEntry[cmEntries.size()]);
                    }
                }
                if (entries == null) {
                    List<LegendEntry> localEntries = new ArrayList<LegendEntry>();
                    if (ruleCount == 1) {
                        // only one rule so apply this to the layer legend
                        // entry
                        layerEntry.setRule(rules.get(0));
                    }
                    localEntries.add(layerEntry); // add layer legend entry

                    if (ruleCount > 1) {
                        // we have more than one rule so there is likely
                        // some
                        // themeing going on; add each of these rules
                        for (Rule rule : rules) {
                            LegendEntry rentry = new LegendEntry(rule);
                            localEntries.add(rentry);
                        }
                    }
                    entries = localEntries.toArray(new LegendEntry[localEntries.size()]);
                }
            }
            layers.add(Collections.singletonMap(layer, entries));

            // compute maximum length for each entry
            for (int j = 0; j < entries.length; j++) {
                StringBuilder sb = new StringBuilder();
                for (int k = 0; k < entries[j].getText().length; k++) {
                    sb.append(entries[j].getText()[k]);
                }
                Rectangle2D bounds = graphics.getStringBounds(sb.toString());
                int length = indentSize + imageWidth + horizontalSpacing + (int) bounds.getWidth();

                if (length > longestRow) {
                    longestRow = length;
                }
                numberOfEntries[0]++;
            }
        }
    }

    if (numberOfEntries[0] == 0) {
        // nothing to draw!
        return;
    }

    final int rowHeight = Math.max(imageHeight, graphics.getFontHeight()); // space
    // allocated
    // to
    // each
    // layer

    if (locationStyle.width == 0 || locationStyle.height == 0) {
        // we want to change the location style as needed
        // but not change the saved one so we create a copy here
        locationStyle = new Rectangle(locationStyle);
        if (locationStyle.width == 0) {
            // we want to grow to whatever size we need
            int width = longestRow + horizontalMargin * 2;
            locationStyle.width = width;
        }
        if (locationStyle.height == 0) {
            // we want to grow to whatever size we need
            int height = rowHeight * numberOfEntries[0] + verticalMargin * 2;
            for (int i = 0; i < layers.size(); i++) {
                Map<ILayer, LegendEntry[]> map = layers.get(i);
                final LegendEntry[] entries = map.values().iterator().next();
                for (int j = 0; j < entries.length; j++) {
                    if (entries[j].getSpacingAfter() == null) {
                        height += verticalSpacing;
                    } else {
                        height += entries[j].getSpacingAfter();
                    }
                }
            }
            locationStyle.height = height - verticalSpacing;
        }
    }

    // ensure box within the display
    Dimension displaySize = context.getMapDisplay().getDisplaySize();
    if (locationStyle.x < 0) {
        locationStyle.x = displaySize.width - locationStyle.width + locationStyle.x;
    }
    if ((locationStyle.x + locationStyle.width + 6) > displaySize.width) {
        locationStyle.x = displaySize.width - locationStyle.width - 5;
    }

    if (locationStyle.y < 0) {
        locationStyle.y = displaySize.height - locationStyle.height - 5 + locationStyle.y;
    }
    if ((locationStyle.y + locationStyle.height + 6) > displaySize.height) {
        locationStyle.y = displaySize.height - locationStyle.height - 5;
    }

    graphics.setClip(
            new Rectangle(locationStyle.x, locationStyle.y, locationStyle.width + 1, locationStyle.height + 1));

    /*
     * Draw the box containing the layers/icons
     */
    drawOutline(graphics, context, locationStyle);

    /*
     * Draw the layer names/icons
     */
    final int[] rowsDrawn = new int[1];
    rowsDrawn[0] = 0;
    final int[] x = new int[1];
    x[0] = locationStyle.x + horizontalMargin;
    final int[] y = new int[1];
    y[0] = locationStyle.y + verticalMargin;

    if (fontStyle.getFont() != null) {
        graphics.setFont(fontStyle.getFont());
    }

    for (int i = 0; i < layers.size(); i++) {
        Map<ILayer, LegendEntry[]> map = layers.get(i);
        final ILayer layer = map.keySet().iterator().next();
        final LegendEntry[] entries = map.values().iterator().next();

        try {
            layer.getGeoResources().get(0).getInfo(null);
        } catch (Exception ex) {
        }

        PlatformGIS.syncInDisplayThread(new Runnable() {
            public void run() {
                for (int i = 0; i < entries.length; i++) {
                    BufferedImage awtIcon = null;
                    if (entries[i].getRule() != null) {
                        // generate icon from use
                        ImageDescriptor descriptor = LayerGeneratedGlyphDecorator.generateStyledIcon(layer,
                                entries[i].getRule());
                        if (descriptor == null) {
                            descriptor = LayerGeneratedGlyphDecorator.generateIcon((Layer) layer);
                        }
                        if (descriptor != null) {
                            awtIcon = AWTSWTImageUtils.convertToAWT(descriptor.getImageData());
                        }
                    } else if (entries[i].getIcon() != null) {
                        // use set icon
                        awtIcon = AWTSWTImageUtils.convertToAWT(entries[i].getIcon().getImageData());
                    } else {
                        // no rule, no icon, try default for layer
                        ImageDescriptor descriptor = LayerGeneratedGlyphDecorator.generateIcon((Layer) layer);
                        if (descriptor != null) {
                            awtIcon = AWTSWTImageUtils.convertToAWT(descriptor.getImageData());
                        }
                    }
                    drawRow(graphics, x[0], y[0], awtIcon, entries[i].getText(), i != 0,
                            entries[i].getTextPosition());

                    y[0] += rowHeight;
                    if ((rowsDrawn[0] + 1) < numberOfEntries[0]) {
                        if (entries[i].getSpacingAfter() != null) {
                            y[0] += entries[i].getSpacingAfter();
                        } else {
                            y[0] += verticalSpacing;
                        }
                    }
                    rowsDrawn[0]++;
                }

            }
        });
    }
    // clear the clip so we don't affect other rendering processes
    graphics.setClip(null);
}

From source file:net.refractions.udig.ui.DecoratorOverlayIcon.java

License:Open Source License

/**
 * Draw the overlays for the reciever./*from w w w  .j a  va  2  s  .  c om*/
 */
protected void drawOverlays(ImageDescriptor[] overlaysArray) {

    for (int i = 0; i < overlays.length; i++) {
        ImageDescriptor overlay = overlaysArray[i];
        if (overlay == null)
            continue;

        ImageData overlayData = overlay.getImageData();
        //Use the missing descriptor if it is not there.
        if (overlayData == null)
            overlayData = ImageDescriptor.getMissingImageDescriptor().getImageData();
        switch (i) {
        case TOP_LEFT:
            drawImage(overlayData, 0, 0);
            break;
        case TOP_RIGHT:
            drawImage(overlayData, size.x - overlayData.width, 0);
            break;
        case BOTTOM_LEFT:
            drawImage(overlayData, 0, size.y - overlayData.height);
            break;
        case BOTTOM_RIGHT:
            drawImage(overlayData, size.x - overlayData.width, size.y - overlayData.height);
            break;
        }
    }
}

From source file:net.refractions.udig.ui.DecoratorOverlayIcon.java

License:Open Source License

protected void drawCompositeImage(int width, int height) {
    ImageDescriptor underlay = overlays[UNDERLAY];
    if (underlay != null)
        drawImage(underlay.getImageData(), 0, 0);
    drawImage(base.getImageData(), 0, 0);
    drawOverlays(overlays);/*from  w  ww  .j  a va 2 s  .c  om*/
}