You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2013/03/21 23:24:30 UTC

[08/14] git commit: DropDownList

DropDownList


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

Branch: refs/heads/develop
Commit: 178359e4920ff8023f161a6dc8e3b720d830c8be
Parents: afe0ec1
Author: Alex Harui <ah...@apache.org>
Authored: Tue Mar 19 12:31:58 2013 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Mar 19 12:31:58 2013 -0700

----------------------------------------------------------------------
 .../flex/html/staticControls/DropDownList.as       |   76 ++++--
 .../html/staticControls/beads/DropDownListBead.as  |  225 +++++++++++++++
 .../html/staticControls/beads/IDropDownListBead.as |   31 ++
 .../beads/controllers/DropDownListController.as    |   71 +++++
 .../supportClasses/DropDownListList.as             |   43 +++
 5 files changed, 426 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/178359e4/frameworks/as/src/org/apache/flex/html/staticControls/DropDownList.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/DropDownList.as b/frameworks/as/src/org/apache/flex/html/staticControls/DropDownList.as
index 80cf6fd..ae13cdf 100644
--- a/frameworks/as/src/org/apache/flex/html/staticControls/DropDownList.as
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/DropDownList.as
@@ -18,29 +18,65 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.flex.html.staticControls
 {
-	public class DropDownList
+    import org.apache.flex.core.IBead;
+    import org.apache.flex.core.ISelectionModel;
+    import org.apache.flex.core.ValuesManager;
+    import org.apache.flex.html.staticControls.beads.DropDownListBead;
+    import org.apache.flex.html.staticControls.beads.IDropDownListBead;
+	import org.apache.flex.html.staticControls.beads.controllers.DropDownListController;
+    
+    [Event("change", flash.events.Event)]
+    
+	public class DropDownList extends Button
 	{
 		public function DropDownList()
 		{
 		}
 		
-		private var _dataProvider:Array;
-		
-		public function get dataProvider():Array
-		{
-			return _dataProvider;
-		}
-		
-		public function set dataProvider(value:Array):void
-		{
-			_dataProvider = value;	
-		}
-		
-		private var _selectedIndex:int;
-		
-		public function get selectedIndex():int
-		{
-			return _selectedIndex;	
-		}
-	}
+        public function get dataProvider():Object
+        {
+            return ISelectionModel(model).dataProvider;
+        }
+        public function set dataProvider(value:Object):void
+        {
+            ISelectionModel(model).dataProvider = value;
+        }
+        
+        public function get selectedIndex():int
+        {
+            return ISelectionModel(model).selectedIndex;
+        }
+        public function set selectedIndex(value:int):void
+        {
+            ISelectionModel(model).selectedIndex = value;
+        }
+        
+        public function get selectedItem():Object
+        {
+            return ISelectionModel(model).selectedItem;
+        }
+        public function set selectedItem(value:Object):void
+        {
+            ISelectionModel(model).selectedItem = value;
+        }
+        
+        override public function initModel():void
+        {
+            if (getBeadByType(ISelectionModel) == null)
+                addBead(new (ValuesManager.valuesImpl.getValue(this, "iSelectionModel")) as IBead);
+        }
+        
+        override public function initSkin():void
+        {
+            // TODO: (aharui) remove later
+            if (getBeadByType(IDropDownListBead) == null)
+            {
+                var lb:DropDownListBead = new DropDownListBead();
+                addBead(lb);	
+				var lc:DropDownListController = new DropDownListController();
+				addBead(lc);	
+            }
+        }
+        
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/178359e4/frameworks/as/src/org/apache/flex/html/staticControls/beads/DropDownListBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/DropDownListBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/DropDownListBead.as
new file mode 100644
index 0000000..ccfe6b1
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/DropDownListBead.as
@@ -0,0 +1,225 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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
+{
+	import flash.display.DisplayObject;
+	import flash.display.DisplayObjectContainer;
+	import flash.display.Graphics;
+	import flash.display.Shape;
+	import flash.display.SimpleButton;
+	import flash.display.Sprite;
+	import flash.events.Event;
+	import flash.events.IEventDispatcher;
+	import flash.text.TextField;
+	import flash.text.TextFieldType;
+	
+	import org.apache.flex.core.IInitModel;
+	import org.apache.flex.core.IInitSkin;
+	import org.apache.flex.core.ISelectionModel;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.ValuesManager;
+
+	public class DropDownListBead implements IDropDownListBead
+	{
+		public function DropDownListBead()
+		{
+            upSprite = new Sprite();
+            downSprite = new Sprite();
+            overSprite = new Sprite();
+			upTextField = new TextField();
+			downTextField = new TextField();
+			overTextField = new TextField();
+            upSprite.addChild(upTextField);
+            overSprite.addChild(overTextField);
+            downSprite.addChild(downTextField);
+			upTextField.border = true;
+			downTextField.border = true;
+			overTextField.border = true;
+			upTextField.background = true;
+			downTextField.background = true;
+			overTextField.background = true;
+			upTextField.borderColor = 0;
+			downTextField.borderColor = 0;
+			overTextField.borderColor = 0;
+			upTextField.backgroundColor = 0xCCCCCC;
+			downTextField.backgroundColor = 0x808080;
+			overTextField.backgroundColor = 0xFFCCCC;
+			upTextField.selectable = false;
+			upTextField.type = TextFieldType.DYNAMIC;
+			downTextField.selectable = false;
+			downTextField.type = TextFieldType.DYNAMIC;
+			overTextField.selectable = false;
+			overTextField.type = TextFieldType.DYNAMIC;
+			//upTextField.autoSize = "left";
+			//downTextField.autoSize = "left";
+			//overTextField.autoSize = "left";
+            
+            upArrows = new Shape();
+            overArrows = new Shape();
+            downArrows = new Shape();
+            upSprite.addChild(upArrows);
+			overSprite.addChild(overArrows);
+			downSprite.addChild(downArrows);
+            drawArrows(upArrows, 0xCCCCCC);
+            drawArrows(overArrows, 0xFFCCCC);
+            drawArrows(downArrows, 0x808080);
+
+		}
+
+        private function drawArrows(shape:Shape, color:uint):void
+        {
+            var g:Graphics = shape.graphics;
+            g.beginFill(color);
+            g.drawRect(0, 0, 16, 16);
+            g.endFill();
+            g.beginFill(0);
+            g.moveTo(8, 2);
+            g.lineTo(12, 6);
+            g.lineTo(4, 6);
+            g.lineTo(8, 2);
+            g.endFill();
+            g.beginFill(0);
+            g.moveTo(8, 14);
+            g.lineTo(12, 10);
+            g.lineTo(4, 10);
+            g.lineTo(8, 14);
+            g.endFill();
+            g.lineStyle(1, 0);
+            g.drawRect(0, 0, 16, 16);
+        }
+        
+		private var selectionModel:ISelectionModel;
+		
+		private var _strand:IStrand;
+		
+		private var shape:Shape;
+		
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+            selectionModel = value.getBeadByType(ISelectionModel) as ISelectionModel;
+            selectionModel.addEventListener("selectedIndexChanged", selectionChangeHandler);
+			shape = new Shape();
+			shape.graphics.beginFill(0xCCCCCC);
+			shape.graphics.drawRect(0, 0, 10, 10);
+			shape.graphics.endFill();
+			SimpleButton(value).upState = upSprite;
+			SimpleButton(value).downState = downSprite;
+			SimpleButton(value).overState = overSprite;
+			SimpleButton(value).hitTestState = shape;
+			if (selectionModel.selectedIndex !== -1)
+				text = selectionModel.selectedItem.toString();
+            IEventDispatcher(value).addEventListener("heightChanged", changeHandler);
+            IEventDispatcher(value).addEventListener("widthChanged", changeHandler);
+			changeHandler(null);
+		}
+		
+		private function selectionChangeHandler(event:Event):void
+		{
+			text = selectionModel.selectedItem.toString();
+		}
+		
+        private function changeHandler(event:Event):void
+        {
+            var ww:Number = DisplayObject(_strand).width;
+            var hh:Number = DisplayObject(_strand).height;
+            upArrows.x = ww - upArrows.width;            
+            overArrows.x = ww - overArrows.width;            
+            downArrows.x = ww - downArrows.width;
+			upTextField.width = upArrows.x;
+			downTextField.width = downArrows.x;
+			overTextField.width = overArrows.x;
+			upTextField.height = hh;
+			downTextField.height = hh;
+			overTextField.height = hh;
+			shape.graphics.clear();
+			shape.graphics.beginFill(0xCCCCCC);
+			shape.graphics.drawRect(0, 0, ww, hh);
+			shape.graphics.endFill();
+        }
+        
+		private var upTextField:TextField;
+		private var downTextField:TextField;
+		private var overTextField:TextField;
+        private var upSprite:Sprite;
+        private var downSprite:Sprite;
+        private var overSprite:Sprite;
+        private var upArrows:Shape;
+        private var downArrows:Shape;
+        private var overArrows:Shape;
+		
+		public function get text():String
+		{
+			return upTextField.text;
+		}
+        
+		public function set text(value:String):void
+		{
+            var ww:Number = DisplayObject(_strand).width;
+            var hh:Number = DisplayObject(_strand).height;
+			upTextField.text = value;
+			downTextField.text = value;
+			overTextField.text = value;
+			
+		}
+		
+        private var _popUp:IStrand;
+        public function get popUp():IStrand
+        {
+            return _popUp;
+        }
+        
+        private var _popUpVisible:Boolean;
+        
+        public function get popUpVisible():Boolean
+        {
+            return _popUpVisible;
+        }
+        
+        public function set popUpVisible(value:Boolean):void
+        {
+            if (value != _popUpVisible)
+            {
+                _popUpVisible = value;
+                if (value)
+                {
+                    if (!_popUp)
+                    {
+                        var popUpClass:Class = ValuesManager.valuesImpl.getValue(_strand, "iPopUp") as Class;
+                        _popUp = new popUpClass() as IStrand;
+                    }
+					var root:Object = DisplayObject(_strand).root;
+					var host:DisplayObjectContainer = DisplayObject(_strand).parent;
+					while (host.parent != root)
+						host = host.parent;
+                    host.addChild(_popUp as DisplayObject);
+					if (_popUp is IInitModel)
+						IInitModel(_popUp).initModel();
+					if (_popUp is IInitSkin)
+						IInitSkin(_popUp).initSkin();
+                }
+                else
+                {
+                    DisplayObject(_popUp).parent.removeChild(_popUp as DisplayObject);                    
+                }
+            }
+        }
+        
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/178359e4/frameworks/as/src/org/apache/flex/html/staticControls/beads/IDropDownListBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/IDropDownListBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/IDropDownListBead.as
new file mode 100644
index 0000000..2824187
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/IDropDownListBead.as
@@ -0,0 +1,31 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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
+{
+    import org.apache.flex.core.IBead;
+    import org.apache.flex.core.IStrand;
+
+	public interface IDropDownListBead extends IBead
+	{
+        function get popUp():IStrand;
+        
+        function get popUpVisible():Boolean;
+        function set popUpVisible(value:Boolean):void;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/178359e4/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/DropDownListController.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/DropDownListController.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/DropDownListController.as
new file mode 100644
index 0000000..86dcd77
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/DropDownListController.as
@@ -0,0 +1,71 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.controllers
+{
+	import flash.display.DisplayObject;
+	import flash.events.Event;
+	import flash.events.IEventDispatcher;
+	import flash.events.MouseEvent;
+	
+	import org.apache.flex.core.IBead;
+	import org.apache.flex.core.ISelectionModel;
+	import org.apache.flex.core.IStrand;
+	import org.apache.flex.html.staticControls.beads.IDropDownListBead;
+
+	public class DropDownListController implements IBead
+	{
+		public function DropDownListController()
+		{
+		}
+		
+		private var _strand:IStrand;
+		
+		public function set strand(value:IStrand):void
+		{
+			_strand = value;
+            IEventDispatcher(value).addEventListener(MouseEvent.CLICK, clickHandler);
+		}
+		
+        private function clickHandler(event:Event):void
+        {
+            var viewBead:IDropDownListBead = _strand.getBeadByType(IDropDownListBead) as IDropDownListBead;
+            viewBead.popUpVisible = true;
+            var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
+            var popUpModel:ISelectionModel = viewBead.popUp.getBeadByType(ISelectionModel) as ISelectionModel;
+            popUpModel.dataProvider = selectionModel.dataProvider;
+            popUpModel.selectedIndex = selectionModel.selectedIndex;
+			DisplayObject(viewBead.popUp).width = DisplayObject(_strand).width;
+			DisplayObject(viewBead.popUp).height = 200;
+			DisplayObject(viewBead.popUp).x = DisplayObject(_strand).x;
+			DisplayObject(viewBead.popUp).y = DisplayObject(_strand).y;
+            IEventDispatcher(viewBead.popUp).addEventListener(Event.CHANGE, changeHandler);
+        }
+        
+        private function changeHandler(event:Event):void
+        {
+            var viewBead:IDropDownListBead = _strand.getBeadByType(IDropDownListBead) as IDropDownListBead;
+            viewBead.popUpVisible = false;
+            var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
+            var popUpModel:ISelectionModel = viewBead.popUp.getBeadByType(ISelectionModel) as ISelectionModel;
+            selectionModel.selectedIndex = popUpModel.selectedIndex;
+			IEventDispatcher(_strand).dispatchEvent(new Event("change"));
+        }
+	
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/178359e4/frameworks/as/src/org/apache/flex/html/staticControls/supportClasses/DropDownListList.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/supportClasses/DropDownListList.as b/frameworks/as/src/org/apache/flex/html/staticControls/supportClasses/DropDownListList.as
new file mode 100644
index 0000000..2d66c6d
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/supportClasses/DropDownListList.as
@@ -0,0 +1,43 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.supportClasses
+{
+    import org.apache.flex.core.IPopUp;
+    import org.apache.flex.html.staticControls.List;
+    import org.apache.flex.html.staticControls.beads.SolidBackgroundBead;
+    
+    [Event("change", flash.events.Event)]
+    
+	public class DropDownListList extends List implements IPopUp
+	{
+		public function DropDownListList()
+		{
+			super();
+		}
+		
+		override public function initSkin():void
+		{
+			super.initSkin();
+			
+			var bb:SolidBackgroundBead = new SolidBackgroundBead();
+			bb.backgroundColor = 0xffffff;
+			addBead(bb);
+		}
+	}
+}
\ No newline at end of file