Erik Hunter
Erik Hunter

Reputation: 211

Eclipse label decorator can't draw off the image

I'm trying to create a label decorator to add an icon to the top left of my file icons. I see that the little red X can be drawn off of the edge of the icon, but my radiation symbol is cut off at the edge.

enter image description here l

@Override
public Image decorateImage(Image image, Object element) {
    Image failureImg = Activator.imageDescriptorFromPlugin(IMAGE PATH).createImage();


    GC gc = new GC(image);
    gc.drawImage(failureImg, 0, 0, failureImg.getImageData().width, failureImg.getImageData().height, 
            0, 0, 11, 11);
    gc.dispose();

    return image;
}

Any ideas on how to draw outside of the bounds of the file icon?

Upvotes: 0

Views: 97

Answers (1)

greg-449
greg-449

Reputation: 111142

It is easier to use a lightweight label decorator (implement ILightweightLabelDecorator and specify lightweight="true" in the extension point).

You can then add the decoration image with:

@Override
public void decorate(final Object element, final IDecoration decoration)
{
  ImageDescriptor imageDescriptor = Activator.imageDescriptorFromPlugin(IMAGE PATH);

  decoration.addOverlay(imageDescriptor, IDecoration.TOP_LEFT); 
}

Since lightweight decorators are run in a background thread they also make the UI more responsive.

Note: Your code is creating Image objects and not arranging for them to be disposed - this leaks resource handles. The lightweight decorator does not have this issue.

Upvotes: 1

Related Questions