2003/12/25 08:52:13
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:43:14 +0000 (07:43 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:43:14 +0000 (07:43 +0000)
darcs-hash:20040130074314-2ba56-ba27ad6a14537da8ac70e93659d30eb2d0ea1b5d.gz

src/org/xwt/Box.java
src/org/xwt/Picture.java
src/org/xwt/Scheduler.java
src/org/xwt/plat/AWT.java

index 98fb49e..0e4a30b 100644 (file)
@@ -172,6 +172,8 @@ public final class Box extends JSScope implements Scheduler.Task {
 
     /** invoked when a resource needed to render ourselves finishes loading */
     public void perform() throws JSExn {
+
+        // FIXME; we can't assume that just because we were performed the image is loaded.
         // as external events have occured, check the state of box
         if (texture != null) {
            if (texture.isLoaded) { minwidth = texture.width; minheight = texture.height; }
@@ -621,7 +623,6 @@ public final class Box extends JSScope implements Scheduler.Task {
             return;
         }
         if (!(value instanceof Res)) return;
-
         texture = Picture.load((Res)value, this);
     }
 
index 2bffb65..8538d39 100644 (file)
@@ -35,15 +35,19 @@ public class Picture {
             new java.lang.Thread() { public void run() {
                 // get the InputStream for the image
                 InputStream in = null;
-                try { in = r.getInputStream(); }
-                catch (IOException e) {
+                try {
+                    in = r.getInputStream();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                    Log.log(Picture.class, 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" };
+                        String[] exts = new String[] { ".png", ".jpeg", ".gif" };
                         for (int i=0; i < exts.length && in == null; i++) {
                             newr = ref.addExtension(exts[i]);
                             try { in = newr.getInputStream(); }
@@ -51,8 +55,9 @@ public class Picture {
                         }
                     }
                 }
-
-                if (in == null) return; // could not find image
+        
+                // could not find image
+                if (in == null) { Log.log(Picture.class, "couldn't load image for resource " + r); return; }
 
                 try {
                     PushbackInputStream pbis = new PushbackInputStream(in);
@@ -63,6 +68,7 @@ public class Picture {
                     else if ((firstByte & 0xff) == 137)  PNG.load(pbis, p);
                     else if ((firstByte & 0xff) == 0xff) Platform.decodeJPEG(pbis, p);
                     else throw new JSExn("couldn't figure out image type from first byte");
+                    p.isLoaded = true;
                     Scheduler.add(callback);
                 } catch (Exception e) {
                     Log.log(this, "exception while loading image");
index 55be6df..ce59d1e 100644 (file)
@@ -59,7 +59,7 @@ public class Scheduler {
                 if (runnable.size() == 0 && Surface.needRender) Surface.renderAll.perform();
             } catch (JSExn e) {
                 Log.log(Scheduler.class, "a JavaScript thread spawned with xwt.thread() threw an exception:");
-                Log.log(Scheduler.class, e.toString());
+                Log.log(Scheduler.class, e);
             } catch (Exception e) {
                 Log.log(Scheduler.class, "a Task threw an exception which was caught by the scheduler:");
                 Log.log(Scheduler.class, e);
index 44c43f0..513834f 100644 (file)
@@ -141,7 +141,6 @@ public class AWT extends JVM {
     }
 
     protected static class AWTPicture extends Picture {
-        int[] data = null;
         public Image i = null;
         private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
         
@@ -308,7 +307,6 @@ public class AWT extends JVM {
 
         AWTSurface(Box root, boolean framed) {
             super(root);
-            System.out.println("Y");
             try {
                 if (framed) window = frame = new InnerFrame();
                 else window = new InnerWindow();