Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 20db8e922c97c28b2d3be369b27cf19e51926f56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*******************************************************************************
 *  Copyright (c) 2000, 2011 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.compare.internal.patch;

import java.util.Arrays;

import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;

/**
 * An DecoratorOverlayIcon consists of a main icon and several adornments.
 * Copied until bug 164394 is resolved.
 */
class DecoratorOverlayIcon extends CompositeImageDescriptor {
	// the base image
	private Image base;

	// the overlay images
	private ImageDescriptor[] overlays;

	// the size
	private Point size;


	/**
	 * OverlayIcon constructor.
	 *
	 * @param baseImage the base image
	 * @param overlaysArray the overlay images
	 * @param sizeValue the size
	 */
	public DecoratorOverlayIcon(Image baseImage,
			ImageDescriptor[] overlaysArray, Point sizeValue) {
		this.base = baseImage;
		this.overlays = overlaysArray;
		this.size = sizeValue;
	}

	/**
	 * Draw the overlays for the receiver.
	 * @param overlaysArray the overlay images
	 */
	protected void drawOverlays(ImageDescriptor[] overlaysArray) {

		for (int i = 0; i < overlays.length; i++) {
			ImageDescriptor overlay = overlaysArray[i];
			if (overlay == null) {
				continue;
			}
			ImageData overlayData = overlay.getImageData();
			//Use the missing descriptor if it is not there.
			if (overlayData == null) {
				overlayData = ImageDescriptor.getMissingImageDescriptor()
						.getImageData();
			}
			switch (i) {
			case IDecoration.TOP_LEFT:
				drawImage(overlayData, 0, 0);
				break;
			case IDecoration.TOP_RIGHT:
				drawImage(overlayData, size.x - overlayData.width, 0);
				break;
			case IDecoration.BOTTOM_LEFT:
				drawImage(overlayData, 0, size.y - overlayData.height);
				break;
			case IDecoration.BOTTOM_RIGHT:
				drawImage(overlayData, size.x - overlayData.width, size.y
						- overlayData.height);
				break;
			}
		}
	}

	@Override
	public boolean equals(Object o) {
		if (!(o instanceof DecoratorOverlayIcon)) {
			return false;
		}
		DecoratorOverlayIcon other = (DecoratorOverlayIcon) o;
		return base.equals(other.base)
				&& Arrays.equals(overlays, other.overlays);
	}

	@Override
	public int hashCode() {
		int code = base.hashCode();
		for (int i = 0; i < overlays.length; i++) {
			if (overlays[i] != null) {
				code ^= overlays[i].hashCode();
			}
		}
		return code;
	}

	@Override
	protected void drawCompositeImage(int width, int height) {
		ImageDescriptor underlay = overlays[IDecoration.UNDERLAY];
		if (underlay != null) {
			drawImage(underlay.getImageData(), 0, 0);
		}
		drawImage(base.getImageData(), 0, 0);
		drawOverlays(overlays);
	}

	@Override
	protected Point getSize() {
		return size;
	}

	@Override
	protected int getTransparentPixel() {
		return base.getImageData().transparentPixel;
	}

}

Back to the top