flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject [1/2] git commit: [flex-asjs] [refs/heads/develop] - Added TileLayout (AS and JS versions).
Date Tue, 18 Feb 2014 19:55:13 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop 0ff1aa34b -> e3ef83eed


Added TileLayout (AS and JS versions).


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/1fec5717
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/1fec5717
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/1fec5717

Branch: refs/heads/develop
Commit: 1fec5717c31c443b7a532486c12c9cc4c58c189d
Parents: 0ff1aa3
Author: Peter Ent <pent@apache.org>
Authored: Tue Feb 18 14:48:35 2014 -0500
Committer: Peter Ent <pent@apache.org>
Committed: Tue Feb 18 14:48:35 2014 -0500

----------------------------------------------------------------------
 .../as/projects/FlexJSUI/basic-manifest.xml     |   1 +
 .../as/projects/FlexJSUI/src/FlexJSUIClasses.as |   1 +
 .../src/org/apache/flex/core/IUIBase.as         |  39 +++++
 .../src/org/apache/flex/core/UIButtonBase.as    |  94 +++++++++++
 .../staticControls/beads/layouts/TileLayout.as  | 127 +++++++++++++++
 .../staticControls/beads/layouts/TileLayout.js  | 158 +++++++++++++++++++
 6 files changed, 420 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1fec5717/frameworks/as/projects/FlexJSUI/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/basic-manifest.xml b/frameworks/as/projects/FlexJSUI/basic-manifest.xml
index 2fe364b..80d7ac9 100644
--- a/frameworks/as/projects/FlexJSUI/basic-manifest.xml
+++ b/frameworks/as/projects/FlexJSUI/basic-manifest.xml
@@ -54,6 +54,7 @@
     <component id="TitleBarModel" class="org.apache.flex.html.staticControls.beads.models.TitleBarModel"/>
     <component id="NonVirtualVerticalLayout" class="org.apache.flex.html.staticControls.beads.layouts.NonVirtualVerticalLayout"/>
     <component id="NonVirtualHorizontalLayout" class="org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalLayout"/>
+    <component id="TileLayout" class="org.apache.flex.html.staticControls.beads.layouts.TileLayout"/>
     <component id="SimpleAlert" class="org.apache.flex.html.staticControls.SimpleAlert"/>
     <component id="Alert" class="org.apache.flex.html.staticControls.Alert"/>
     <component id="Spinner" class="org.apache.flex.html.staticControls.Spinner"/>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1fec5717/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as b/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
index 1d08346..5cf11ef 100644
--- a/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
+++ b/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
@@ -83,6 +83,7 @@ internal class FlexJSUIClasses
     import org.apache.flex.html.staticControls.beads.layouts.NonVirtualVerticalScrollingLayout;
NonVirtualVerticalScrollingLayout;  
 	import org.apache.flex.html.staticControls.beads.layouts.NonVirtualHorizontalScrollingLayout;
NonVirtualHorizontalScrollingLayout;
     import org.apache.flex.html.staticControls.beads.layouts.VScrollBarLayout; VScrollBarLayout;
+	import org.apache.flex.html.staticControls.beads.layouts.TileLayout; TileLayout;
     import org.apache.flex.html.staticControls.beads.TextItemRendererFactoryForArrayData;
TextItemRendererFactoryForArrayData;
 	import org.apache.flex.html.staticControls.beads.DataItemRendererFactoryForArrayData; DataItemRendererFactoryForArrayData;
     import org.apache.flex.core.ItemRendererClassFactory; ItemRendererClassFactory;  

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1fec5717/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as
index 15605f4..da9121f 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IUIBase.as
@@ -50,5 +50,44 @@ package org.apache.flex.core
          *  @productversion FlexJS 0.0
          */
 		function addedToParent():void;
+		
+		/**
+		 *  The x co-ordinate or left side position of the bounding box.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		function get x():Number;
+		function set x(value:Number):void;
+		
+		/**
+		 *  The y co-ordinate or top position of the bounding box.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		function get y():Number;
+		function set y(value:Number):void;
+		
+		/**
+		 *  The width of the bounding box.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		function get width():Number;
+		function set width(value:Number):void;
+		
+		/**
+		 * The height of the bounding box.
+		 */
+		function get height():Number;
+		function set height(value:Number):void;
 	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1fec5717/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as
index 7d0039d..b02ffd9 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as
@@ -84,6 +84,100 @@ package org.apache.flex.core
 			}
 		}
 		
