KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > views > actions > EditorImageDescriptor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.ant.internal.ui.views.actions;
12
13
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.swt.graphics.Image;
16 import org.eclipse.swt.graphics.ImageData;
17 import org.eclipse.swt.program.Program;
18 import org.eclipse.ui.ISharedImages;
19 import org.eclipse.ui.PlatformUI;
20
21 /**
22  * Copy of org.eclipse.ui.internal.misc.ExternalProgramImageDescriptor for
23  * use in the AntViewOpenWithMenu
24  */

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

33     public EditorImageDescriptor(Program program) {
34         this.program = program;
35     }
36     /* (non-Javadoc)
37      * @see java.lang.Object#equals(java.lang.Object)
38      */

39     public boolean equals(Object JavaDoc o) {
40         if (!(o instanceof EditorImageDescriptor)) {
41             return false;
42         }
43         EditorImageDescriptor other = (EditorImageDescriptor) 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         }
50         return otherName.equals(program.getName());
51     }
52     /**
53      * Returns an SWT Image that is described by the information
54      * in this descriptor. Each call returns a new Image.
55      */

56     public Image getImage() {
57         return createImage();
58     }
59     
60     /**
61      * @see org.eclipse.jface.resource.ImageDescriptor#getImageData()
62      */

63     public ImageData getImageData() {
64         
65         ImageData defaultImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE).getImageData();
66         if (defaultImage == null) {
67             return null;
68         }
69         ImageData data = null;
70         if (program == null || ((data = program.getImageData()) == null)) {
71             return defaultImage;
72         }
73
74         //The images in GNOME are too big. Scaling them does not give nice result so return defaultImage;
75
if (data.height > defaultImage.height || data.width > defaultImage.width) {
76             return defaultImage;
77         }
78
79         return data;
80     }
81     
82     /* (non-Javadoc)
83      * @see java.lang.Object#hashCode()
84      */

85     public int hashCode() {
86         String JavaDoc programName = program.getName();
87         if (programName == null) {
88             return program.hashCode();
89         }
90         return programName.hashCode();
91     }
92 }
93
Popular Tags