Revision: 4686
          http://sourceforge.net/p/vexi/code/4686
Author:   mkpg2
Date:     2014-04-17 18:22:57 +0000 (Thu, 17 Apr 2014)
Log Message:
-----------
New method vexi.ui.loadImage.
- synchronously loads an image
- can be sure an image is valid before assigning it, and can handle exceptions 
thrown when loading it

Modified Paths:
--------------
    branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/GIF.java
    branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/PNG.java
    
branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Picture.java
    branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp

Modified: 
branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/GIF.java
===================================================================
--- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/GIF.java  
2014-04-10 18:42:20 UTC (rev 4685)
+++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/GIF.java  
2014-04-17 18:22:57 UTC (rev 4686)
@@ -77,9 +77,7 @@
         if (is instanceof BufferedInputStream) _in = (BufferedInputStream)is;
         else _in = new BufferedInputStream(is);
         decodeAsBufferedImage(0);
-        p.isLoaded = true;
-        p = null;
-        _in = null;
+        this.p = null;
     }
 
 

Modified: 
branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/PNG.java
===================================================================
--- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/PNG.java  
2014-04-10 18:42:20 UTC (rev 4685)
+++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/PNG.java  
2014-04-17 18:22:57 UTC (rev 4686)
@@ -106,7 +106,6 @@
             inputStream.readInt();
             needChunkInfo = true;
         }
-        p.isLoaded = true;
     }
     
     static private void skip(InputStream is, int n) throws IOException {

Modified: 
branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Picture.java
===================================================================
--- 
branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Picture.java  
    2014-04-10 18:42:20 UTC (rev 4685)
+++ 
branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Picture.java  
    2014-04-17 18:22:57 UTC (rev 4686)
@@ -77,7 +77,7 @@
                     Picture pic = (Picture)loadedPictures.elementAt(j);
                     int numcallbacks = pic.loadedCallbacks.size();
                     for (int i=0; i<numcallbacks; i++) {
-                        ((Callable)pic.loadedCallbacks.elementAt(i)).run(null);
+                        ((Callable)pic.loadedCallbacks.elementAt(i)).run(pic);
                     }
                     pic.loadedCallbacks.removeAllElements();
                     pic.loadedCallbacks = null;

Modified: branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp
===================================================================
--- branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp       
2014-04-10 18:42:20 UTC (rev 4685)
+++ branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp       
2014-04-17 18:22:57 UTC (rev 4686)
@@ -4,8 +4,6 @@
 
 package org.vexi.core;
 
-import java.awt.Desktop;
-import java.io.File;
 
 import org.ibex.crypto.MD5;
 import org.ibex.js.*;
@@ -15,6 +13,7 @@
 import org.ibex.util.Callable;
 import org.ibex.util.Encode;
 import org.vexi.graphics.Font;
+import org.vexi.graphics.Picture;
 import org.vexi.plat.Platform;
 import org.vexi.graphics.Color;
 import org.vexi.util.Log;
@@ -340,6 +339,7 @@
         case "ui.key.name": return getSub(name);
         case "ui.mouse": return getSub(name);
         case "ui.screen": return getSub(name);
+        case "ui.loadImage": return METHOD;
                
         case "desktop": return org.vexi.plat.Desktop.get();
         /* The version of the current Vexi core
@@ -786,6 +786,19 @@
                     ret.put(JSU.S("bottom"), JSU.N(s.bottomInset));
                     ret.put(JSU.S("right"), JSU.N(s.rightInset));
                     return ret;
+                case "ui.loadImage":
+                       final Scheduler sched = Scheduler.findCurrent();
+                       final Callable callback = sched.pauseJSThread();
+                       Picture.load(args[0], new Callable(){
+                               public Object run(Object o) throws Exception {
+                                       Picture p = (Picture)o;
+                                       // if loadFailed then interpreter will 
handle the exception
+                                       callback.run(p.loadFailed); 
+                                       return null;
+                               }
+                       });
+                       return null; // doesn't matter since we paused
+                       
                 case "unclone": return args[0].unclone();
                 //#end
                 break;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to