2003/10/31 09:50:08
[org.ibex.core.git] / src / org / xwt / Surface.java
index c30a34b..9f48b2c 100644 (file)
@@ -14,7 +14,7 @@ import java.util.*;
  *
  *  Note that the members in the section 'state variables' are either
  *  in real-time (the actual size/position/state), or in
- *  MessageQueue-time (the size/position/state at the time that the
+ *  Scheduler-time (the size/position/state at the time that the
  *  now-executing message was enqueued). This distinction is important.
  */
 // FIXME: put the scar box back in
@@ -25,10 +25,16 @@ public abstract class Surface extends PixelBuffer {
         
     // Static Data ////////////////////////////////////////////////////////////////////////////////
 
+    // FIXME
+    private abstract static class Message extends Scheduler.Task {
+        public abstract void perform();
+        public Object call(Object arg) { perform(); return null; }
+    }
+
     /**< the most recently enqueued Move message; used to throttle the message rate */
     private static Message lastMoveMessage = null;
 
-    /** all instances of Surface which need to be refreshed by the MessageQueue */
+    /** all instances of Surface which need to be refreshed by the Scheduler */
     public static Vec allSurfaces = new Vec();
     
     /** When set to true, render() should abort as soon as possible and restart the rendering process */
@@ -37,9 +43,9 @@ public abstract class Surface extends PixelBuffer {
     public static boolean alt = false;          ///< true iff the alt button is pressed down, in real time
     public static boolean control = false;      ///< true iff the control button is pressed down, in real time
     public static boolean shift = false;        ///< true iff the shift button is pressed down, in real time
-    public static boolean button1 = false;      ///< true iff button 1 is depressed, in MessageQueue-time
-    public static boolean button2 = false;      ///< true iff button 2 is depressed, in MessageQueue-time
-    public static boolean button3 = false;      ///< true iff button 3 is depressed, in MessageQueue-time
+    public static boolean button1 = false;      ///< true iff button 1 is depressed, in Scheduler-time
+    public static boolean button2 = false;      ///< true iff button 2 is depressed, in Scheduler-time
+    public static boolean button3 = false;      ///< true iff button 3 is depressed, in Scheduler-time
 
      
 
@@ -48,8 +54,8 @@ public abstract class Surface extends PixelBuffer {
     public Box root;      /**< The Box at the root of this surface */
     public String cursor = "default";
 
-    public int mousex;                    ///< the x position of the mouse, relative to this Surface, in MessageQueue-time
-    public int mousey;                    ///< the y position of the mouse, relative to this Surface, in MessageQueue-time
+    public int mousex;                    ///< the x position of the mouse, relative to this Surface, in Scheduler-time
+    public int mousey;                    ///< the y position of the mouse, relative to this Surface, in Scheduler-time
     public boolean minimized = false;     ///< True iff this surface is minimized, in real time
     public boolean maximized = false;     ///< True iff this surface is maximized, in real time
 
@@ -103,7 +109,7 @@ public abstract class Surface extends PixelBuffer {
         else if (button == 2) new SimpleMessage("Press2", Boolean.TRUE, Box.whoIs(root, mousex, mousey));
         else if (button == 3) {
             final Box who = Box.whoIs(root, mousex, mousey);
-            Message.Q.add(new Message() { public void perform() {
+            Scheduler.add(new Message() { public void perform() {
                 Platform.clipboardReadEnabled = true;
                 root.put("Press3", Boolean.TRUE);
                 Platform.clipboardReadEnabled = false;
@@ -157,11 +163,11 @@ public abstract class Surface extends PixelBuffer {
         else if (control) key = "C-" + key;
 
         final String fkey = key;
-        Message.Q.add(new KMessage(key));
+        Scheduler.add(new KMessage(key));
     }
 
     // This is implemented as a private static class instead of an anonymous class to work around a GCJ bug
-    private class KMessage implements Message {
+    private class KMessage extends Message {
         String key = null;
         public KMessage(String k) { key = k; }
         public void perform() {
@@ -184,7 +190,7 @@ public abstract class Surface extends PixelBuffer {
         if (key.toLowerCase().equals("alt")) alt = false;
         else if (key.toLowerCase().equals("control")) control = false;
         else if (key.toLowerCase().equals("shift")) shift = false;
-        Message.Q.add(new Message() { public void perform() {
+        Scheduler.add(new Message() { public void perform() {
             /* FIXME
             outer: for(int i=0; i<keywatchers.size(); i++) {
                 Box b = (Box)keywatchers.elementAt(i);
@@ -203,7 +209,7 @@ public abstract class Surface extends PixelBuffer {
      *  message), the subclass should use (-1,-1).
      */
     protected final void Move(final int newmousex, final int newmousey) {
-        Message.Q.add(lastMoveMessage = new Message() { public void perform() {
+        Scheduler.add(lastMoveMessage = new Message() { public void perform() {
             synchronized(Surface.this) {
 
                 // if move messages are arriving faster than we can process them, we just start ignoring them
@@ -228,7 +234,7 @@ public abstract class Surface extends PixelBuffer {
     }
 
     protected final void SizeChange(final int width, final int height) {
-        Message.Q.add(new Message() { public void perform() {
+        Scheduler.add(new Message() { public void perform() {
             if (width == root.width && height == root.height) return;
             root.needs_reflow = true;
             do { abort = false; root.reflow(width, height); } while(abort);
@@ -237,7 +243,7 @@ public abstract class Surface extends PixelBuffer {
     }
 
     protected final void PosChange(final int x, final int y) {
-        Message.Q.add(new Message() { public void perform() {
+        Scheduler.add(new Message() { public void perform() {
             root.x = x;
             root.y = y;
             root.put("PosChange", Boolean.TRUE);
@@ -248,7 +254,12 @@ public abstract class Surface extends PixelBuffer {
     protected final void Minimized(boolean b) { minimized = b; new SimpleMessage("Minimized", b ? Boolean.TRUE : Boolean.FALSE, root); }
     protected final void Maximized(boolean b) { maximized = b; new SimpleMessage("Maximized", b ? Boolean.TRUE : Boolean.FALSE, root); }
     protected final void Focused(boolean b) { new SimpleMessage("Focused", b ? Boolean.TRUE : Boolean.FALSE, root); }
-    public static void Refresh() { Message.Q.refresh(); }
+    public static void Refresh() {
+        Scheduler.add(new Scheduler.Task() { public Object call(Object arg) {
+                for(int i=0; i<allSurfaces.size(); i++)
+                    ((Surface)allSurfaces.elementAt(i)).render();
+                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); }
@@ -337,7 +348,7 @@ public abstract class Surface extends PixelBuffer {
     }
 
     // FEATURE: reinstate recycler
-    public class SimpleMessage implements Message {
+    public class SimpleMessage extends Message {
         
         private Box boxContainingMouse;
         private Object value;
@@ -347,7 +358,7 @@ public abstract class Surface extends PixelBuffer {
             this.boxContainingMouse = boxContainingMouse;
             this.name = name;
             this.value = value;
-            Message.Q.add(this);
+            Scheduler.add(this);
         }
         
         public void perform() { boxContainingMouse.put(name, value); }