diff dwtx/jface/resource/FileImageDescriptor.d @ 38:c884a1ab6db3

resource loading, fix type in image names
author Frank Benoit <benoit@tionex.de>
date Sun, 06 Apr 2008 14:15:58 +0200
parents c87617952847
children da5ad8eedf5d
line wrap: on
line diff
--- a/dwtx/jface/resource/FileImageDescriptor.d	Sun Apr 06 13:21:48 2008 +0200
+++ b/dwtx/jface/resource/FileImageDescriptor.d	Sun Apr 06 14:15:58 2008 +0200
@@ -28,6 +28,7 @@
 import dwt.dwthelper.InputStream;
 import dwt.dwthelper.FileInputStream;
 import dwt.dwthelper.BufferedInputStream;
+import dwt.dwthelper.ByteArrayInputStream;
 
 /**
  * An image descriptor that loads its image information
@@ -39,12 +40,13 @@
      * The class whose resource directory contain the file,
      * or <code>null</code> if none.
      */
-    private ClassInfo location;
+//     private ClassInfo location;
 
     /**
      * The name of the file.
      */
-    private String name;
+//     private String name;
+    private void[] importdata;
 
     /**
      * Creates a new file image descriptor.
@@ -60,9 +62,10 @@
      *   <code>null</code>
      * @param filename the name of the file
      */
-    this(ClassInfo clazz, String filename) {
-        this.location = clazz;
-        this.name = filename;
+    this(void[] importdata/+ClassInfo clazz, String filename+/) {
+//         this.location = clazz;
+//         this.name = filename;
+        this.importdata = importdata;
     }
 
     /* (non-Javadoc)
@@ -73,16 +76,16 @@
             return false;
         }
         FileImageDescriptor other = cast(FileImageDescriptor) o;
-        if (location !is null) {
-            if ( location.name != other.location.name ) {
-                return false;
-            }
-        } else {
-            if (other.location !is null) {
-                return false;
-            }
-        }
-        return name == other.name;
+//         if (location !is null) {
+//             if ( location.name != other.location.name ) {
+//                 return false;
+//             }
+//         } else {
+//             if (other.location !is null) {
+//                 return false;
+//             }
+//         }
+        return importdata == other.importdata;
     }
 
     /* (non-Javadoc)
@@ -117,16 +120,17 @@
     private InputStream getStream() {
         InputStream is_ = null;
 
-        if (location !is null) {
-            is_ = ClassInfoGetResourceAsStream( location, name);
+//         if (location !is null) {
+            is_ = new ByteArrayInputStream(cast(byte[]) importdata);
+//             is_ = ClassInfoGetResourceAsStream( location, name);
 
-        } else {
-            try {
-                is_ = new FileInputStream(name);
-            } catch (/+FileNotFoundException+/ IOException e) {
-                return null;
-            }
-        }
+//         } else {
+//             try {
+//                 is_ = new FileInputStream(name);
+//             } catch (/+FileNotFoundException+/ IOException e) {
+//                 return null;
+//             }
+//         }
         if (is_ is null) {
             return null;
         } else {
@@ -138,10 +142,10 @@
      * Method declared on Object.
      */
     public override hash_t toHash() {
-        int code = dwt.dwthelper.utils.toHash(name);
-        if (location !is null) {
-            code += location.toHash();
-        }
+        int code = dwt.dwthelper.utils.toHash(cast(char[])importdata/+name+/);
+//         if (location !is null) {
+//             code += location.toHash();
+//         }
         return code;
     }
 
@@ -153,6 +157,7 @@
      * returns a string representation of this object which is suitable only for debugging.
      */
     public override String toString() {
-        return "FileImageDescriptor(location=" ~ location.toString() ~ ", name=" ~ name ~ ")";//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
+//         return "FileImageDescriptor(location=" ~ location.toString() ~ ", name=" ~ name ~ ")";//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
+        return "FileImageDescriptor()";//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
     }
 }