Looks mostly ok, but Array has the same issue as Object.  It will cause
memory leaks unless you know of a way to clean up the Array.

Maybe one approach is to have a property on each RadioButton instance that
is the selectedValue that way there isn't an external entity to query:  You
can ask any RadioButton which one is selected.  RadioButtons could probably
reference each other because they'll get thrown away as a group.  The only
question is how do they find each other?  Maybe on the AS side you can use a
Dictionary and on the JS side it doesn't matter, you can query whatever
array is created for them.  I guess the JS RBs must know how to find each
other.


On 3/1/13 12:49 PM, "p...@apache.org" <p...@apache.org> wrote:

> Author: pent
> Date: Fri Mar  1 20:49:58 2013
> New Revision: 1451713
> 
> URL: http://svn.apache.org/r1451713
> Log:
> Moved button group management to the RadioButton. Map to IButtonGroup is done
> through ValuesManager
> 
> Added:
>     
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IButtonGroup
> .as   (with props)
> Modified:
>     
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/ButtonGroup.
> as
>     
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IRadioButton
> Bead.as
>     
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IValueToggle
> ButtonModel.as
>     
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticContro
> ls/RadioButton.as
>     
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticContro
> ls/beads/models/ValueToggleButtonModel.as
> 
> Modified: 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/ButtonGroup.
> as
> URL: 
> http://svn.apache.org/viewvc/flex/asjs/branches/develop/frameworks/as/src/org/
> apache/flex/core/ButtonGroup.as?rev=1451713&r1=1451712&r2=1451713&view=diff
> ==============================================================================
> --- 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/ButtonGroup.
> as (original)
> +++ 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/ButtonGroup.
> as Fri Mar  1 20:49:58 2013
> @@ -21,27 +21,8 @@ package org.apache.flex.core
> import flash.events.Event;
> import flash.events.EventDispatcher;
>  
> - public class ButtonGroup extends EventDispatcher
> + public class ButtonGroup extends EventDispatcher implements IButtonGroup
> {
> -  private static var groups:Object;
> -  
> -  public static function getGroup( name:String ) : ButtonGroup
> -  {
> -   if( groups == null ) {
> -    groups = new Object();
> -   }
> -   
> -   var result:ButtonGroup;
> -   if( groups.hasOwnProperty(name) ) result = groups[name];
> -   else {
> -    result = new ButtonGroup();
> -    result.name = name;
> -    groups[name] = result;
> -   }
> -   return result;
> -  }
> -  
> -  
> public function ButtonGroup()
> {
> }
> 
> Added: 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IButtonGroup
> .as
> URL: 
> http://svn.apache.org/viewvc/flex/asjs/branches/develop/frameworks/as/src/org/
> apache/flex/core/IButtonGroup.as?rev=1451713&view=auto
> ==============================================================================
> --- 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IButtonGroup
> .as (added)
> +++ 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IButtonGroup
> .as Fri Mar  1 20:49:58 2013
> @@ -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.core
> +{
> + import flash.events.IEventDispatcher;
> +
> + public interface IButtonGroup extends IEventDispatcher
> + { 
> +  function get name() : String;
> +  function set name(value:String):void;
> +  
> +  function get value() : Object;
> +  function set value(newValue:Object):void;
> + }
> +}
> \ No newline at end of file
> 
> Propchange: 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IButtonGroup
> .as
> ------------------------------------------------------------------------------
>     svn:eol-style = native
> 
> Modified: 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IRadioButton
> Bead.as
> URL: 
> http://svn.apache.org/viewvc/flex/asjs/branches/develop/frameworks/as/src/org/
> apache/flex/core/IRadioButtonBead.as?rev=1451713&r1=1451712&r2=1451713&view=di
> ff
> ==============================================================================
> --- 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IRadioButton
> Bead.as (original)
> +++ 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IRadioButton
> Bead.as Fri Mar  1 20:49:58 2013
> @@ -25,5 +25,8 @@ package org.apache.flex.core
> 
> function get html():String;
> function set html(value:String):void;
> +  
> +  function get selected():Boolean;
> +  function set selected(value:Boolean):void;
> }
>  }
> \ No newline at end of file
> 
> Modified: 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IValueToggle
> ButtonModel.as
> URL: 
> http://svn.apache.org/viewvc/flex/asjs/branches/develop/frameworks/as/src/org/
> apache/flex/core/IValueToggleButtonModel.as?rev=1451713&r1=1451712&r2=1451713&
> view=diff
> ==============================================================================
> --- 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IValueToggle
> ButtonModel.as (original)
> +++ 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/core/IValueToggle
> ButtonModel.as Fri Mar  1 20:49:58 2013
> @@ -25,7 +25,5 @@ package org.apache.flex.core
> 
> function get groupName():String;
> function set groupName(value:String):void;
> -  
> -  function get buttonGroup():ButtonGroup;
> }
>  }
> \ No newline at end of file
> 
> Modified: 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticContro
> ls/RadioButton.as
> URL: 
> http://svn.apache.org/viewvc/flex/asjs/branches/develop/frameworks/as/src/org/
> apache/flex/html/staticControls/RadioButton.as?rev=1451713&r1=1451712&r2=14517
> 13&view=diff
> ==============================================================================
> --- 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticContro
> ls/RadioButton.as (original)
> +++ 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticContro
> ls/RadioButton.as Fri Mar  1 20:49:58 2013
> @@ -23,9 +23,9 @@ package org.apache.flex.html.staticContr
> import flash.events.Event;
> import flash.events.MouseEvent;
> 
> - import org.apache.flex.core.ButtonGroup;
> 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,10 +42,9 @@ package org.apache.flex.html.staticContr
> addEventListener(MouseEvent.CLICK, internalMouseHandler);
> }
> 
> -  private function handleValueChange(event:Event):void
> -  {
> -   selected = IValueToggleButtonModel(model).buttonGroup.value == value;
> -  }
> +  protected static var groups:Array = new Array();
> +  
> +  private var _buttonGroup:IButtonGroup;
> 
> private var _groupName:String;
> 
> @@ -56,8 +55,22 @@ package org.apache.flex.html.staticContr
> 
> public function set groupName(value:String) : void
> {
> -   IValueToggleButtonModel(model).groupName = value;
> -   IValueToggleButtonModel(model).buttonGroup.addEventListener("valueChange",
> handleValueChange);
> +   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);
> }
> 
> public function get text():String
> @@ -77,6 +90,10 @@ package org.apache.flex.html.staticContr
> public function set selected(selValue:Boolean):void
> {
> IValueToggleButtonModel(model).selected = selValue;
> +   
> +   if( selValue ) {
> +    _buttonGroup.value = value;
> +   }
> }
> 
> public function get value():Object
> @@ -196,6 +213,11 @@ 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/staticContro
> ls/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=145
> 1713&r1=1451712&r2=1451713&view=diff
> ==============================================================================
> --- 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticContro
> ls/beads/models/ValueToggleButtonModel.as (original)
> +++ 
> flex/asjs/branches/develop/frameworks/as/src/org/apache/flex/html/staticContro
> ls/beads/models/ValueToggleButtonModel.as Fri Mar  1 20:49:58 2013
> @@ -20,7 +20,6 @@ package org.apache.flex.html.staticContr
>  {
> import flash.events.Event;
> 
> - import org.apache.flex.core.ButtonGroup;
> import org.apache.flex.core.IValueToggleButtonModel;
>  
> public class ValueToggleButtonModel extends ToggleButtonModel implements
> IValueToggleButtonModel
> @@ -30,18 +29,6 @@ package org.apache.flex.html.staticContr
> super();
> }
> 
> -  override public function set selected(selValue:Boolean):void
> -  {
> -   if( selValue != super.selected )
> -   {
> -    super.selected = selValue;
> -    
> -    if( selValue ) {
> -     _buttonGroup.value = this.value;
> -    }
> -   }
> -  }
> -  
> private var _value:Object;
> 
> public function get value():Object
> @@ -71,16 +58,7 @@ package org.apache.flex.html.staticContr
> {
> _groupName = value;
> dispatchEvent(new Event("groupNameChange"));
> -    
> -    _buttonGroup = ButtonGroup.getGroup(groupName);
> }
> }
> -  
> -  private var _buttonGroup:ButtonGroup;
> -  
> -  public function get buttonGroup() : ButtonGroup
> -  {
> -   return _buttonGroup;
> -  }
> }
>  }
> \ No newline at end of file
> 
> 

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui

Reply via email to