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.1 2004-09-02 18:26:28 jsurfer 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.
44 * @param base the descriptor of the base image
45 * @param overlays descriptors of the overlay images
47 public OverlayImageDescriptor(ImageDescriptor base,
48 ImageDescriptor[][] overlays) {
49 this(base, overlays, null);
53 * Creates the image descriptor.
55 * @param base the descriptor of the base image
56 * @param overlays descriptors of the overlay images
57 * @param size the size of the composite image, or <tt>null</tt> to use the
58 * size of the base image
60 public OverlayImageDescriptor(ImageDescriptor base,
61 ImageDescriptor[][] overlays, Point size) {
63 this.overlays = overlays;
65 ImageData data = base.getImageData();
66 size = new Point(data.width, data.height);
71 // CompositeImageDescriptor Implementation ---------------------------------
74 * @see CompositeImageDescriptor#drawCompositeImage(int, int)
76 protected void drawCompositeImage(int width, int height) {
78 if ((base == null) || ((bg = base.getImageData()) == null)) {
79 bg = DEFAULT_IMAGE_DATA;
82 if (overlays != null) {
83 if (overlays.length > 0) {
84 drawTopRight(overlays[0]);
86 if (overlays.length > 1) {
87 drawBottomRight(overlays[1]);
89 if (overlays.length > 2) {
90 drawBottomLeft(overlays[2]);
92 if (overlays.length > 3) {
93 drawTopLeft(overlays[3]);
99 * @see CompositeImageDescriptor#getSize()
101 protected Point getSize() {
105 // Private Methods ---------------------------------------------------------
107 private void drawBottomLeft(ImageDescriptor[] descriptors) {
108 if (descriptors == null) {
111 int length = descriptors.length;
113 for (int i = 0; i < 3; i++) {
114 if ((i < length) && (descriptors[i] != null)) {
115 ImageData id = descriptors[i].getImageData();
116 drawImage(id, x, getSize().y - id.height);
122 private void drawBottomRight(ImageDescriptor[] descriptors) {
123 if (descriptors == null) {
126 int length = descriptors.length;
128 for (int i = 2; i >= 0; i--) {
129 if (i < length && descriptors[i] != null) {
130 ImageData id = descriptors[i].getImageData();
132 drawImage(id, x, getSize().y - id.height);
137 private void drawTopLeft(ImageDescriptor[] descriptors) {
138 if (descriptors == null) {
141 int length = descriptors.length;
143 for (int i = 0; i < 3; i++) {
144 if (i < length && descriptors[i] != null) {
145 ImageData id = descriptors[i].getImageData();
152 private void drawTopRight(ImageDescriptor[] descriptors) {
153 if (descriptors == null) {
156 int length = descriptors.length;
158 for (int i = 2; i >= 0; i--) {
159 if (i < length && descriptors[i] != null) {
160 ImageData id = descriptors[i].getImageData();