Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4c579280ee0b0454847751b285668b364cfe254e (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
/*******************************************************************************
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Mylar project committers - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui;

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

/**
 * @author Mik Kersten
 */
public class CompositeTaskImageDescriptor extends CompositeImageDescriptor {

	private ImageData base;

	private ImageData kind;
	
	protected Point size;

	public static final int WIDTH_DECORATION = 6;
	
	private static final int WIDTH_ICON = 16;
		
	static int WIDTH;
	
	static {
		WIDTH = WIDTH_DECORATION + WIDTH_ICON;
	}
	
	public CompositeTaskImageDescriptor(ImageDescriptor icon, ImageDescriptor overlayKind) {
		this.base = getImageData(icon);
		if (overlayKind != null) {
			this.kind = getImageData(overlayKind);
		}
		this.size = new Point(WIDTH, base.height);
	}
	
	@Override
	protected void drawCompositeImage(int width, int height) {
		drawImage(base, WIDTH_DECORATION, 1);
		if (kind != null) {
			drawImage(kind, WIDTH_DECORATION+5, 6);
		}
	}

	private ImageData getImageData(ImageDescriptor descriptor) {
		ImageData data = descriptor.getImageData(); 
		// see bug 51965: getImageData can return null
		if (data == null) {
			data = DEFAULT_IMAGE_DATA;
		}
		return data;
	}

	@Override
	protected Point getSize() {
		return new Point(size.x, size.y);
	}
}

Back to the top