Mercurial > projects > dwt-addons
annotate dwtx/jface/resource/FileImageDescriptor.d @ 43:ea8ff534f622
Fix override and super aliases
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 11 Apr 2008 01:24:25 +0200 |
parents | da5ad8eedf5d |
children | 46a6e0e6ccd4 |
rev | line source |
---|---|
4 | 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.resource.FileImageDescriptor; | |
14 | |
15 import dwtx.jface.resource.ImageDescriptor; | |
16 | |
17 // import java.io.BufferedInputStream; | |
18 // import java.io.FileInputStream; | |
19 // import java.io.FileNotFoundException; | |
20 // import java.io.IOException; | |
21 // import java.io.InputStream; | |
22 | |
23 import dwt.DWT; | |
24 import dwt.DWTException; | |
25 import dwt.graphics.ImageData; | |
26 | |
27 import dwt.dwthelper.utils; | |
28 import dwt.dwthelper.InputStream; | |
29 import dwt.dwthelper.FileInputStream; | |
30 import dwt.dwthelper.BufferedInputStream; | |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
31 import dwt.dwthelper.ByteArrayInputStream; |
4 | 32 |
40
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
33 import tango.util.log.Trace; |
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
34 |
4 | 35 /** |
36 * An image descriptor that loads its image information | |
37 * from a file. | |
38 */ | |
39 class FileImageDescriptor : ImageDescriptor { | |
40 | |
41 /** | |
42 * The class whose resource directory contain the file, | |
43 * or <code>null</code> if none. | |
44 */ | |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
45 // private ClassInfo location; |
4 | 46 |
47 /** | |
48 * The name of the file. | |
49 */ | |
40
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
50 private String name; |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
51 private void[] importdata; |
4 | 52 |
53 /** | |
54 * Creates a new file image descriptor. | |
55 * The file has the given file name and is located | |
56 * in the given class's resource directory. If the given | |
57 * class is <code>null</code>, the file name must be absolute. | |
58 * <p> | |
59 * Note that the file is not accessed until its | |
60 * <code>getImageDate</code> method is called. | |
61 * </p> | |
62 * | |
63 * @param clazz class for resource directory, or | |
64 * <code>null</code> | |
65 * @param filename the name of the file | |
66 */ | |
40
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
67 this(ImportData importdata) { |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
68 // this.location = clazz; |
40
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
69 this.name = importdata.name; |
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
70 this.importdata = importdata.data; |
4 | 71 } |
72 | |
73 /* (non-Javadoc) | |
74 * Method declared on Object. | |
75 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
76 public override int opEquals(Object o) { |
4 | 77 if (!( cast(FileImageDescriptor)o )) { |
78 return false; | |
79 } | |
80 FileImageDescriptor other = cast(FileImageDescriptor) o; | |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
81 // if (location !is null) { |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
82 // if ( location.name != other.location.name ) { |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
83 // return false; |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
84 // } |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
85 // } else { |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
86 // if (other.location !is null) { |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
87 // return false; |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
88 // } |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
89 // } |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
90 return importdata == other.importdata; |
4 | 91 } |
92 | |
93 /* (non-Javadoc) | |
94 * Method declared on ImageDesciptor. | |
95 * Returns null if the image data cannot be read. | |
96 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
40
diff
changeset
|
97 public override ImageData getImageData() { |
4 | 98 InputStream in_ = getStream(); |
99 ImageData result = null; | |
100 if (in_ !is null) { | |
101 try { | |
102 result = new ImageData(in_); | |
103 } catch (DWTException e) { | |
40
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
104 if (e.code !is DWT.ERROR_INVALID_IMAGE /+&& e.code !is DWT.ERROR_UNSUPPORTED_FORMAT+/) { |
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
105 Trace.formatln( "FileImageDescriptor getImageData DWTException for name={}", name ); |
4 | 106 throw e; |
107 // fall through otherwise | |
108 } | |
109 } finally { | |
110 in_.close(); | |
111 } | |
112 } | |
113 return result; | |
114 } | |
115 | |
116 /** | |
117 * Returns a stream on the image contents. Returns | |
118 * null if a stream could not be opened. | |
119 * | |
120 * @return the buffered stream on the file or <code>null</code> | |
121 * if the file cannot be found | |
122 */ | |
123 private InputStream getStream() { | |
124 InputStream is_ = null; | |
125 | |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
126 // if (location !is null) { |
40
da5ad8eedf5d
debug prints, dwt.dwthelper restructure, ...
Frank Benoit <benoit@tionex.de>
parents:
38
diff
changeset
|
127 // Trace.formatln( "FileImageDescriptor getStream importdata.length={} name={}",importdata.length, name ); |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
128 is_ = new ByteArrayInputStream(cast(byte[]) importdata); |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
129 // is_ = ClassInfoGetResourceAsStream( location, name); |
4 | 130 |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
131 // } else { |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
132 // try { |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
133 // is_ = new FileInputStream(name); |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
134 // } catch (/+FileNotFoundException+/ IOException e) { |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
135 // return null; |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
136 // } |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
137 // } |
4 | 138 if (is_ is null) { |
139 return null; | |
140 } else { | |
141 return new BufferedInputStream(is_); | |
142 } | |
143 } | |
144 | |
145 /* (non-Javadoc) | |
146 * Method declared on Object. | |
147 */ | |
148 public override hash_t toHash() { | |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
149 int code = dwt.dwthelper.utils.toHash(cast(char[])importdata/+name+/); |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
150 // if (location !is null) { |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
151 // code += location.toHash(); |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
152 // } |
4 | 153 return code; |
154 } | |
155 | |
156 /* (non-Javadoc) | |
157 * Method declared on Object. | |
158 */ | |
159 /** | |
160 * The <code>FileImageDescriptor</code> implementation of this <code>Object</code> method | |
161 * returns a string representation of this object which is suitable only for debugging. | |
162 */ | |
163 public override String toString() { | |
38
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
164 // return "FileImageDescriptor(location=" ~ location.toString() ~ ", name=" ~ name ~ ")";//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ |
c884a1ab6db3
resource loading, fix type in image names
Frank Benoit <benoit@tionex.de>
parents:
4
diff
changeset
|
165 return "FileImageDescriptor()";//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ |
4 | 166 } |
167 } |