001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal;
011:
012: import org.eclipse.jface.resource.CompositeImageDescriptor;
013: import org.eclipse.jface.resource.ImageDescriptor;
014: import org.eclipse.swt.graphics.ImageData;
015: import org.eclipse.swt.graphics.Point;
016: import org.eclipse.ui.internal.util.Util;
017:
018: /**
019: * An OverlayIcon consists of a main icon and an overlay icon
020: */
021: public class OverlayIcon extends CompositeImageDescriptor {
022:
023: // the size of the OverlayIcon
024: private Point fSize = null;
025:
026: // the main image
027: private ImageDescriptor fBase = null;
028:
029: // the additional image (a pin for example)
030: private ImageDescriptor fOverlay = null;
031:
032: /**
033: * @param base the main image
034: * @param overlay the additional image (a pin for example)
035: * @param size the size of the OverlayIcon
036: */
037: public OverlayIcon(ImageDescriptor base, ImageDescriptor overlay,
038: Point size) {
039: fBase = base;
040: fOverlay = overlay;
041: fSize = size;
042: }
043:
044: /* (non-Javadoc)
045: * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int)
046: */
047: protected void drawCompositeImage(int width, int height) {
048: ImageData bg;
049: if (fBase == null || (bg = fBase.getImageData()) == null) {
050: bg = DEFAULT_IMAGE_DATA;
051: }
052: drawImage(bg, 0, 0);
053:
054: if (fOverlay != null) {
055: drawTopRight(fOverlay);
056: }
057: }
058:
059: /**
060: * @param overlay the additional image (a pin for example)
061: * to be drawn on top of the main image
062: */
063: protected void drawTopRight(ImageDescriptor overlay) {
064: if (overlay == null) {
065: return;
066: }
067: int x = getSize().x;
068: ImageData id = overlay.getImageData();
069: x -= id.width;
070: drawImage(id, x, 0);
071: }
072:
073: /* (non-Javadoc)
074: * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize()
075: */
076: protected Point getSize() {
077: return fSize;
078: }
079:
080: /*
081: * (non-Javadoc)
082: * @see java.lang.Object#hashCode()
083: */
084: public int hashCode() {
085: return Util.hashCode(fBase) * 17 + Util.hashCode(fOverlay);
086: }
087:
088: /* (non-Javadoc)
089: * @see java.lang.Object#equals(java.lang.Object)
090: */
091: public boolean equals(Object obj) {
092: if (!(obj instanceof OverlayIcon)) {
093: return false;
094: }
095: OverlayIcon overlayIcon = (OverlayIcon) obj;
096: return Util.equals(this.fBase, overlayIcon.fBase)
097: && Util.equals(this.fOverlay, overlayIcon.fOverlay)
098: && Util.equals(this.fSize, overlayIcon.fSize);
099: }
100: }
|