2 * Copyright (c) 2004 Christopher Lenz and others
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Christopher Lenz - initial version based on the internal Eclipse class
10 * org.eclipse.ui.internal.ide.misc.OverlayIcon
12 * $Id: OverlayImageDescriptor.java,v 1.2 2006-10-21 23:13:53 pombredanne Exp $
15 package net.sourceforge.phpeclipse.ui.views.util;
17 import org.eclipse.jface.resource.CompositeImageDescriptor;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.swt.graphics.ImageData;
20 import org.eclipse.swt.graphics.Point;
23 * An overlay image descriptor can add several overlay icons to a base image.
25 public class OverlayImageDescriptor extends CompositeImageDescriptor {
27 // Instance Variables ------------------------------------------------------
29 /** Size of the resulting composite image. */
30 private Point size = null;
32 /** The base image. */
33 private ImageDescriptor base;
35 /** The overlay images. */
36 private ImageDescriptor overlays[][];
38 // Constructors ------------------------------------------------------------
41 * Creates the image descriptor. The size of the resulting image will be the
42 * same as the size of the base image.
45 * the descriptor of the base image
47 * descriptors of the overlay images
49 public OverlayImageDescriptor(ImageDescriptor base,
50 ImageDescriptor[][] overlays) {
51 this(base, overlays, null);
55 * Creates the image descriptor.
58 * the descriptor of the base image
60 * descriptors of the overlay images
62 * the size of the composite image, or <tt>null</tt> to use the
63 * size of the base image
65 public OverlayImageDescriptor(ImageDescriptor base,
66 ImageDescriptor[][] overlays, Point size) {
68 this.overlays = overlays;
70 ImageData data = base.getImageData();
71 size = new Point(data.width, data.height);
76 // CompositeImageDescriptor Implementation ---------------------------------
79 * @see CompositeImageDescriptor#drawCompositeImage(int, int)
81 protected void drawCompositeImage(int width, int height) {
83 if ((base == null) || ((bg = base.getImageData()) == null)) {
84 bg = DEFAULT_IMAGE_DATA;
87 if (overlays != null) {
88 if (overlays.length > 0) {
89 drawTopRight(overlays[0]);
91 if (overlays.length > 1) {
92 drawBottomRight(overlays[1]);
94 if (overlays.length > 2) {
95 drawBottomLeft(overlays[2]);
97 if (overlays.length > 3) {
98 drawTopLeft(overlays[3]);
104 * @see CompositeImageDescriptor#getSize()
106 protected Point getSize() {
110 // Private Methods ---------------------------------------------------------
112 private void drawBottomLeft(ImageDescriptor[] descriptors) {
113 if (descriptors == null) {
116 int length = descriptors.length;
118 for (int i = 0; i < 3; i++) {
119 if ((i < length) && (descriptors[i] != null)) {
120 ImageData id = descriptors[i].getImageData();
121 drawImage(id, x, getSize().y - id.height);
127 private void drawBottomRight(ImageDescriptor[] descriptors) {
128 if (descriptors == null) {
131 int length = descriptors.length;
133 for (int i = 2; i >= 0; i--) {
134 if (i < length && descriptors[i] != null) {
135 ImageData id = descriptors[i].getImageData();
137 drawImage(id, x, getSize().y - id.height);
142 private void drawTopLeft(ImageDescriptor[] descriptors) {
143 if (descriptors == null) {
146 int length = descriptors.length;
148 for (int i = 0; i < 3; i++) {
149 if (i < length && descriptors[i] != null) {
150 ImageData id = descriptors[i].getImageData();
157 private void drawTopRight(ImageDescriptor[] descriptors) {
158 if (descriptors == null) {
161 int length = descriptors.length;
163 for (int i = 2; i >= 0; i--) {
164 if (i < length && descriptors[i] != null) {
165 ImageData id = descriptors[i].getImageData();