KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > misc > ExternalProgramImageDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.misc;
12
13 import org.eclipse.jface.resource.ImageDescriptor;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.graphics.ImageData;
16 import org.eclipse.swt.program.Program;
17 import org.eclipse.ui.ISharedImages;
18 import org.eclipse.ui.internal.WorkbenchImages;
19
20 /**
21  * The external program image descriptor is the descriptor used to
22  * handle images that are from a Program.
23  */

24 public class ExternalProgramImageDescriptor extends ImageDescriptor {
25
26     public Program program;
27
28     /**
29      * Creates a new ImageDescriptor. The image is loaded
30      * from a file with the given name <code>name</code>.
31      */

32     public ExternalProgramImageDescriptor(Program program) {
33         this.program = program;
34     }
35
36     /**
37      * @see Object#equals
38      */

39     public boolean equals(Object JavaDoc o) {
40         if (!(o instanceof ExternalProgramImageDescriptor)) {
41             return false;
42         }
43         ExternalProgramImageDescriptor other = (ExternalProgramImageDescriptor) o;
44
45         //See if there is a name - compare it if so and compare the programs if not
46
String JavaDoc otherName = other.program.getName();
47         if (otherName == null) {
48             return other.program.equals(program);
49         } else {
50             return otherName.equals(program.getName());
51         }
52     }
53
54     /**
55      * Returns an SWT Image that is described by the information
56      * in this descriptor. Each call returns a new Image.
57      */

58     public Image getImage() {
59         return createImage();
60     }
61
62     /**
63      * Returns an SWT Image that is described by the information
64      * in this descriptor. Each call returns a new Image.
65      */

66     public ImageData getImageData() {
67         ImageData data = null;
68         ImageData defaultImage = WorkbenchImages.getImageDescriptor(
69                 ISharedImages.IMG_OBJ_FILE).getImageData();
70         if (defaultImage == null) {
71             return null;
72         }
73
74         if (program == null || ((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 JavaDoc programName = program.getName();
92         if (programName == null) {
93             return program.hashCode();
94         } else {
95             return programName.hashCode();
96         }
97     }
98 }
99
Popular Tags