[seam-commits] Seam SVN: r11427 - sandbox/trunk/modules/xwidgets/src/main/javascript.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Aug 25 22:34:26 EDT 2009


Author: shane.bryzak at jboss.com
Date: 2009-08-25 22:34:26 -0400 (Tue, 25 Aug 2009)
New Revision: 11427

Modified:
   sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js
   sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js
Log:
groundwork for layout management


Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js
===================================================================
--- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js	2009-08-25 20:00:55 UTC (rev 11426)
+++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js	2009-08-26 02:34:26 UTC (rev 11427)
@@ -5,11 +5,27 @@
   this.width = 200;
   this.height = 100; 
   this.parent = null;
-  this.control = null;
+  this.control = null;
+  this.align = null;
     
   xw.controls.Panel.prototype.setParent = function(parent)
   {
     this.parent = parent;
+  }
+  
+  xw.controls.Panel.prototype.setAlign = function(align)
+  {
+    this.align = align;
+  }
+  
+  xw.controls.Panel.prototype.setWidth = function(width)
+  {
+    this.width = width;
+  }
+  
+  xw.controls.Panel.prototype.setHeight = function(height)
+  {
+    this.height = height;
   }
   
   xw.controls.Panel.prototype.paint = function()
@@ -19,10 +35,32 @@
        this.control = document.createElement("div");
        this.control.widget = this;
        this.parent.control.appendChild(this.control);
-       
-       this.control.style.width = "400";
-       this.control.style.height = "200";
-       
+       
+       if (this.align == "top")
+       {
+         this.control.style.float = "top";
+         this.control.style.height = this.height;
+       }
+       else if (this.align = "bottom")
+       {
+         this.control.style.float = "bottom";
+         this.control.style.height = this.height;
+       }
+       else if (this.align = "left")
+       {
+         this.control.style.float = "left";
+         this.control.style.width = this.width;
+       }
+       else if (this.align = "right")
+       {
+         this.control.style.float = "right";
+         this.control.style.width = this.width;
+       }
+       else if (this.align = "client")
+       {
+         this.control.style.height = "100%";
+       }
+       
        this.control.style.backgroundColor = "#ece9d6";
        this.control.style.borderTop = "1px solid white";
        this.control.style.borderLeft = "1px solid white";

Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js
===================================================================
--- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js	2009-08-25 20:00:55 UTC (rev 11426)
+++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js	2009-08-26 02:34:26 UTC (rev 11427)
@@ -246,9 +246,8 @@
     }
     else
     {            
-      // TODO improve this    
       var controlName = xw.Sys.capitalize(tag);
-      var control = eval("new xw.controls." + controlName + "()");    
+      var control = new xw.controls[controlName]();
       control.parent = parentControl;
       
       if (xw.Sys.isUndefined(parentControl.children))
@@ -388,7 +387,26 @@
       return eval(this.script);
     }
   }
-}
+}
+
+/** LAYOUT MANAGERS **/
+
+xw.BorderLayout = function(container)
+{
+  this.container = container;
+  
+  xw.BorderLayout.prototype.layout = function()
+  {      
+    for (var i = 0; i < container.children.length; i++)
+    {
+      container.children[i].paint(); 
+    }
+  }
+  
+}
+
+xw.layoutManagers = new Object();
+xw.layoutManagers["border"] = xw.BorderLayout;
 
 /**
  * A single instance of a view
@@ -396,16 +414,46 @@
 xw.View = function()
 {
   this.container = null;  
-  this.children = new Array();
+  this.children = new Array();
+  
+  this.layout = "border"; // The default layout
+  this.layoutManager = null;
+    
+  /**
+   * Callback for window resize events
+   */
+  xw.View.prototype.resize = function()
+  {
+    // bubble the resize event through the component tree
+  }  
+  
+  xw.View.prototype.setLayout = function(layout)
+  {
+    this.layout = layout;
+  }
+  
+  xw.View.prototype.setLayoutManager = function(layoutManager)
+  {
+    this.layout = null;
+    this.layoutManager = layoutManager;
+  }
   
   xw.View.prototype.paint = function()
-  {
-    this.control = xw.Sys.getObject(this.container);
-    
-    for (var i = 0; i < this.children.length; i++)
-    {
-      this.children[i].paint(); 
-    }
+  {       
+    // Determine the container control
+    if ("string" == (typeof this.container))
+      this.control = xw.Sys.getObject(this.container);
+    else
+      this.control = this.container;           
+    
+    // Set the window resize callback so that we can respond to resize events
+    var target = this; 
+    var callback = function() { target.resize(); };
+    xw.Sys.chainEvent(window, "resize", callback);    
+    
+    // Layout the child controls
+    if (this.layout != null) this.layoutManager = new xw.layoutManagers[this.layout](this);  
+    this.layoutManager.layout();            
   }  
 }
 
@@ -429,4 +477,4 @@
 xw.getResourceBase = function()
 {
   return xw.Sys.isUndefined(xw.resourceBase) ? "" : xw.resourceBase + "/";
-}
\ No newline at end of file
+}



More information about the seam-commits mailing list