make core compile with new js stuff and Task replacement class
[org.ibex.core.git] / src / org / ibex / graphics / Surface.java
index a6b8447..6beebac 100644 (file)
@@ -16,7 +16,7 @@ import org.ibex.core.*;  // FIXME
  *  Platform subclasses should include an inner class subclass of
  *  Surface to return from the Platform._createSurface() method
  */
-public abstract class Surface extends PixelBuffer implements Task {
+public abstract class Surface extends PixelBuffer implements Callable {
 
     // Static Data ////////////////////////////////////////////////////////////////////////////////
 
@@ -96,13 +96,14 @@ public abstract class Surface extends PixelBuffer implements Task {
         if (button == 1) new Message("_Press1", T, root);
         else if (button == 2) new Message("_Press2", T, root);
         else if (button == 3) {
-            Scheduler.add(new Task() { public void perform() throws JSExn {
+            Scheduler.add(new Callable() { public Object run(Object o) throws JSExn {
                 Platform.clipboardReadEnabled = true;
                 try {
                     root.putAndTriggerTraps(JSU.S("_Press3"), T);
                 } finally {
                     Platform.clipboardReadEnabled = false;
                 }
+                return null;
             }});
         }
     }
@@ -135,9 +136,9 @@ public abstract class Surface extends PixelBuffer implements Task {
 
     private final static JS MOVE = JSU.S("_Move");
     /** we enqueue ourselves in the Scheduler when we have a Move message to deal with */
-    private Task mover = new Task() {
-            public void perform() {
-                if (mousex == newmousex && mousey == newmousey) return;
+    private Callable mover = new Callable() {
+        public Object run(Object o) {
+                if (mousex == newmousex && mousey == newmousey) return null;
                 int oldmousex = mousex;     mousex = newmousex;
                 int oldmousey = mousey;     mousey = newmousey;
                 String oldcursor = cursor;  cursor = "default";
@@ -145,6 +146,7 @@ public abstract class Surface extends PixelBuffer implements Task {
                 if (oldmousex != mousex || oldmousey != mousey)
                     root.putAndTriggerTrapsAndCatchExceptions(MOVE, T);
                 if (!cursor.equals(oldcursor)) syncCursor();
+                return null;
             } };
 
     /**
@@ -176,10 +178,11 @@ public abstract class Surface extends PixelBuffer implements Task {
 
     // FEATURE: can we avoid creating objects here?
     protected final void PosChange(final int x, final int y) {
-        Scheduler.add(new Task() { public void perform() throws JSExn {
+        Scheduler.add(new Callable() { public Object run(Object o) throws JSExn {
             root.x = x;
             root.y = y;
             root.putAndTriggerTrapsAndCatchExceptions(JSU.S("PosChange"), T);
+            return null;
         }});
     }
 
@@ -194,7 +197,7 @@ public abstract class Surface extends PixelBuffer implements Task {
 
     private boolean scheduled = false;
     public void Refresh() { if (!scheduled) Scheduler.add(this); scheduled = true; }
-    public void perform() { scheduled = false; Scheduler.renderAll(); }
+    public Object run(Object o) { scheduled = false; Scheduler.renderAll(); return null; }
 
     public final void setMaximized(boolean b) { if (b != maximized) _setMaximized(maximized = b); }
     public final void setMinimized(boolean b) { if (b != minimized) _setMinimized(minimized = b); }
@@ -305,7 +308,7 @@ public abstract class Surface extends PixelBuffer implements Task {
     }
 
     // FEATURE: reinstate recycler
-    public class Message implements Task {
+    public class Message implements Callable {
         
         private Box boxContainingMouse;
         private JS value;
@@ -318,32 +321,33 @@ public abstract class Surface extends PixelBuffer implements Task {
             Scheduler.add(this);
         }
         
-        public void perform() throws JSExn {
+        public Object run(Object o) throws JSExn {
             if (name.equals("_KeyPressed")) {
-                String value = JS.toString(this.value);
+                String value = JSU.toString(this.value);
                 if (value.toLowerCase().endsWith("shift")) shift = true;     else if (shift) value = value.toUpperCase();
                 if (value.toLowerCase().equals("alt")) alt = true;           else if (alt) value = "A-" + value;
                 if (value.toLowerCase().endsWith("control")) control = true; else if (control) value = "C-" + value;
                 if (value.equals("C-v") || value.equals("A-v")) Platform.clipboardReadEnabled = true;
                 this.value = JSU.S(value);
             } else if (name.equals("_KeyReleased")) {
-                String value = JS.toString(this.value);
+                String value = JSU.toString(this.value);
                 if (value.toLowerCase().equals("alt")) alt = false;
                 else if (value.toLowerCase().equals("control")) control = false;
                 else if (value.toLowerCase().equals("shift")) shift = false;
                 this.value = JSU.S(value);
             } else if (name.equals("_HScroll") || name.equals("_VScroll")) {
                 // FIXME: technically points != pixels
-                if (JS.isInt(value))
-                    value = JSU.N(JS.toInt(value) * root.fontSize());
+                if (JSU.isInt(value))
+                    value = JSU.N(JSU.toInt(value) * root.fontSize());
             }
             try {
                 boxContainingMouse.putAndTriggerTrapsAndCatchExceptions(JSU.S(name), value);
             } finally {
                 Platform.clipboardReadEnabled = false;
             }
+            return null;
         }
-        public String toString() { return "Message [name=" + name + ", value=" + JS.debugToString(value) + "]"; }
+        public String toString() { return "Message [name=" + name + ", value=" + JSU.str(value) + "]"; }
     }