001: /*******************************************************************************
002: * Copyright (c) 2005, 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.cheatsheets.composite.explorer;
011:
012: import org.eclipse.jface.resource.*;
013: import org.eclipse.swt.graphics.*;
014:
015: /**
016: * An OverlayIcon consists of a main icon and several adornments.
017: */
018: public abstract class AbstractOverlayIcon extends
019: CompositeImageDescriptor {
020:
021: static final int DEFAULT_WIDTH = 16;
022: static final int DEFAULT_HEIGHT = 16;
023:
024: private Point fSize = null;
025:
026: private ImageDescriptor fOverlays[][];
027:
028: public AbstractOverlayIcon(ImageDescriptor[][] overlays) {
029: this (overlays, null);
030: }
031:
032: public AbstractOverlayIcon(ImageDescriptor[][] overlays, Point size) {
033: fOverlays = overlays;
034: if (size != null)
035: fSize = size;
036: else
037: fSize = new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
038: }
039:
040: protected void drawBottomLeft(ImageDescriptor[] overlays) {
041: if (overlays == null)
042: return;
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: int length = overlays.length;
058: int x = getSize().x;
059: for (int i = 2; i >= 0; i--) {
060: if (i < length && overlays[i] != null) {
061: ImageData id = overlays[i].getImageData();
062: x -= id.width;
063: drawImage(id, x, getSize().y - id.height);
064: }
065: }
066: }
067:
068: protected abstract ImageData getBaseImageData();
069:
070: protected void drawCompositeImage(int width, int height) {
071: ImageData base = getBaseImageData();
072: drawImage(base, 0, 0);
073: if (fOverlays != null) {
074: if (fOverlays.length > 0)
075: drawTopRight(fOverlays[0]);
076:
077: if (fOverlays.length > 1)
078: drawBottomRight(fOverlays[1]);
079:
080: if (fOverlays.length > 2)
081: drawBottomLeft(fOverlays[2]);
082:
083: if (fOverlays.length > 3)
084: drawTopLeft(fOverlays[3]);
085: }
086: }
087:
088: protected void drawTopLeft(ImageDescriptor[] overlays) {
089: if (overlays == null)
090: return;
091: int length = overlays.length;
092: int x = 0;
093: for (int i = 0; i < 3; i++) {
094: if (i < length && overlays[i] != null) {
095: ImageData id = overlays[i].getImageData();
096: drawImage(id, x, 0);
097: x += id.width;
098: }
099: }
100: }
101:
102: protected void drawTopRight(ImageDescriptor[] overlays) {
103: if (overlays == null)
104: return;
105: int length = overlays.length;
106: int x = getSize().x;
107: for (int i = 2; i >= 0; i--) {
108: if (i < length && overlays[i] != null) {
109: ImageData id = overlays[i].getImageData();
110: x -= id.width;
111: drawImage(id, x, 0);
112: }
113: }
114: }
115:
116: protected Point getSize() {
117: return fSize;
118: }
119: }
|