flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject svn commit: r1452510 - in /flex/asjs/branches/develop/frameworks/as/src/org/apache/flex: core/ html/staticControls/ html/staticControls/beads/ html/staticControls/beads/models/
Date Mon, 04 Mar 2013 20:53:31 GMT
Author: pent
Date: Mon Mar  4 20:53:31 2013
New Revision: 1452510

URL: http://svn.apache.org/r1452510
Log:
Removed need for ButtonGroup in RadioButton class; now self-manages its groups

Removed:
    flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/ButtonGroup.as
    flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IButtonGroup.as
Modified:
    flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IValueToggleButtonModel.as
    flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/RadioButton.as
    flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/RadioButtonBead.as
    flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/models/ValueToggleButtonModel.as

Modified: flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IValueToggleButtonModel.as
URL: http://svn.apache.org/viewvc/flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IValueToggleButtonModel.as?rev=1452510&r1=1452509&r2=1452510&view=diff
==============================================================================
--- flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IValueToggleButtonModel.as
(original)
+++ flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IValueToggleButtonModel.as
Mon Mar  4 20:53:31 2013
@@ -25,5 +25,8 @@ package org.apache.flex.core
 		
 		function get groupName():String;
 		function set groupName(value:String):void;
+		
+		function get selectedValue():Object;
+		function set selectedValue(newValue:Object):void;
 	}
 }
\ No newline at end of file

Modified: flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/RadioButton.as
URL: http://svn.apache.org/viewvc/flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/RadioButton.as?rev=1452510&r1=1452509&r2=1452510&view=diff
==============================================================================
--- flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/RadioButton.as
(original)
+++ flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/RadioButton.as
Mon Mar  4 20:53:31 2013
@@ -22,10 +22,10 @@ package org.apache.flex.html.staticContr
 	import flash.display.SimpleButton;
 	import flash.events.Event;
 	import flash.events.MouseEvent;
+	import flash.utils.Dictionary;
 	
 	import org.apache.flex.core.IBead;
 	import org.apache.flex.core.IBeadModel;
-	import org.apache.flex.core.IButtonGroup;
 	import org.apache.flex.core.IInitModel;
 	import org.apache.flex.core.IInitSkin;
 	import org.apache.flex.core.IRadioButtonBead;
@@ -42,9 +42,7 @@ package org.apache.flex.html.staticContr
 			addEventListener(MouseEvent.CLICK, internalMouseHandler);
 		}
 		
-		protected static var groups:Array = new Array();
-		
-		private var _buttonGroup:IButtonGroup;
+		protected static var dict:Dictionary = new Dictionary(true);
 		
 		private var _groupName:String;
 		
@@ -55,22 +53,7 @@ package org.apache.flex.html.staticContr
 		
 		public function set groupName(value:String) : void
 		{
-			for(var i:int=0; i < groups.length; i++)
-			{
-				var bg:IButtonGroup = groups[i] as IButtonGroup;
-				if( bg.name == value ) {
-					_buttonGroup = bg;
-					break;
-				}
-			}
-			
-			if( _buttonGroup == null )  {
-				_buttonGroup = new (ValuesManager.valuesImpl.getValue("IButtonGroup")) as IButtonGroup;
-				_buttonGroup.name = value;
-				groups.push(_buttonGroup);
-			}
-			
-			_buttonGroup.addEventListener("valueChange", handleButtonGroupValueChange);
+			IValueToggleButtonModel(model).groupName = value;
 		}
 		
 		public function get text():String
@@ -91,8 +74,16 @@ package org.apache.flex.html.staticContr
 		{
 			IValueToggleButtonModel(model).selected = selValue;
 			
+			// if this button is being selected, its value should become
+			// its group's selectedValue
 			if( selValue ) {
-				_buttonGroup.value = value;
+				for each(var rb:RadioButton in dict)
+				{
+					if( rb.groupName == groupName )
+					{
+						rb.selectedValue = value;
+					}
+				}
 			}
 		}
 		
@@ -106,6 +97,18 @@ package org.apache.flex.html.staticContr
 			IValueToggleButtonModel(model).value = newValue;
 		}
 		
