2003/12/17 04:13:27
[org.ibex.core.git] / src / org / xwt / Picture.java
index f0eafec..2bffb65 100644 (file)
@@ -33,8 +33,29 @@ public class Picture {
         final Picture p = ret;
         if (!ret.isLoaded && callback != null)
             new java.lang.Thread() { public void run() {
+                // get the InputStream for the image
+                InputStream in = null;
+                try { in = r.getInputStream(); }
+                catch (IOException e) {
+                    in = null;
+                    if (r instanceof Res.Ref) {
+                        // add extensions to the resource, looking for the image
+                        Res.Ref ref = (Res.Ref)r;
+                        Res newr;
+
+                        String[] exts = new String[] { ".png", ".jpg", ".jpeg", ".gif" };
+                        for (int i=0; i < exts.length && in == null; i++) {
+                            newr = ref.addExtension(exts[i]);
+                            try { in = newr.getInputStream(); }
+                            catch (IOException f) { in = null; }
+                        }
+                    }
+                }
+
+                if (in == null) return; // could not find image
+
                 try {
-                    PushbackInputStream pbis = new PushbackInputStream(r.getInputStream());
+                    PushbackInputStream pbis = new PushbackInputStream(in);
                     int firstByte = pbis.read();
                     if (firstByte == -1) throw new JSExn("empty stream reading image");
                     pbis.unread(firstByte);
@@ -48,6 +69,7 @@ public class Picture {
                     Log.log(this, e);
                 }
             } }.start();
+
         return ret;
     }
 }