KickJava   Java API By Example, From Geeks To Geeks.

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


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.ui.ISharedImages;
17 import org.eclipse.ui.internal.WorkbenchImages;
18
19 /**
20  * An image descriptor that loads its data from a program file.
21  */

22 public class ProgramImageDescriptor extends ImageDescriptor {
23     private String JavaDoc filename;
24
25     private int offset;
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 ProgramImageDescriptor(String JavaDoc fullPath, int offsetInFile) {
32         filename = fullPath;
33         offset = offsetInFile;
34     }
35
36     /**
37      * @see Object#equals
38      */

39     public boolean equals(Object JavaDoc o) {
40         if (!(o instanceof ProgramImageDescriptor)) {
41             return false;
42         }
43         ProgramImageDescriptor other = (ProgramImageDescriptor) o;
44         return filename.equals(other.filename) && offset == other.offset;
45     }
46
47     /**
48      * Returns an SWT Image that is described by the information
49      * in this descriptor. Each call returns a new Image.
50      */

51     public Image getImage() {
52         return createImage();
53     }
54
55     /**
56      * Returns an SWT Image that is described by the information
57      * in this descriptor.
58      */

59     public ImageData getImageData() {
60         /*This is a user defined offset into the file which always
61          *returns us the defualt - return the default regardless*/

62
63         return WorkbenchImages.getImageDescriptor(ISharedImages.IMG_OBJ_FILE)
64                 .getImageData();
65     }
66
67     /**
68      * @see Object#hashCode
69      */

70     public int hashCode() {
71         return filename.hashCode() + offset;
72     }
73 }
74
Popular Tags