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.ui.ISharedImages;
16: import org.eclipse.ui.internal.WorkbenchImages;
17:
18: /**
19: * An image descriptor that loads its data from a program file.
20: */
21: public class ProgramImageDescriptor extends ImageDescriptor {
22: private String filename;
23:
24: private int offset;
25:
26: /**
27: * Creates a new ImageDescriptor. The image is loaded
28: * from a file with the given name <code>name</code>.
29: */
30: public ProgramImageDescriptor(String fullPath, int offsetInFile) {
31: filename = fullPath;
32: offset = offsetInFile;
33: }
34:
35: /**
36: * @see Object#equals
37: */
38: public boolean equals(Object o) {
39: if (!(o instanceof ProgramImageDescriptor)) {
40: return false;
41: }
42: ProgramImageDescriptor other = (ProgramImageDescriptor) o;
43: return filename.equals(other.filename)
44: && 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(
64: ISharedImages.IMG_OBJ_FILE).getImageData();
65: }
66:
67: /**
68: * @see Object#hashCode
69: */
70: public int hashCode() {
71: return filename.hashCode() + offset;
72: }
73: }
|