Revision: 2783
          http://vexi.svn.sourceforge.net/vexi/?rev=2783&view=rev
Author:   clrg
Date:     2008-02-02 13:49:07 -0800 (Sat, 02 Feb 2008)

Log Message:
-----------
Surface cleanup
- Add comments and remove dead code
- Reorganise into more logical segments
- Fix bug in Surface where 'alt' key modifier would be left set after an 
alt-tab away

Modified Paths:
--------------
    trunk/core/org.vexi.core/src/org/vexi/core/Surface.java

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Surface.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Surface.java     2008-01-31 
19:00:30 UTC (rev 2782)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Surface.java     2008-02-02 
21:49:07 UTC (rev 2783)
@@ -98,8 +98,23 @@
     public static Picture scarImage = null;
 
 
-    // Helper methods for subclasses 
////////////////////////////////////////////////////////////
+    // Event Handling Helper methods for subclasses ///////////////////
+    
+    protected final void KeyPressed(String key) { new Message("KeyPressed", 
JSU.S(key)); }
+    protected final void KeyReleased(String key) { new Message("KeyReleased", 
JSU.S(key)); }
+    protected final void Close() { new Message("Close", T, false); }
+    protected final void Minimized(boolean b) { minimized = b; new 
Message("Minimized", b ? T : F, false); }
+    protected final void Maximized(boolean b) { maximized = b; new 
Message("Maximized", b ? T : F, false); }
+    protected final void Focused(boolean b) {
+        if (!b) { alt = control = shift = false; }
+        new Message("Focused", b ? T : F, false);
+    }
 
+    protected final void HScroll(int pixels) { new Message("HScroll", 
JSU.N(pixels)); }
+    protected final void VScroll(int pixels) { new Message("VScroll", 
JSU.N(pixels)); }
+    protected final void HScroll(float lines) { new Message("HScroll", 
JSU.N(lines)); }
+    protected final void VScroll(float lines) { new Message("VScroll", 
JSU.N(lines)); }
+
     protected final void Press(final int button) {
         last_press_x = mousex;
         last_press_y = mousey;
@@ -108,10 +123,7 @@
         else if (button == 2) button2 = true;
         else if (button == 3) button3 = true;
 
-        if (button == 1) 
-               new Message("Press1", T, root);
-        else if (button == 2) new Message("Press2", T, root);
-        else if (button == 3) {
+        if (button == 3) {
             Scheduler.add(new Callable() { public Object run(Object o) throws 
JSExn {
                 Platform.clipboardReadEnabled = true;
                 try {
@@ -121,7 +133,7 @@
                 }
                 return o;
             }});
-        }
+        } else new 
Message(button==1?"Press1":button==2?"Press2":"Press"+button, T); 
     }
 
     protected final void Release(int button) {
@@ -129,19 +141,14 @@
         else if (button == 2) button2 = false;
         else if (button == 3) button3 = false;
 
-        if (button == 1) new Message("Release1", T, root);
-        else if (button == 2) new Message("Release2", T, root);
-        else if (button == 3) new Message("Release3", T, root);
-
+        new 
Message(button==1?"Release1":button==2?"Release2":button==3?"Release3":"Release"+button,
 T);
         if (Platform.needsAutoClick() && Math.abs(last_press_x - mousex) < 5 
&& Math.abs(last_press_y - mousey) < 5) Click(button);
         last_press_x = Integer.MAX_VALUE;
         last_press_y = Integer.MAX_VALUE;
     }
 
     protected final void Click(int button) {
-        if (button == 1) new Message("Click1", T, root);
-        else if (button == 2) new Message("Click2", T, root);
-        else if (button == 3) new Message("Click3", T, root);
+        new 
Message(button==1?"Click1":button==2?"Click2":button==3?"Click3":"Click"+button,
 T);
         if (Platform.needsAutoDoubleClick()) {
             long now = System.currentTimeMillis();
             if (lastClickButton == button && now - lastClickTime < 350) 
DoubleClick(button);
@@ -149,18 +156,11 @@
             lastClickTime = now;
         }
     }
-    
-    // FIXME: handle exceptions etc - better checking of types?
-    /** prepare an image for setting it as the icon of this surface */
-    protected final void queueSetIcon(JS icon) { this.icon = 
Picture.load(icon, seticon); }
-    private Callable seticon = new Callable() {
-        public Object run(Object o) {
-            Log.warn(this, "setting icon");
-            setIcon(icon);
-            return o;
-        }
-    };
 
+    protected final void DoubleClick(int button) {
+        new 
Message(button==1?"DoubleClick1":button==2?"DoubleClick2":button==3?"DoubleClick3":"DoubleClick"+button,
 T);
+    }
+
     /** we enqueue ourselves in the Platform.Scheduler when we have a Move 
message to deal with */
     private boolean moverScheduled = false;
     private Callable mover = new Callable() {
@@ -193,33 +193,79 @@
         Scheduler.add(mover);
     }
 
