KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > OverlayIcon


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;
12
13 import org.eclipse.jface.resource.CompositeImageDescriptor;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.swt.graphics.ImageData;
16 import org.eclipse.swt.graphics.Point;
17 import org.eclipse.ui.internal.util.Util;
18
19 /**
20  * An OverlayIcon consists of a main icon and an overlay icon
21  */

22 public class OverlayIcon extends CompositeImageDescriptor {
23
24     // the size of the OverlayIcon
25
private Point fSize = null;
26
27     // the main image
28
private ImageDescriptor fBase = null;
29
30     // the additional image (a pin for example)
31
private ImageDescriptor fOverlay = null;
32
33     /**
34      * @param base the main image
35      * @param overlay the additional image (a pin for example)
36      * @param size the size of the OverlayIcon
37      */

38     public OverlayIcon(ImageDescriptor base, ImageDescriptor overlay, Point size) {
39         fBase = base;
40         fOverlay = overlay;
41         fSize = size;
42     }
43
44     /* (non-Javadoc)
45      * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int)
46      */

47     protected void drawCompositeImage(int width, int height) {
48         ImageData bg;
49         if (fBase == null || (bg = fBase.getImageData()) == null) {
50             bg = DEFAULT_IMAGE_DATA;
51         }
52         drawImage(bg, 0, 0);
53
54         if (fOverlay != null) {
55             drawTopRight(fOverlay);
56         }
57     }
58
59     /**
60      * @param overlay the additional image (a pin for example)
61      * to be drawn on top of the main image
62      */

63     protected void drawTopRight(ImageDescriptor overlay) {
64         if (overlay == null) {
65             return;
66         }
67         int x = getSize().x;
68         ImageData id = overlay.getImageData();
69         x -= id.width;
70         drawImage(id, x, 0);
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize()
75      */

76     protected Point getSize() {
77         return fSize;
78     }
79
80     /*
81      * (non-Javadoc)
82      * @see java.lang.Object#hashCode()
83      */

84     public int hashCode() {
85         return Util.hashCode(fBase) * 17 + Util.hashCode(fOverlay);
86     }
87
88     /* (non-Javadoc)
89      * @see java.lang.Object#equals(java.lang.Object)
90      */

91     public boolean equals(Object JavaDoc obj) {
92         if (!(obj instanceof OverlayIcon)) {
93             return false;
94         }
95         OverlayIcon overlayIcon = (OverlayIcon) obj;
96         return Util.equals(this.fBase, overlayIcon.fBase)
97                 && Util.equals(this.fOverlay, overlayIcon.fOverlay)
98                 && Util.equals(this.fSize, overlayIcon.fSize);
99     }
100 }
101
Popular Tags