+		private var _x:Number;
+		
+		/**
+		 *  @copy org.apache.flex.core.UIBase#x
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		override public function get x():Number
+		{
+			if (isNaN(_x))
+			{
+				var value:* = ValuesManager.valuesImpl.getValue(this, "x");
+				if (value === undefined)
+					return $x;
+				_x = Number(value);
+			}
+			return _x;
+		}
+		
+		/**
+		 *  @private
+		 */
+		override public function set x(value:Number):void
+		{
+			if (_x != value) {
+				_x = value;
+				super.x = value;
+				dispatchEvent(new Event("xChanged"));
+			}
+		}
+		
+		/**
+		 *  Retrieve the low-level bounding box x.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		protected function get $x():Number
+		{
+			return super.x;
+		}
+		
+		private var _y:Number;
+		
+		/**
+		 *  @copy org.apache.flex.core.UIBase#y
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		override public function get y():Number
+		{
+			if (isNaN(_y))
+			{
+				var value:* = ValuesManager.valuesImpl.getValue(this, "y");
+				if (value === undefined)
+					return $y;
+				_y = Number(value);
+			}
+			return _y;
+		}
+		
+		/**
+		 *  @private
+		 */
+		override public function set y(value:Number):void
+		{
+			if (_y != value) {
+				_y = value;
+				super.y = value;
+				dispatchEvent(new Event("yChanged"));
+			}
+		}
+		
+		/**
+		 *  Retrieve the low-level bounding box y.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		protected function get $y():Number
+		{
+			return super.y;
+		}
+		
 		private var _width:Number;
         
         /**

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1fec5717/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/layouts/TileLayout.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/layouts/TileLayout.as
b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/layouts/TileLayout.as
new file mode 100644
index 0000000..06a9277
--- /dev/null
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/layouts/TileLayout.as
@@ -0,0 +1,127 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.html.staticControls.beads.layouts
+{	
+	import org.apache.flex.core.IBeadLayout;
+	import org.apache.flex.core.ILayoutParent;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.IUIBase;
+	import org.apache.flex.core.UIBase;
+	import org.apache.flex.events.Event;
+	import org.apache.flex.events.IEventDispatcher;
+	
+	public class TileLayout implements IBeadLayout
+	{
+		public function TileLayout()
+		{
+		}
+		
+		private var _strand:IStrand;
+		
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+			
+			IEventDispatcher(_strand).addEventListener("itemsCreated",handleCreated);
+			IEventDispatcher(_strand).addEventListener("childrenAdded",handleCreated);
+		}
+		
+		private var _numColumns:Number = 4;
+		private var _columnWidth:Number = Number.NaN;
+		private var _rowHeight:Number = Number.NaN;
+		
+		public function get numColumns():Number
+		{
+			return _numColumns;
+		}
+		public function set numColumns(value:Number):void
+		{
+			_numColumns = value;
+//			updateLayout();
+		}
+		
+		public function get columnWidth():Number
+		{
+			return _columnWidth;
+		}
+		public function set columnWidth(value:Number):void
+		{
+			_columnWidth = value;
+//			updateLayout();
+		}
+		
+		public function get rowHeight():Number
+		{
+			return _rowHeight;
+		}
+		public function set rowHeight(value:Number):void
+		{
+			_rowHeight = value;
+//			updateLayout();
+		}
+		
+		private function handleCreated(event:Event):void
+		{
+			// this is where we know the strand has things in it and we want to
+			// get the part of the strand that holds the items for the layout
+			trace("TileLayout.itemsCreated");
+			updateLayout();
+		}
+		
+		protected function updateLayout():void
+		{
+			// this is where the layout is calculated
+			var p:ILayoutParent = _strand.getBeadByType(ILayoutParent) as ILayoutParent;
+			var area:UIBase = p.contentView as UIBase;
+			if (area == null) return;
+			
+			var xpos:Number = 0;
+			var ypos:Number = 0;
+			var useWidth:Number = columnWidth;
+			var useHeight:Number = rowHeight;
+			var n:Number = area.numChildren;
+			if (n == 0) return;
+			
+			if (isNaN(useWidth)) useWidth = Math.floor(area.width / numColumns); // + gap
+			if (isNaN(useHeight)) {
+				// given the width and total number of items, how many rows?
+				var numRows:Number = Math.floor(n/numColumns);
+				useHeight = Math.floor(area.height / numRows);
+			}
+			
+			for(var i:int=0; i < n; i++)
+			{
+				var child:IUIBase = area.getChildAt(i) as IUIBase;
+				child.width = useWidth;
+				child.height = useHeight;
+				child.x = xpos;
+				child.y = ypos;
+				
+				xpos += useWidth;
+				
+				var test:Number = (i+1)%numColumns;
+				
+				if (test == 0) {
+					xpos = 0;
+					ypos += useHeight;
+				} 
+			}
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1fec5717/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/layouts/TileLayout.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/layouts/TileLayout.js
b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/layouts/TileLayout.js
new file mode 100644
index 0000000..1d3e10f
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/layouts/TileLayout.js
@@ -0,0 +1,158 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the 'License');
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an 'AS IS' BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+goog.provide('org.apache.flex.html.staticControls.beads.layouts.TileLayout');
+
+goog.require('org.apache.flex.core.IBeadLayout');
+
+
+
+/**
+ * @constructor
+ * @implements {org.apache.flex.core.IBeadLayout}
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout =
+    function() {
+  this.strand_ = null;
+  this.className = 'TileLayout';
+};
+
+
+/**
+ * Metadata
+ *
+ * @type {Object.<string, Array.<Object>>}
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout.prototype.FLEXJS_CLASS_INFO
=
+    { names: [{ name: 'TileLayout',
+                qName: 'org.apache.flex.html.staticControls.beads.layouts.TileLayout'}],
+      interfaces: [org.apache.flex.core.IBeadLayout] };
+
+
+/**
+ * @expose
+ * @return {number} The number of columns wide for the layout.
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout.prototype.
+  get_numColumns = function() {
+      return this._numColumns;
+};
+
+
+/**
+ * @expose
+ * @param {number} value The number of columns wide for the layout.
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout.prototype.
+  set_numColumns = function(value) {
+      this._numColumns = value;
+};
+
+
+/**
+ * @expose
+ * @return {number} The width of each column in the layout.
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout.prototype.
+  get_columnWidth = function() {
+      return this._columnWidth;
+};
+
+
+/**
+ * @expose
+ * @param {number} value The width of each column in the layout.
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout.prototype.
+  set_columnWidth = function(value) {
+      this._columnWidth = value;
+};
+
+
+/**
+ * @expose
+ * @return {number} The height of each row of the layout.
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout.prototype.
+  get_rowHeight = function() {
+      return this._rowHeight;
+};
+
+
+/**
+ * @expose
+ * @param {number} value The height of each row of the Tile layout.
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout.prototype.
+  set_rowHeight = function(value) {
+      this._rowHeight = value;
+};
+
+
+/**
+ * @expose
+ * @param {Object} value The new host.
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout.
+    prototype.set_strand = function(value) {
+  if (this.strand_ !== value) {
+    this.strand_ = value;
+    this.strand_.addEventListener('childrenAdded',
+        goog.bind(this.changeHandler, this));
+    this.strand_.addEventListener('layoutNeeded',
+        goog.bind(this.changeHandler, this));
+  }
+};
+
+
+/**
+ * @param {org.apache.flex.events.Event} event The text getter.
+ */
+org.apache.flex.html.staticControls.beads.layouts.TileLayout.
+    prototype.changeHandler = function(event) {
+  var children, i, n;
+  var xpos, ypos, useWidth, useHeight;
+
+  children = this.strand_.internalChildren();
+  n = children.length;
+  if (n == 0) return;
+
+  xpos = 0;
+  ypos = 0;
+  useWidth = this.get_columnWidth();
+  useHeight = this.get_rowHeight();
+
+  if (isNaN(useWidth)) useWidth = Math.floor(this.strand_.get_width() / this.get_numColumns());
// + gap
+  if (isNaN(useHeight)) {
+    // given the width and total number of items, how many rows?
+    var numRows = Math.floor(n / this.get_numColumns());
+    useHeight = Math.floor(this.strand_.get_height() / numRows);
+  }
+
+  for (i = 0; i < n; i++)
+  {
+    var child = children[i].flexjs_wrapper;
+    child.set_width(useWidth);
+    child.set_height(useHeight);
+    child.set_x(xpos);
+    child.set_y(ypos);
+
+    xpos += useWidth;
+
+    if (((i + 1) % this.get_numColumns()) == 0) {
+      xpos = 0;
+      ypos += useHeight;
+    }
+  }
+};


Mime
View raw message