Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8eef9dc0228f26abbd6395387363b7afdc64733d (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
package org.eclipse.ui.externaltools.internal.ant.view.actions;

/**********************************************************************
Copyright (c) 2003 IBM Corp.  All rights reserved.
This file is 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
**********************************************************************/

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.program.Program;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

/**
 * Copy of org.eclipse.ui.internal.misc.ExternalProgramImageDescriptor for
 * use in the AntViewOpenWithMenu
 */
public class EditorImageDescriptor extends ImageDescriptor {

	public Program program;

	/**
	 * Creates a new ImageDescriptor. The image is loaded 
	 * from a file with the given name <code>name</code>.
	 */
	public EditorImageDescriptor(Program program) {
		this.program = program;
	}
	/**
	 * @see Object#equals
	 */
	public boolean equals(Object o) {
		if (!(o instanceof EditorImageDescriptor)) {
			return false;
		}
		EditorImageDescriptor other = (EditorImageDescriptor) o;

		//See if there is a name - compare it if so and compare the programs if not
		String otherName = other.program.getName();
		if (otherName == null) {
			return other.program.equals(program);
		} else {
			return otherName.equals(program.getName());
		}
	}
	/**
	 * Returns an SWT Image that is described by the information
	 * in this descriptor.  Each call returns a new Image.
	 */
	public Image getImage() {
		return createImage();
	}
	
	/**
	 * @see org.eclipse.jface.resource.ImageDescriptor#getImageData()
	 */
	public ImageData getImageData() {
		
		ImageData defaultImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE).getImageData();
		if (defaultImage == null) {
			return null;
		}
		ImageData data = null;
		if (program == null || ((data = program.getImageData()) == null)) {
			return defaultImage;
		}

		//The images in GNOME are too big. Scaling them does not give nice result so return defaultImage;
		if (data.height > defaultImage.height || data.width > defaultImage.width) {
			return defaultImage;
		}

		return data;
	}
	/**
	 * @see Object#hashCode
	 */
	public int hashCode() {
		String programName = program.getName();
		if (programName == null) {
			return program.hashCode();
		} else {
			return programName.hashCode();
		}
	}
}

Back to the top