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.ide.misc;
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:
017: /**
018: * An OverlayIcon consists of a main icon and several adornments.
019: */
020: public class OverlayIcon extends CompositeImageDescriptor {
021:
022: static final int DEFAULT_WIDTH = 22;
023:
024: static final int DEFAULT_HEIGHT = 16;
025:
026: private Point fSize = null;
027:
028: private ImageDescriptor fBase;
029:
030: private ImageDescriptor fOverlays[][];
031:
032: public OverlayIcon(ImageDescriptor base,
033: ImageDescriptor[][] overlays, Point size) {
034: fBase = base;
035: fOverlays = overlays;
036: fSize = size;
037: }
038:
039: protected void drawBottomLeft(ImageDescriptor[] overlays) {
040: if (overlays == null) {
041: return;
042: }
043: int length = overlays.length;
044: int x = 0;
045: for (int i = 0; i < 3; i++) {
046: if (i < length && overlays[i] != null) {
047: ImageData id = overlays[i].getImageData();
048: drawImage(id, x, getSize().y - id.height);
049: x += id.width;
050: }
051: }
052: }
053:
054: protected void drawBottomRight(ImageDescriptor[] overlays) {
055: if (overlays == null) {
056: return;
057: }
058: int length = overlays.length;
059: int x = getSize().x;
060: for (int i = 2; i >= 0; i--) {
061: if (i < length && overlays[i] != null) {
062: ImageData id = overlays[i].getImageData();
063: x -= id.width;
064: drawImage(id, x, getSize().y - id.height);
065: }
066: }
067: }
068:
069: /**
070: * @see CompositeImageDescriptor#drawCompositeImage(int, int)
071: */
072: protected void drawCompositeImage(int width, int height) {
073: ImageData bg;
074: if (fBase == null || (bg = fBase.getImageData()) == null) {
075: bg = DEFAULT_IMAGE_DATA;
076: }
077: drawImage(bg, 0, 0);
078:
079: if (fOverlays != null) {
080: if (fOverlays.length > 0) {
081: drawTopRight(fOverlays[0]);
082: }
083:
084: if (fOverlays.length > 1) {
085: drawBottomRight(fOverlays[1]);
086: }
087:
088: if (fOverlays.length > 2) {
089: drawBottomLeft(fOverlays[2]);
090: }
091:
092: if (fOverlays.length > 3) {
093: drawTopLeft(fOverlays[3]);
094: }
095: }
096: }
097:
098: protected void drawTopLeft(ImageDescriptor[] overlays) {
099: if (overlays == null) {
100: return;
101: }
102: int length = overlays.length;
103: int x = 0;
104: for (int i = 0; i < 3; i++) {
105: if (i < length && overlays[i] != null) {
106: ImageData id = overlays[i].getImageData();
107: drawImage(id, x, 0);
108: x += id.width;
109: }
110: }
111: }
112:
113: protected void drawTopRight(ImageDescriptor[] overlays) {
114: if (overlays == null) {
115: return;
116: }
117: int length = overlays.length;
118: int x = getSize().x;
119: for (int i = 2; i >= 0; i--) {
120: if (i < length && overlays[i] != null) {
121: ImageData id = overlays[i].getImageData();
122: x -= id.width;
123: drawImage(id, x, 0);
124: }
125: }
126: }
127:
128: /**
129: * @see CompositeImageDescriptor#getSize()
130: */
131: protected Point getSize() {
132: return fSize;
133: }
134: }
|