KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > decorators > 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.ui.internal.decorators;
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.swt.graphics.Image;
18 import org.eclipse.swt.graphics.ImageData;
19 import org.eclipse.swt.graphics.Point;
20
21 /**
22  * An DecoratorOverlayIcon consists of a main icon and several adornments.
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      * OverlayIcon constructor.
36      *
37      * @param baseImage the base image
38      * @param overlaysArray the overlay images
39      * @param sizeValue the size
40      */

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

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