1   package de.matthias_burbach.mosaique4eclipse.util;
2   
3   import org.eclipse.jface.resource.CompositeImageDescriptor;
4   import org.eclipse.jface.resource.ImageDescriptor;
5   import org.eclipse.swt.graphics.Image;
6   import org.eclipse.swt.graphics.ImageData;
7   import org.eclipse.swt.graphics.Point;
8   
9   import de.matthias_burbach.mosaique4eclipse.MosaiquePlugin;
10  
11  /***
12   * This class is used for overlaying image icons with adornments to convey extra
13   * information.
14   */
15  public class OverlayImageIcon extends CompositeImageDescriptor {
16      /***
17       * The error image descriptor to be used as overlay.
18       */
19      private static final ImageDescriptor
20          ERROR_DESCRIPTOR = MosaiquePlugin.getImageDescriptor("icons/error.gif");
21  
22      /***
23       * The base image of the object to overlay.
24       */
25      private Image baseImage;
26  
27      /***
28       * The size of the base image to overlay.
29       */
30      private Point sizeOfImage;
31  
32      /***
33       * @param baseImage The base image to overlay.
34       */
35      public OverlayImageIcon(final Image baseImage) {
36          this.baseImage = baseImage;
37          sizeOfImage = new Point(baseImage.getBounds().width, baseImage
38                  .getBounds().height);
39      }
40  
41      
42  
43  
44  
45  
46      /***
47       * {@inheritDoc}
48       */
49      protected void drawCompositeImage(final int width, final int height) {
50          
51          drawImage(baseImage.getImageData(), 0, 0);
52  
53          
54          ImageData imageData = ERROR_DESCRIPTOR.getImageData();
55          drawImage(imageData, 0, sizeOfImage.y - imageData.height);
56      }
57  
58      
59  
60  
61  
62      /***
63       * {@inheritDoc}
64       */
65      protected Point getSize() {
66          return sizeOfImage;
67      }
68  
69      /***
70       * @return The image formed by overlaying one or more images on the base
71       *         image.
72       */
73      public Image getImage() {
74          return createImage();
75      }
76  }