-    protected final void HScroll(int pixels) { new Message("HScroll", 
JSU.N(pixels), root); }
-    protected final void VScroll(int pixels) { new Message("VScroll", 
JSU.N(pixels), root); }
-    protected final void HScroll(float lines) { new Message("HScroll", 
JSU.N(lines), root); }
-    protected final void VScroll(float lines) { new Message("VScroll", 
JSU.N(lines), root); }
+    // FEATURE: reinstate recycler
+    public class Message implements Callable {
+        
+        private JS value;
+        private boolean inputEvent;
+        public String name;
 
+        Message(String name, JS value) {
+            this(name, value, true);
+        }
+
+        Message(String name, JS value, boolean inputEvent) {
+            this.name = name;
+            this.value = value;
+            this.inputEvent = inputEvent;
+            Scheduler.add(this);
+        }
+
+        public Object run(Object o) throws JSExn {
+            if (!inputEvent) {
+                root.putAndTriggerTraps(JSU.S(name), value);
+                return o;
+            }
+
+            if (name.equals("KeyPressed")) {
+                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 = 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);
+            }
+            
+            try { root.tryPropagateEvent(name, value); }
+            finally { Platform.clipboardReadEnabled = false; }
+            return o;
+        }
+        public String toString() { return "Message [name=" + name + ", value=" 
+ JSU.toString(value) + "]"; }
+    }
+    
+    
+    // Frame Management ///////////////////////////////////////////////
+    
+    // FIXME: handle exceptions etc - better checking of types?
+    /** prepare an image for setting it as the icon of this surface */
+    protected final void queueSetIcon(JS icon) { this.icon = 
Picture.load(icon, seticon); }
+    private Callable seticon = new Callable() {
+        public Object run(Object o) {
+            Log.warn(this, "setting icon");
+            setIcon(icon);
+            return o;
+        }
+    };
+
+    public final void setMaximized(boolean b) { if (b != maximized) 
_setMaximized(maximized = b); }
+    public final void setMinimized(boolean b) { if (b != minimized) 
_setMinimized(minimized = b); }
+
     protected boolean firstrender = false;
     /** subclasses should invoke this method when the user resizes the window 
*/
     protected final void SizeChange(int width, int height) {
         if (firstrender) return;
+        // FIXME: do this properly i.e. at platform level
         // constrain our size as determined by the root box
         width = root.maxwidth < width ? root.maxwidth : width;
         width = root.minwidth > width ? root.minwidth : width;
         height = root.maxheight < height ? root.maxheight : height;
         height = root.minheight > height ? root.minheight : height;
-        /*
-        // the following causes the expanded region to flicker
-        // as it 1. resizes (AWT), 2. fills, 3. collapses (setSizes), back to 
1.
-        int capwidth = width, capheight = height;
-        capwidth = root.maxwidth < capwidth ? root.maxwidth : capwidth;
-        capwidth = root.minwidth > capwidth ? root.minwidth : capwidth;
-        capheight = root.maxheight < capheight ? root.maxheight : capheight;
-        capheight = root.minheight > capheight ? root.minheight : capheight;
-        if (capwidth != width || capheight != height) {
-               //setSize(capwidth, capheight);
-               return;
-        }
-        */
         if (pendingWidth == width && pendingHeight == height) return;
         pendingWidth = width;
         pendingHeight = height;
@@ -233,6 +279,7 @@
     private final Callable poschanger = new Callable() {
         public Object run(Object o) throws JSExn {
             poschangeScheduled = false;
+            // FIXME: remove or fix the following behaviour (push it into the 
widgets?)
             int sw = Platform.getScreenWidth();
             int sh = Platform.getScreenHeight();
             int _x, _y;
@@ -285,15 +332,9 @@
         setLocation();
     }
 
-    private final String[] doubleClick = new String[] { null, "DoubleClick1", 
"DoubleClick2", "DoubleClick3" };
-    protected final void DoubleClick(int button) { new 
Message(doubleClick[button], T, root); }
-    protected final void KeyPressed(String key) { new Message("KeyPressed", 
JSU.S(key), root); }
-    protected final void KeyReleased(String key) { new Message("KeyReleased", 
JSU.S(key), root); }
-    protected final void Close() { new Message("Close", T, root, false); }
-    protected final void Minimized(boolean b) { minimized = b; new 
Message("Minimized", b ? T : F, root, false); }
-    protected final void Maximized(boolean b) { maximized = b; new 
Message("Maximized", b ? T : F, root, false); }
-    protected final void Focused(boolean b) { new Message("Focused", b ? T : 
F, root, false); }
 
+    // Core Surface Logic 
///////////////////////////////////////////////////////////////////////////////
+
     /** refresh handles interacting with the scheduler - it needs
      * to be synchronized to prevent scheduled 
      */
@@ -311,12 +352,6 @@
        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); }
-
-
-    // Other Methods 
///////////////////////////////////////////////////////////////////////////////
-
     /** Indicates that the Surface is no longer needed */
     public final void dispose(boolean quitIfAllSurfacesGone) {
         Log.info(this, "disposing " + this);
@@ -441,55 +476,7 @@
         }
     }
 
-    // FEATURE: reinstate recycler
-    public class Message implements Callable {
-        
-        private Box boxContainingMouse;
-        private JS value;
-        private boolean inputEvent;
-        public String name;
 
-        Message(String name, JS value, Box boxContainingMouse) {
-            this(name, value, boxContainingMouse, true);
-        }
-
-        Message(String name, JS value, Box boxContainingMouse, boolean 
inputEvent) {
-            this.boxContainingMouse = boxContainingMouse;
-            this.name = name;
-            this.value = value;
-            this.inputEvent = inputEvent;
-            Scheduler.add(this);
-        }
-
-        public Object run(Object o) throws JSExn {
-            if (!inputEvent) {
-                boxContainingMouse.putAndTriggerTraps(JSU.S(name), value);
-                return o;
-            }
-
-            if (name.equals("KeyPressed")) {
-                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 = 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);
-            }
-            
-            try { boxContainingMouse.tryPropagateEvent(name, value); }
-            finally { Platform.clipboardReadEnabled = false; }
-            return o;
-        }
-        public String toString() { return "Message [name=" + name + ", value=" 
+ JSU.toString(value) + "]"; }
-    }
-
-
     // Default PixelBuffer implementation 
/////////////////////////////////////////////////////////
 
     public static abstract class DoubleBufferedSurface extends Surface 
implements PixelBuffer {


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

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to