我正在尝试创建一个标签装饰器,以便在文件图标的左上角添加一个图标。我看到小红X可以从图标的边缘画出来,但是我的辐射符号在边缘被切断了。

我
@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;
}对于如何绘制出文件图标的边界有什么想法吗?
发布于 2015-03-20 08:11:32
更容易使用轻量级标签装饰器(实现ILightweightLabelDecorator并在扩展点中指定lightweight="true" )。
然后,您可以使用以下内容添加装饰图像:
@Override
public void decorate(final Object element, final IDecoration decoration)
{
ImageDescriptor imageDescriptor = Activator.imageDescriptorFromPlugin(IMAGE PATH);
decoration.addOverlay(imageDescriptor, IDecoration.TOP_LEFT);
}因为轻量级装饰器是在后台线程中运行的,所以它们也使UI更有响应性。
注意:您的代码正在创建Image对象,而不是安排它们被释放--这会泄漏资源句柄。轻量级装饰师没有这个问题。
https://stackoverflow.com/questions/29156605
复制相似问题