1 package com.android.ide.eclipse.adt.internal.editors.ui; 2 3 import org.eclipse.jface.resource.CompositeImageDescriptor; 4 import org.eclipse.jface.resource.ImageDescriptor; 5 import org.eclipse.jface.viewers.DecorationOverlayIcon; 6 import org.eclipse.swt.graphics.Image; 7 import org.eclipse.swt.graphics.ImageData; 8 import org.eclipse.swt.graphics.Point; 9 import org.eclipse.ui.ISharedImages; 10 import org.eclipse.ui.PlatformUI; 11 12 /** 13 * ImageDescriptor that adds a error marker. 14 * Based on {@link DecorationOverlayIcon} only available in Eclipse 3.3 15 */ 16 public class ErrorImageComposite extends CompositeImageDescriptor { 17 18 private Image mBaseImage; 19 private ImageDescriptor mErrorImageDescriptor; 20 private Point mSize; 21 22 public ErrorImageComposite(Image baseImage) { 23 mBaseImage = baseImage; 24 mErrorImageDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( 25 ISharedImages.IMG_OBJS_ERROR_TSK); 26 mSize = new Point(baseImage.getBounds().width, baseImage.getBounds().height); 27 } 28 29 @Override 30 protected void drawCompositeImage(int width, int height) { 31 ImageData baseData = mBaseImage.getImageData(); 32 drawImage(baseData, 0, 0); 33 34 ImageData overlayData = mErrorImageDescriptor.getImageData(); 35 if (overlayData.width == baseData.width && overlayData.height == baseData.height) { 36 overlayData = overlayData.scaledTo(14, 14); 37 drawImage(overlayData, -3, mSize.y - overlayData.height + 3); 38 } else { 39 drawImage(overlayData, 0, mSize.y - overlayData.height); 40 } 41 } 42 43 @Override 44 protected Point getSize() { 45 return mSize; 46 } 47 } 48