KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > patch > DecoratorOverlayIcon


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.compare.internal.patch;
12
13 import java.util.Arrays JavaDoc;
14
15 import org.eclipse.jface.resource.CompositeImageDescriptor;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.jface.viewers.IDecoration;
18 import org.eclipse.swt.graphics.*;
19
20 /**
21  * An DecoratorOverlayIcon consists of a main icon and several adornments.
22  * Copied until bug 164394 is resolved.
23  */

24 class DecoratorOverlayIcon extends CompositeImageDescriptor {
25     // the base image
26
private Image base;
27
28     // the overlay images
29
private ImageDescriptor[] overlays;
30
31     // the size
32
private Point size;
33
34
35     /**
36      * OverlayIcon constructor.
37      *
38      * @param baseImage the base image
39      * @param overlaysArray the overlay images
40      * @param sizeValue the size
41      */

42     public DecoratorOverlayIcon(Image baseImage,
43             ImageDescriptor[] overlaysArray, Point sizeValue) {
44         this.base = baseImage;
45         this.overlays = overlaysArray;
46         this.size = sizeValue;
47     }
48
49     /**
50      * Draw the overlays for the reciever.
51      */

52     protected void drawOverlays(ImageDescriptor[] overlaysArray) {
53
54         for (int i = 0; i < overlays.length; i++) {
55             ImageDescriptor overlay = overlaysArray[i];
56             if (overlay == null) {
57                 continue;
58             }
59             ImageData overlayData = overlay.getImageData();
60             //Use the missing descriptor if it is not there.
61
if (overlayData == null) {
62                 overlayData = ImageDescriptor.getMissingImageDescriptor()
63                         .getImageData();
64             }
65             switch (i) {
66             case IDecoration.TOP_LEFT:
67                 drawImage(overlayData, 0, 0);
68                 break;
69             case IDecoration.TOP_RIGHT:
70                 drawImage(overlayData, size.x - overlayData.width, 0);
71                 break;
72             case IDecoration.BOTTOM_LEFT:
73                 drawImage(overlayData, 0, size.y - overlayData.height);
74                 break;
75             case IDecoration.BOTTOM_RIGHT:
76                 drawImage(overlayData, size.x - overlayData.width, size.y
77                         - overlayData.height);
78                 break;
79             }
80         }
81     }
82
83     public boolean equals(Object JavaDoc o) {
84         if (!(o instanceof DecoratorOverlayIcon)) {
85             return false;
86         }
87         DecoratorOverlayIcon other = (DecoratorOverlayIcon) o;
88         return base.equals(other.base)
89                 && Arrays.equals(overlays, other.overlays);
90     }
91
92     public int hashCode() {
93         int code = base.hashCode();
94         for (int i = 0; i < overlays.length; i++) {
95             if (overlays[i] != null) {
96                 code ^= overlays[i].hashCode();
97             }
98         }
99         return code;
100     }
101
102     protected void drawCompositeImage(int width, int height) {
103         ImageDescriptor underlay = overlays[IDecoration.UNDERLAY];
104         if (underlay != null) {
105             drawImage(underlay.getImageData(), 0, 0);
106         }
107         drawImage(base.getImageData(), 0, 0);
108         drawOverlays(overlays);
109     }
110
111     protected Point getSize() {
112         return size;
113     }
114     
115     /* (non-Javadoc)
116      * @see org.eclipse.jface.resource.CompositeImageDescriptor#getTransparentPixel()
117      */

118     protected int getTransparentPixel() {
119         return base.getImageData().transparentPixel;
120     }
121
122 }
123
Popular Tags