+		public function get selectedValue():Object 
+		{
+			return IValueToggleButtonModel(model).selectedValue;
+		}
+		
+		public function set selectedValue(newValue:Object):void 
+		{
+			// a radio button is really selected when its value matches that of the group's value
+			IValueToggleButtonModel(model).selected = (newValue == value);
+			IValueToggleButtonModel(model).selectedValue = newValue;
+		}
+		
 		public function initModel():void
 		{
 			if (getBeadByType(IValueToggleButtonModel) == null) 
@@ -119,6 +122,19 @@ package org.apache.flex.html.staticContr
 			
 			_width = $width;
 			_height = $height;
+			
+			// make sure this button's selectedValue is set from its group's selectedValue
+			// to keep it in sync with the rest of the buttons in its group.
+			for each(var rb:RadioButton in dict)
+			{
+				if( rb.groupName == groupName )
+				{
+					selectedValue = rb.selectedValue;
+					break;
+				}
+			}
+			
+			dict[this] = this;
 		}
 		
 		private var _id:String;
@@ -213,11 +229,6 @@ package org.apache.flex.html.staticContr
 			return null;
 		}
 		
-		private function handleButtonGroupValueChange(event:Event):void
-		{
-			selected = _buttonGroup.value == value;
-		}
-		
 		private function internalMouseHandler(event:MouseEvent) : void
 		{
 			// prevent radiobutton from being turned off by a click

Modified: flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/RadioButtonBead.as
URL: http://svn.apache.org/viewvc/flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/RadioButtonBead.as?rev=1452510&r1=1452509&r2=1452510&view=diff
==============================================================================
--- flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/RadioButtonBead.as
(original)
+++ flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/RadioButtonBead.as
Mon Mar  4 20:53:31 2013
@@ -79,7 +79,7 @@ package org.apache.flex.html.staticContr
 			_toggleButtonModel = value.getBeadByType(IValueToggleButtonModel) as IValueToggleButtonModel;
 			_toggleButtonModel.addEventListener("textChange", textChangeHandler);
 			_toggleButtonModel.addEventListener("htmlChange", htmlChangeHandler);
-			_toggleButtonModel.addEventListener("selectedChange", selectedChangeHandler);
+			_toggleButtonModel.addEventListener("selectedValueChange", selectedValueChangeHandler);
 			if (_toggleButtonModel.text != null)
 				text = _toggleButtonModel.text;
 			if (_toggleButtonModel.html != null)
@@ -162,8 +162,6 @@ package org.apache.flex.html.staticContr
 		{
 			_selected = value;
 			
-			layoutControl();
-			
 			if( value ) {
 				SimpleButton(_strand).upState = upAndSelectedSprite;
 				SimpleButton(_strand).downState = downAndSelectedSprite;
@@ -174,11 +172,13 @@ package org.apache.flex.html.staticContr
 				SimpleButton(_strand).downState = downSprite;
 				SimpleButton(_strand).overState = overSprite;
 			}
+			
+			layoutControl();
 		}
 		
-		private function selectedChangeHandler(event:Event):void
+		private function selectedValueChangeHandler(event:Event):void
 		{
-			selected = toggleButtonModel.selected;
+			selected = _toggleButtonModel.value == _toggleButtonModel.selectedValue;
 		}
 		
 		protected function layoutControl() : void
@@ -209,7 +209,7 @@ package org.apache.flex.html.staticContr
 			icon.graphics.drawEllipse(0,0,10,10);
 			icon.graphics.endFill();
 			
-			if( _toggleButtonModel.selected ) {
+			if( selected ) {
 				icon.graphics.beginFill(0x555555);
 				icon.graphics.drawEllipse(2,2,6,6);
 				icon.graphics.endFill();

Modified: flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/models/ValueToggleButtonModel.as
URL: http://svn.apache.org/viewvc/flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/models/ValueToggleButtonModel.as?rev=1452510&r1=1452509&r2=1452510&view=diff
==============================================================================
--- flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/models/ValueToggleButtonModel.as
(original)
+++ flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticControls/beads/models/ValueToggleButtonModel.as
Mon Mar  4 20:53:31 2013
@@ -60,5 +60,21 @@ package org.apache.flex.html.staticContr
 				dispatchEvent(new Event("groupNameChange"));
 			}
 		}
+		
+		private var _selectedValue:Object;
+		
+		public function get selectedValue():Object
+		{
+			return _selectedValue;
+		}
+		
+		public function set selectedValue(newValue:Object):void
+		{
+			if( _selectedValue != newValue )
+			{
+				_selectedValue = newValue;
+				dispatchEvent(new Event("selectedValueChange"));
+			}
+		}
 	}
 }
\ No newline at end of file



Mime
View raw message