[seam-commits] Seam SVN: r11449 - in sandbox/trunk/modules/xwidgets: src/main/javascript and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sat Aug 29 22:25:57 EDT 2009


Author: shane.bryzak at jboss.com
Date: 2009-08-29 22:25:57 -0400 (Sat, 29 Aug 2009)
New Revision: 11449

Modified:
   sandbox/trunk/modules/xwidgets/examples/panels/index.html
   sandbox/trunk/modules/xwidgets/examples/panels/panels.xw
   sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Label.js
   sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js
   sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js
Log:
support panel hierarchy


Modified: sandbox/trunk/modules/xwidgets/examples/panels/index.html
===================================================================
--- sandbox/trunk/modules/xwidgets/examples/panels/index.html	2009-08-29 16:51:42 UTC (rev 11448)
+++ sandbox/trunk/modules/xwidgets/examples/panels/index.html	2009-08-30 02:25:57 UTC (rev 11449)
@@ -12,7 +12,7 @@
   
     <div id="container" style="border:1px solid black;width:75%;height:50%"></div>
     
-    <script src="../../src/main/javascript/xw.js"></script>
+    <script src="../../src/main/javascript/xw.js"></script>
       
     <script type="text/javascript">           
       // See README for notes on running in Firefox

Modified: sandbox/trunk/modules/xwidgets/examples/panels/panels.xw
===================================================================
--- sandbox/trunk/modules/xwidgets/examples/panels/panels.xw	2009-08-29 16:51:42 UTC (rev 11448)
+++ sandbox/trunk/modules/xwidgets/examples/panels/panels.xw	2009-08-30 02:25:57 UTC (rev 11449)
@@ -16,7 +16,13 @@
     <label value="right"/>
   </panel>    
 
-  <panel align="client">
-    <label value="client"/>  
+  <panel align="client" layout="border">
+    <panel align="left" width="120">
+      <label value="client:left"/>
+    </panel>
+    
+    <panel align="client">
+      <label value="client:client"/>
+    </panel>
   </panel>
 </view>

Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Label.js
===================================================================
--- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Label.js	2009-08-29 16:51:42 UTC (rev 11448)
+++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Label.js	2009-08-30 02:25:57 UTC (rev 11449)
@@ -11,14 +11,14 @@
     this.parent = parent;
   }
   
-  xw.controls.Label.prototype.paint = function()
-  {
+  xw.controls.Label.prototype.paint = function(layout)
+  {
     if (this.control == null)
     {
       this.control = document.createTextNode(this.value);
       // IE doesn't support setting random properties on text nodes
       // this.control.widget = this;
-      this.parent.control.appendChild(this.control);
-    }       
+      this.parent.appendChild(this.control);
+    }       
   }
 }

Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js
===================================================================
--- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js	2009-08-29 16:51:42 UTC (rev 11448)
+++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.Panel.js	2009-08-30 02:25:57 UTC (rev 11449)
@@ -4,9 +4,17 @@
 {
   this.width = 200;
   this.height = 100; 
-  this.parent = null;
+  this.parent = null;
+  
+  // the outer div
   this.control = null;
+  
+  // the inner div
+  this.inner = null;
+  
   this.align = null;
+  this.layout = null;
+  this.layoutManager = null;
     
   xw.controls.Panel.prototype.setParent = function(parent)
   {
@@ -29,39 +37,102 @@
   }
   
   xw.controls.Panel.prototype.paint = function(layout)
-  {
-     if (this.control == null)
-     {
-       this.control = document.createElement("div");
-       this.control.widget = this;              
-       this.control.style.backgroundColor = "#ece9d6";
+  {
+    if (this.control == null)
+    {
+      this.control = document.createElement("div");
+      this.control.widget = this;              
+      this.control.style.backgroundColor = "#ece9d6";
        
-       // TODO make the border more configurable (or allow it to be turned off etc)
-       this.control.style.borderTop = "1px solid white";
-       this.control.style.borderLeft = "1px solid white";
-       this.control.style.borderBottom = "1px solid #555555";
-       this.control.style.borderRight = "1px solid #555555";
+      // TODO make the border more configurable (or allow it to be turned off etc)
+      this.control.style.borderTop = "1px solid white";
+      this.control.style.borderLeft = "1px solid white";
+      this.control.style.borderBottom = "1px solid #555555";
+      this.control.style.borderRight = "1px solid #555555";
+      
+      this.control.style.padding = "0px";
+      this.control.style.margin = "0px";
        
-       if (layout != null)
-       {
-         layout.setBounds(this);
-       }
-       else
-       {
-         this.control.style.width = this.width;
-         this.control.style.height = this.height;         
-         this.control.style.display = "inline";
-       }
+      if (layout != null)
+      {
+        var bounds = layout.getBounds(this);
+        if (bounds != null) this.applyBounds(bounds);
+      }
+      else
+      {
+        this.control.style.width = this.width;
+        this.control.style.height = this.height;         
+        this.control.style.display = "inline";
+      }
 
-       this.parent.control.appendChild(this.control);
-     }    
-     
-     if (this.children)
-     {
-       for (var i = 0; i < this.children.length; i++)
-       {
-         this.children[i].paint(); 
-       }     
-     }   
-  }
+      this.parent.appendChild(this.control);
+    }    
+        
+    if (this.inner == null)
+    {
+      this.inner = document.createElement("div");
+      this.inner.widget = this;
+      this.inner.style.width = "100%";
+      this.inner.style.height = "100%";
+      this.inner.style.position = "relative";
+      this.inner.style.border = "0px";    
+      this.control.appendChild(this.inner);      
+    }
+          
+    // Create the appropriate layout manager and layout the child controls
+    if (this.layoutManager == null && this.layout != null) 
+    {
+      this.layoutManager = new xw.layoutManagers[this.layout](this);  
+    }
+    else
+    {
+      this.layoutManager = new xw.DefaultLayout(this);
+    }
+    
+    this.layoutManager.layout(this);           
+  }  
+  
+  xw.controls.Panel.prototype.appendChild = function(child)
+  {
+    this.inner.appendChild(child);
+  }
+  
+  xw.controls.Panel.prototype.getContainingControl = function()
+  {
+    return this.inner;
+  }
+  
+  xw.controls.Panel.prototype.applyBounds = function(bounds)
+  {  
+    if (bounds.left != null) this.control.style.left = bounds.left + "px";
+    if (bounds.top != null) this.control.style.top = bounds.top + "px";
+    
+    for (var i in bounds.style) this.control.style[i] = bounds.style[i];
+  
+    var b = xw.Sys.getBorder(this.control);
+   
+    if (bounds.height != null) 
+    {
+      if (bounds.height.indexOf("%") == -1)
+      {
+        this.control.style.height = (bounds.height - b.top - b.bottom) + "px";
+      }
+      else
+      {
+        this.control.style.height = bounds.height;
+      }
+    }
+    
+    if (bounds.width != null) 
+    {
+      if (bounds.width.indexOf("%") == -1)
+      {
+        this.control.style.width = (bounds.width - b.left - b.right) + "px";
+      }
+      else
+      {
+        this.control.style.width = bounds.width;
+      }
+    }
+  }  
 }

Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js
===================================================================
--- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js	2009-08-29 16:51:42 UTC (rev 11448)
+++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js	2009-08-30 02:25:57 UTC (rev 11449)
@@ -598,31 +598,37 @@
     this.style[property] = value;
     return this;
   }
