Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1c17ded85b09ddf99b32781a2dcfa5585ed96483 (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
/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.compare.internal;

import org.eclipse.swt.graphics.*;

import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;

/**
 * Combines an image with an overlay.
 */
public class DiffImage extends CompositeImageDescriptor {

	static final int HEIGHT= 16;

	private Image fBaseImage;
	private ImageDescriptor fOverlayImage;
	private int fWidth;
	private boolean fLeft= true;

	public DiffImage(Image base, ImageDescriptor overlay, int w) {
		fBaseImage= base;
		fOverlayImage= overlay;
		fWidth= w;
	}

	public DiffImage(Image base, ImageDescriptor overlay, int w, boolean onLeft) {
		fBaseImage= base;
		fOverlayImage= overlay;
		fWidth= w;
		fLeft= onLeft;
	}

	protected Point getSize() {
		return new Point(fWidth, HEIGHT);
	}

	protected void drawCompositeImage(int width, int height) {
		if (fLeft) {
			if (fBaseImage != null) {
				ImageData base= fBaseImage.getImageData();
				if (base == null)
					base= DEFAULT_IMAGE_DATA;
				drawImage(base, fWidth - base.width, 0);
			}
	
			if (fOverlayImage != null) {
				ImageData overlay= fOverlayImage.getImageData();
				if (overlay == null)
					overlay= DEFAULT_IMAGE_DATA;
				drawImage(overlay, 0, (HEIGHT - overlay.height) / 2);
			}
		} else {
			if (fBaseImage != null) {
				ImageData base= fBaseImage.getImageData();
				if (base == null)
					base= DEFAULT_IMAGE_DATA;
				drawImage(base, 0, 0);
			}
	
			if (fOverlayImage != null) {
				ImageData overlay= fOverlayImage.getImageData();
				if (overlay == null)
					overlay= DEFAULT_IMAGE_DATA;
				drawImage(overlay, fWidth - overlay.width, (HEIGHT - overlay.height) / 2);
			}
		}
	}
}

Back to the top