From seam-commits at lists.jboss.org Wed Aug 26 04:05:51 2009 Content-Type: multipart/mixed; boundary="===============2222892724613425611==" MIME-Version: 1.0 From: seam-commits at lists.jboss.org To: seam-commits at lists.jboss.org Subject: [seam-commits] Seam SVN: r11428 - in sandbox/trunk/modules/xwidgets: src/main/javascript and 1 other directory. Date: Wed, 26 Aug 2009 04:05:51 -0400 Message-ID: <200908260805.n7Q85pNi017430@svn01.web.mwc.hst.phx2.redhat.com> --===============2222892724613425611== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: shane.bryzak(a)jboss.com Date: 2009-08-26 04:05:50 -0400 (Wed, 26 Aug 2009) New Revision: 11428 Modified: sandbox/trunk/modules/xwidgets/examples/helloworld/index.html sandbox/trunk/modules/xwidgets/examples/helloworld/test.xw sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Panel.js sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js Log: layout manager functionality Modified: sandbox/trunk/modules/xwidgets/examples/helloworld/index.html =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/examples/helloworld/index.html 2009-08-2= 6 02:34:26 UTC (rev 11427) +++ sandbox/trunk/modules/xwidgets/examples/helloworld/index.html 2009-08-2= 6 08:05:50 UTC (rev 11428) @@ -2,7 +2,7 @@

Hello World Example