+}
+
+/** LAYOUT MANAGERS **/
+
+xw.DefaultLayout = function(container)
+{
+  this.container = container;
   
-  xw.Bounds.prototype.applyToControl = function(control)
-  {  
-    if (this.left != null) control.style.left = this.left + "px";
-    if (this.top != null) control.style.top = this.top + "px";    
-    
-    for (var i in this.style) control.style[i] = this.style[i];              
-  
-    var b = xw.Sys.getBorder(control);
-   
-    if (this.height != null) control.style.height = (this.height - b.top - b.bottom) + "px";
-    if (this.width != null) control.style.width = (this.width - b.left - b.right) + "px";
+  xw.DefaultLayout.prototype.layout = function()
+  {
+    if (this.container.children)
+    {
+      for (var i = 0; i < this.container.children.length; i++)
+      {
+        this.container.children[i].paint();
+      }
+    }
   }
 }
 
-/** LAYOUT MANAGERS **/
-
 xw.BorderLayout = function(container)
 {
   this.container = container;
   this.bounds = new xw.Map();
-  
+    
   xw.BorderLayout.prototype.layout = function()
   {      
-    this.container.control.style.position = "relative";
+    // TODO - support percentage widths
+  
+    this.container.getContainingControl().style.position = "relative";
+    
     var topControls = new Array();
     var bottomControls = new Array();
     var leftControls = new Array();
@@ -653,7 +659,6 @@
         .addStyleProperty("right", "0");      
     
       this.bounds.put(topControls[i], bounds);
-
       topSpace += 1.0 * topControls[i].height;
     }
     
@@ -701,23 +706,22 @@
         .addStyleProperty("bottom", bottomSpace + "px")
       );    
     }
-  
+  
     for (var i = 0; i < this.container.children.length; i++)
     {
       this.container.children[i].paint(this); 
     }
   }
   
-  xw.BorderLayout.prototype.setBounds = function(ctl)
+  xw.BorderLayout.prototype.getBounds = function(ctl)
   {
-    var bounds = this.bounds.get(ctl);
-    if (bounds != null) bounds.applyToControl(ctl.control);
+    return this.bounds.get(ctl);
   }  
 }
 
 xw.layoutManagers = new Object();
 xw.layoutManagers["border"] = xw.BorderLayout;
-
+
 /**
  * A single instance of a view
  */
@@ -761,10 +765,20 @@
     var callback = function() { target.resize(); };
     xw.Sys.chainEvent(window, "resize", callback);    
     
-    // Layout the child controls
+    // Create the appropriate layout manager and layout the child controls
     if (this.layout != null) this.layoutManager = new xw.layoutManagers[this.layout](this);  
     this.layoutManager.layout();            
-  }  
+  }  
+  
+  xw.View.prototype.appendChild = function(child)
+  {
+    this.control.appendChild(child);
+  }
+  
+  xw.View.prototype.getContainingControl = function()
+  {
+    return this.control;
+  }
 }
 
 /**



More information about the seam-commits mailing list