01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.misc;
11:
12: import org.eclipse.jface.resource.ImageDescriptor;
13: import org.eclipse.swt.graphics.Image;
14: import org.eclipse.swt.graphics.ImageData;
15: import org.eclipse.swt.program.Program;
16: import org.eclipse.ui.ISharedImages;
17: import org.eclipse.ui.internal.WorkbenchImages;
18:
19: /**
20: * The external program image descriptor is the descriptor used to
21: * handle images that are from a Program.
22: */
23: public class ExternalProgramImageDescriptor extends ImageDescriptor {
24:
25: public Program program;
26:
27: /**
28: * Creates a new ImageDescriptor. The image is loaded
29: * from a file with the given name <code>name</code>.
30: */
31: public ExternalProgramImageDescriptor(Program program) {
32: this .program = program;
33: }
34:
35: /**
36: * @see Object#equals
37: */
38: public boolean equals(Object o) {
39: if (!(o instanceof ExternalProgramImageDescriptor)) {
40: return false;
41: }
42: ExternalProgramImageDescriptor other = (ExternalProgramImageDescriptor) o;
43:
44: //See if there is a name - compare it if so and compare the programs if not
45: String otherName = other.program.getName();
46: if (otherName == null) {
47: return other.program.equals(program);
48: } else {
49: return otherName.equals(program.getName());
50: }
51: }
52:
53: /**
54: * Returns an SWT Image that is described by the information
55: * in this descriptor. Each call returns a new Image.
56: */
57: public Image getImage() {
58: return createImage();
59: }
60:
61: /**
62: * Returns an SWT Image that is described by the information
63: * in this descriptor. Each call returns a new Image.
64: */
65: public ImageData getImageData() {
66: ImageData data = null;
67: ImageData defaultImage = WorkbenchImages.getImageDescriptor(
68: ISharedImages.IMG_OBJ_FILE).getImageData();
69: if (defaultImage == null) {
70: return null;
71: }
72:
73: if (program == null
74: || ((data = program.getImageData()) == null)) {
75: return defaultImage;
76: }
77:
78: //The images in GNOME are too big. Scaling them does not give nice result so return defaultImage;
79: if (data.height > defaultImage.height
80: || data.width > defaultImage.width) {
81: return defaultImage;
82: }
83:
84: return data;
85: }
86:
87: /**
88: * @see Object#hashCode
89: */
90: public int hashCode() {
91: String programName = program.getName();
92: if (programName == null) {
93: return program.hashCode();
94: } else {
95: return programName.hashCode();
96: }
97: }
98: }
|