[re]-merged in Brians stuff
[org.ibex.core.git] / src / org / ibex / core / Box.java
index 053357a..677fe0c 100644 (file)
@@ -38,7 +38,7 @@ import org.ibex.graphics.*;
  *  trigger a Surface.abort; if rendering were done in the same pass,
  *  rendering work done prior to the Surface.abort would be wasted.
  */
-public final class Box extends JSScope implements Task {
+public final class Box extends JS.O implements Task {
 
     // Macros //////////////////////////////////////////////////////////////////////
 
@@ -52,14 +52,12 @@ public final class Box extends JSScope implements Task {
     //#define CHECKSET_BOOLEAN(prop) boolean nu = toBoolean(value); if (nu == prop) break; prop = nu;
     //#define CHECKSET_STRING(prop) if ((value==null&&prop==null)||(value!=null&&JS.toString(value).equals(prop))) break; prop=JS.toString(value);
 
-    public Box() { super(null); }
-
     // FIXME memory leak
     static Hash boxToCursor = new Hash(500, 3);
 
     static final Font DEFAULT_FONT;
     static {
-        try { DEFAULT_FONT = Font.getFont(Main.builtin.get(JS.S("fonts/vera/Vera.ttf")), 10); }
+        try { DEFAULT_FONT = Font.getFont((JS)Main.builtin.get(JS.S("fonts/vera/Vera.ttf")), 10); }
         catch(JSExn e) { throw new Error("Error loading default font: " + e); }
     }
 
@@ -99,6 +97,8 @@ public final class Box extends JSScope implements Task {
     Box redirect = this;
     int flags = VISIBLE | PACKED | REPACK | RECONSTRAIN | REPLACE | FIXED | STOP_UPWARD_PROPAGATION | CLIP | MOVED;
 
+    private BalancedTree bt;
+    
     private String text = null;
     private Font font = DEFAULT_FONT; 
     private Picture texture = null;
@@ -443,7 +443,7 @@ public final class Box extends JSScope implements Task {
     public JS callMethod(JS method, JS a0, JS a1, JS a2, JS[] rest, int nargs) throws JSExn {
         switch (nargs) {
             case 1: {
-                //#jswitch(method)
+                //#switch(JS.toString(method))
                 case "indexof":
                     Box b = (Box)a0;
                     if (b.parent != this)
@@ -469,7 +469,7 @@ public final class Box extends JSScope implements Task {
         if (JS.isInt(name))
             return redirect == null ? null : redirect == this ? getChild(JS.toInt(name)) : redirect.get(name);
 
-        //#jswitch(name)
+        //#switch(JS.toString(name))
         case "surface": return parent == null ? null : parent.getAndTriggerTraps(name);
         case "indexof": return METHOD;
         case "distanceto": return METHOD;
@@ -527,7 +527,7 @@ public final class Box extends JSScope implements Task {
 
     private class Mouse extends JS implements JS.Cloneable {
         public JS get(JS key) throws JSExn {
-            //#jswitch(key)
+            //#switch(JS.toString(key))
             case "x": return N(globalToLocalX(getSurface()._mousex));
             case "y": return N(globalToLocalY(getSurface()._mousey));
 
@@ -555,7 +555,7 @@ public final class Box extends JSScope implements Task {
 
     public void put(JS name, JS value) throws JSExn {
         if (JS.isInt(name)) { put(JS.toInt(name), value); return; }
-        //#jswitch(name)
+        //#switch(JS.toString(name))
         case "thisbox":     if (value == null) removeSelf();
         case "text":        { String s = value == null ?  "" : JS.toString(value); CHECKSET_STRING(text); RECONSTRAIN(); dirty(); }
         case "strokecolor": value = N(Color.stringToColor(JS.toString(value))); CHECKSET_INT(strokecolor); dirty();
@@ -684,7 +684,7 @@ public final class Box extends JSScope implements Task {
 
     private void setAlign(JS value) throws JSExn {
         clear(ALIGNS);
-        //#jswitch(value)
+        //#switch(JS.toString(value))
         case "topleft": set(ALIGN_TOP | ALIGN_LEFT);
         case "bottomleft": set(ALIGN_BOTTOM | ALIGN_LEFT);
         case "topright": set(ALIGN_TOP | ALIGN_RIGHT);
@@ -938,4 +938,15 @@ public final class Box extends JSScope implements Task {
             JS.log(e);
         }
     }
+    
+    // BalancedTree functions
+    private void insertNode(int p, Box b) {
+        if(bt == null) bt = new BalancedTree();
+        bt.insertNode(p,b);
+    }
+    
+    private int treeSize() { return bt == null ? 0 : bt.treeSize(); }
+    private int indexNode(Box b) { return bt == null ? -1 : bt.indexNode(b); }
+    private void deleteNode(int p) { bt.deleteNode(p); }
+    private Box getNode(int p) { return (Box)bt.getNode(p); }
 }