= -
+
= = Modified: sandbox/trunk/modules/xwidgets/examples/helloworld/test.xw =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/examples/helloworld/test.xw 2009-08-26 0= 2:34:26 UTC (rev 11427) +++ sandbox/trunk/modules/xwidgets/examples/helloworld/test.xw 2009-08-26 0= 8:05:50 UTC (rev 11428) @@ -1,6 +1,6 @@ - + + + + = + + + = + + + = + + = + = + + - \ No newline at end of file + Modified: sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Panel.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Panel.js 2009-08-= 26 02:34:26 UTC (rev 11427) +++ sandbox/trunk/modules/xwidgets/examples/helloworld/xw.Panel.js 2009-08-= 26 08:05:50 UTC (rev 11428) @@ -5,29 +5,53 @@ this.width =3D 200; this.height =3D 100; = this.parent =3D null; - this.control =3D null; + this.control =3D null; + this.align =3D null; = xw.controls.Panel.prototype.setParent =3D function(parent) { this.parent =3D parent; + } + = + xw.controls.Panel.prototype.setAlign =3D function(align) + { + this.align =3D align; + } + = + xw.controls.Panel.prototype.setWidth =3D function(width) + { + this.width =3D width; + } + = + xw.controls.Panel.prototype.setHeight =3D function(height) + { + this.height =3D height; } = - xw.controls.Panel.prototype.paint =3D function() + xw.controls.Panel.prototype.paint =3D function(layout) { if (this.control =3D=3D null) { this.control =3D document.createElement("div"); - this.control.widget =3D this; - this.parent.control.appendChild(this.control); - = - this.control.style.width =3D "400"; - this.control.style.height =3D "200"; - = + this.control.widget =3D this; = this.control.style.backgroundColor =3D "#ece9d6"; this.control.style.borderTop =3D "1px solid white"; this.control.style.borderLeft =3D "1px solid white"; this.control.style.borderBottom =3D "1px solid #555555"; - this.control.style.borderRight =3D "1px solid #555555"; + this.control.style.borderRight =3D "1px solid #555555"; + = + if (layout !=3D null) + { + layout.setBounds(this); + } + else + { + this.control.style.width =3D this.width; + this.control.style.height =3D this.height; = + this.control.style.display =3D "inline"; + } + + this.parent.control.appendChild(this.control); } = = for (var i =3D 0; i < this.children.length; i++) Modified: sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js 2009-08-26 02:= 34:26 UTC (rev 11427) +++ sandbox/trunk/modules/xwidgets/src/main/javascript/xw.js 2009-08-26 08:= 05:50 UTC (rev 11428) @@ -114,6 +114,82 @@ // really old browsers // alert("your browser doesn't support adding event listeners"); } +} + +/** + * A Map implementation + */ +xw.Map =3D function() +{ + this.elements =3D new Array(); + + xw.Map.prototype.size =3D function() + { + return this.elements.length; + } + + xw.Map.prototype.isEmpty =3D function() + { + return this.elements.length =3D=3D 0; + } + + xw.Map.prototype.keySet =3D function() + { + var keySet =3D new Array(); + for (var i =3D 0; i < this.elements.length; i++) + keySet[keySet.length] =3D this.elements[i].key; + return keySet; + } + + xw.Map.prototype.values =3D function() + { + var values =3D new Array(); + for (var i =3D 0; i < this.elements.length; i++) + values[values.length] =3D this.elements[i].value; + return values; + } + + xw.Map.prototype.get =3D function(key) + { + for (var i =3D 0; i < this.elements.length; i++) + { + if (this.elements[i].key =3D=3D key) + return this.elements[i].value; + } + return null; + } + + xw.Map.prototype.put =3D function(key, value) + { + for (var i =3D 0; i < this.elements.length; i++) + { + if (this.elements[i].key =3D=3D key) + { + this.elements[i].value =3D value; + return; + } + } + this.elements.push({key:key,value:value}); + } + + xw.Map.prototype.remove =3D function(key) + { + for (var i =3D 0; i < this.elements.length; i++) + { + if (this.elements[i].key =3D=3D key) + this.elements.splice(i, 1); + } + } + + xw.Map.prototype.contains =3D function(key) + { + for (var i =3D 0; i < this.elements.length; i++) + { + if (this.elements[i].key =3D=3D key) + return true; + } + return false; + } } = /** @@ -389,20 +465,152 @@ } } = +/** + * Defines the physical bounds of a control + */ +xw.Bounds =3D function(top, left, height, width) +{ + this.top =3D top; + this.left =3D left; + this.height =3D height; + this.width =3D width; + this.style =3D new Object(); + = + xw.Bounds.prototype.getTop =3D function() + { + return this.top; + } + = + xw.Bounds.prototype.getLeft =3D function() + { + return this.left; + } + = + xw.Bounds.prototype.getHeight =3D function() + { + return this.height; + } + = + xw.Bounds.prototype.getWidth =3D function() + { + return this.width; + } = + = + xw.Bounds.prototype.addStyleProperty =3D function(property, value) + { + this.style[property] =3D value; + return this; + } + = + xw.Bounds.prototype.applyToControl =3D function(control) + { + if (this.height !=3D null) control.style.height =3D this.height; + if (this.width !=3D null) control.style.width =3D this.width; + if (this.height !=3D null) control.style.height =3D this.height; + if (this.width !=3D null) control.style.width =3D this.width; + for (var i in this.style) control.style[i] =3D this.style[i]; + } +} + /** LAYOUT MANAGERS **/ = xw.BorderLayout =3D function(container) { this.container =3D container; + this.bounds =3D new xw.Map(); = xw.BorderLayout.prototype.layout =3D function() - { = - for (var i =3D 0; i < container.children.length; i++) + { = + this.container.control.style.position =3D "relative"; + var topControls =3D new Array(); + var bottomControls =3D new Array(); + var leftControls =3D new Array(); + var rightControls =3D new Array(); + var clientControls =3D new Array(); = + + for (var i =3D 0; i < this.container.children.length; i++) + { + var child =3D this.container.children[i]; + if ("top" =3D=3D child.align) topControls.push(child); + else if ("bottom" =3D=3D child.align) bottomControls.push(child); + else if ("left" =3D=3D child.align) leftControls.push(child); + else if ("right" =3D=3D child.align) rightControls.push(child); + else if ("client" =3D=3D child.align) clientControls.push(child); + } + = + var topSpace =3D 0; + var bottomSpace =3D 0; + var leftSpace =3D 0; + var rightSpace =3D 0; + = + // TODO - take border widths into account so we don't need all the +2'= s everywhere + = + for (var i =3D 0; i < topControls.length; i++) + { + this.bounds.put(topControls[i], new xw.Bounds(null, null, topControl= s[i].height, null) + .addStyleProperty("position", "absolute") + .addStyleProperty("top", topSpace) + .addStyleProperty("left", "0") + .addStyleProperty("right", "0") + ); + topSpace +=3D 1.0 * topControls[i].height; + } + = + for (var i =3D 0; i < bottomControls.length; i++) + { + this.bounds.put(bottomControls[i], new xw.Bounds(null, null, bottomC= ontrols[i].height, null) + .addStyleProperty("position","absolute") + .addStyleProperty("bottom", bottomSpace) + .addStyleProperty("left", "0") + .addStyleProperty("right", "0") + ); = + bottomSpace +=3D 1.0 * bottomControls[i].height; = + } + = + for (var i =3D 0; i < leftControls.length; i++) + { + this.bounds.put(leftControls[i], new xw.Bounds(null, null, null, lef= tControls[i].width) + .addStyleProperty("position", "absolute") + .addStyleProperty("left", leftSpace + (leftSpace > 0 ? 2 : 0)) + .addStyleProperty("top", topSpace + 2) + .addStyleProperty("bottom", bottomSpace + 2) + ); + leftSpace +=3D 1.0 * leftControls[i].width; = + } + = + for (var i =3D 0; i < rightControls.length; i++) + { + this.bounds.put(rightControls[i], new xw.Bounds(null, null, null, ri= ghtControls[i].width) + .addStyleProperty("position", "absolute") + .addStyleProperty("right", rightSpace) + .addStyleProperty("top", topSpace + 2) + .addStyleProperty("bottom", bottomSpace + 2) + ); + rightSpace +=3D 1.0 * rightControls[i].width; + } + = + for (var i =3D 0; i < clientControls.length; i++) + { + this.bounds.put(clientControls[i], new xw.Bounds(null, null, null, n= ull) + .addStyleProperty("position", "absolute") + .addStyleProperty("left", leftSpace + 4) + .addStyleProperty("right", rightSpace + 2) + .addStyleProperty("top", topSpace + 2) + .addStyleProperty("bottom", bottomSpace + 2) + ); = + } + = + for (var i =3D 0; i < this.container.children.length; i++) { - container.children[i].paint(); = + this.container.children[i].paint(this); = } } = + xw.BorderLayout.prototype.setBounds =3D function(ctl) + { + var bounds =3D this.bounds.get(ctl); + if (bounds !=3D null) bounds.applyToControl(ctl.control); + } = } = xw.layoutManagers =3D new Object(); --===============2222892724613425611==--