This is an automated email from the ASF dual-hosted git repository.

pent pushed a commit to branch feature/MXRoyale
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/feature/MXRoyale by this push:
     new 234ba18  Added RadioButton and RadioButtonGroup
234ba18 is described below

commit 234ba18740d00eec36bb265687553b2219b1cfbb
Author: Peter Ent <p...@apache.org>
AuthorDate: Wed Mar 7 16:27:14 2018 -0500

    Added RadioButton and RadioButtonGroup
---
 .../MXRoyale/src/main/royale/mx/controls/Button.as |   6 +-
 .../src/main/royale/mx/controls/RadioButton.as     | 528 ++++++++++++++++++
 .../main/royale/mx/controls/RadioButtonGroup.as    | 596 +++++++++++++++++++++
 3 files changed, 1127 insertions(+), 3 deletions(-)

diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as
index e8450aa..f8490cc 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as
@@ -332,9 +332,9 @@ use namespace mx_internal;
  *  @productversion Flex 3
  */
 public class Button extends UIComponent
-       implements IDataRenderer, IDropInListItemRenderer,
-       IFocusManagerComponent, IListItemRenderer,
-       IFontContextComponent, IButton
+       implements IDataRenderer,
+       IListItemRenderer,
+       IButton
 {
 
     
//--------------------------------------------------------------------------
diff --git 
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButton.as 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButton.as
new file mode 100644
index 0000000..427337a
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButton.as
@@ -0,0 +1,528 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 mx.controls
+{
+COMPILE::JS {
+       import goog.DEBUG;
+}
+COMPILE::SWF
+{
+       import flash.display.DisplayObject;
+       import flash.events.MouseEvent;
+       import flash.utils.Dictionary;
+       import org.apache.royale.core.UIButtonBase;
+}
+
+COMPILE::JS
+{
+       import org.apache.royale.core.UIBase;
+       import org.apache.royale.core.WrappedHTMLElement;
+       import org.apache.royale.html.supportClasses.RadioButtonIcon;
+       import org.apache.royale.html.util.addElementToWrapper;
+}
+
+import org.apache.royale.core.IStrand;
+import org.apache.royale.core.IUIBase;
+import org.apache.royale.core.IValueToggleButtonModel;
+import org.apache.royale.events.Event;
+import org.apache.royale.events.MouseEvent;
+import org.apache.royale.core.ISelectable;
+/*
+import flash.events.Event;
+import flash.events.KeyboardEvent;
+import flash.events.MouseEvent;
+import flash.ui.Keyboard;
+import mx.core.IFlexDisplayObject;
+import mx.core.IFlexModuleFactory;
+import mx.core.mx_internal;
+import mx.events.FlexEvent;
+import mx.core.FlexVersion;
+import mx.core.IToggleButton;
+import mx.events.ItemClickEvent;
+import mx.managers.IFocusManager;
+import mx.managers.IFocusManagerGroup;
+import mx.core.UITextField;
+import mx.styles.CSSStyleDeclaration;
+import mx.styles.StyleManager;
+import flash.text.TextLineMetrics;
+import flash.utils.getQualifiedClassName;
+
+use namespace mx_internal;
+*/
+
+
+/**
+ *  The RadioButton control lets the user make a single choice
+ *  within a set of mutually exclusive choices.
+ *  A RadioButton group is composed of two or more RadioButton controls
+ *  with the same <code>groupName</code> property. While grouping RadioButton 
instances
+ *  in a RadioButtonGroup is optional, a group lets you do things
+ *  like set a single event handler on a group of buttons, rather than
+ *  on each individual button. The RadioButton group can refer to a group 
created by the
+ *  <code>&lt;mx:RadioButtonGroup&gt;</code> tag.
+ *  The user selects only one member of the group at a time.
+ *  Selecting an unselected group member deselects the currently selected
+ *  RadioButton control within that group.
+ *
+ *  <p>The RadioButton control has the following default characteristics:</p>
+ *     <table class="innertable">
+ *        <tr>
+ *           <th>Characteristic</th>
+ *           <th>Description</th>
+ *        </tr>
+ *        <tr>
+ *           <td>Default size</td>
+ *           <td>Wide enough to display the text label of the control</td>
+ *        </tr>
+ *        <tr>
+ *           <td>Minimum size</td>
+ *           <td>0 pixels</td>
+ *        </tr>
+ *        <tr>
+ *           <td>Maximum size</td>
+ *           <td>Undefined</td>
+ *        </tr>
+ *     </table>
+ *
+ *  @mxml
+ *
+ *  <p>The <code>&lt;mx:RadioButton&gt;</code> tag inherits all of the tag
+ *  attributes of its superclass, and adds the following tag attributes:</p>
+ *
+ *  <pre>
+ *  &lt;mx:RadioButton
+ *    <strong>Properties</strong>
+ *    groupName=""
+ *    labelPlacement="right|left|top|bottom"
+ *
+ *    <strong>Styles</strong>
+ *    disabledIconColor="0x999999"
+ *    iconColor="0x2B333C"
+ *  /&gt;
+ *  </pre>
+ *
+ *  @includeExample examples/RadioButtonExample.mxml
+ *
+ *  @see mx.controls.RadioButtonGroup
+ *
+ *  @langversion 3.0
+ *  @playerversion Flash 9
+ *  @playerversion AIR 1.1
+ *  @productversion Flex 3
+ */
+COMPILE::SWF
+public class RadioButton extends Button
+{
+
+    
//--------------------------------------------------------------------------
+    //
+    //  Constructor
+    //
+    
//--------------------------------------------------------------------------
+
+    /**
+     *  Constructor.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function RadioButton()
+    {
+        super();
+
+               addEventListener(org.apache.royale.events.MouseEvent.CLICK, 
internalMouseHandler);
+    }
+
+
+
+       protected static var dict:Dictionary = new Dictionary(true);
+
+       private var _groupName:String;
+
+       /**
+        *  The name of the group. Only one RadioButton in a group is selected.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.0
+        */
+       public function get groupName() : String
+       {
+               return IValueToggleButtonModel(model).groupName;
+       }
+       public function set groupName(value:String) : void
+       {
+               IValueToggleButtonModel(model).groupName = value;
+       }
+
+
+    /**
+     *  @private
+     *  Storage for the group property.
+     */
+    private var _group:RadioButtonGroup;
+
+    /**
+     *  The RadioButtonGroup object to which this RadioButton belongs.
+     *
+     *  @default "undefined"
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function get group():RadioButtonGroup
+    {
+       if (goog.DEBUG)
+               trace("RadioButtonGroup not implemented for RadioButton");
+       return _group;
+    }
+
+    public function set group(value:RadioButtonGroup):void
+    {
+       _group = value;
+    }
+
+       /**
+        *  The string used as a label for the RadioButton.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.0
+        */
+       public function get text():String
+       {
+               return IValueToggleButtonModel(model).text;
+       }
+       public function set text(value:String):void
+       {
+               IValueToggleButtonModel(model).text = value;
+       }
+
+       /**
+        *  Whether or not the RadioButton instance is selected. Setting this 
property
+        *  causes the currently selected RadioButton in the same group to lose 
the
+        *  selection.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.0
+        */
+       public function get selected():Boolean
+       {
+               return IValueToggleButtonModel(model).selected;
+       }
+       public function set selected(selValue:Boolean):void
+       {
+               IValueToggleButtonModel(model).selected = selValue;
+
+               // if this button is being selected, its value should become
+               // its group's selectedValue
+               if( selValue ) {
+                       for each(var rb:RadioButton in dict)
+                       {
+                               if( rb.groupName == groupName )
+                               {
+                                       rb.selectedValue = value;
+                               }
+                       }
+               }
+       }
+
+       /**
+        *  The value associated with the RadioButton. For example, 
RadioButtons with labels,
+        *  "Red", "Green", and "Blue" might have the values 0, 1, and 2 
respectively.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.0
+        */
+       public function get value():Object
+       {
+               return IValueToggleButtonModel(model).value;
+       }
+       public function set value(newValue:Object):void
+       {
+               IValueToggleButtonModel(model).value = newValue;
+       }
+
+       /**
+        *  The group's currently selected value.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.0
+        */
+       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;
+       }
+
+       /**
+        * @private
+        */
+       override public function addedToParent():void
+       {
+               super.addedToParent();
+
+               // if this instance is selected, set the local selectedValue to
+               // this instance's value
+               if( selected ) selectedValue = value;
+
+               else {
+
+                       // 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
+        */
+       private function 
internalMouseHandler(event:org.apache.royale.events.MouseEvent) : void
+       {
+               // prevent radiobutton from being turned off by a click
+               if( !selected ) {
+                       selected = !selected;
+                       dispatchEvent(new Event("change"));
+               }
+       }
+}
+
+
+COMPILE::JS
+public class RadioButton extends Button
+{
+
+    
//--------------------------------------------------------------------------
+    //
+    //  Constructor
+    //
+    
//--------------------------------------------------------------------------
+
+    /**
+     *  Constructor.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function RadioButton()
+    {
+        super();
+    }
+
+    /**
+        * @private
+        *
+        *  @royalesuppresspublicvarwarning
+        */
+       public static var radioCounter:int = 0;
+
+       private var labelFor:HTMLLabelElement;
+       private var textNode:Text;
+       private var icon:RadioButtonIcon;
+
+       /**
+        * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
+        * @royaleignorecoercion HTMLInputElement
+        * @royaleignorecoercion HTMLLabelElement
+        * @royaleignorecoercion Text
+        */
+       override protected function createElement():WrappedHTMLElement
+       {
+               icon = new RadioButtonIcon()
+               icon.id = '_radio_' + RadioButton.radioCounter++;
+
+               textNode = document.createTextNode('') as Text;
+
+               labelFor = addElementToWrapper(this,'label') as 
HTMLLabelElement;
+               labelFor.appendChild(icon.element);
+               labelFor.appendChild(textNode);
+
+          (textNode as WrappedHTMLElement).royale_wrapper = this;
+               (icon.element as WrappedHTMLElement).royale_wrapper = this;
+
+               typeNames = 'RadioButton';
+
+               return element;
+       }
+
+       override public function set id(value:String):void
+       {
+               super.id = value;
+               labelFor.id = value;
+               icon.element.id = value;
+       }
+
+       /**
+        * @royaleignorecoercion HTMLInputElement
+        */
+       public function get groupName():String
+       {
+               return (icon.element as HTMLInputElement).name as String;
+       }
+       /**
+        * @royaleignorecoercion HTMLInputElement
+        */
+       public function set groupName(value:String):void
+       {
+               (icon.element as HTMLInputElement).name = value;
+       }
+
+    /**
+     *  @private
+     *  Storage for the group property.
+     */
+    private var _group:RadioButtonGroup;
+
+    /**
+     *  The RadioButtonGroup object to which this RadioButton belongs.
+     *
+     *  @default "undefined"
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function get group():RadioButtonGroup
+    {
+       if (goog.DEBUG)
+               trace("RadioButtonGroup not implemented for RadioButton");
+       return _group;
+    }
+
+    public function set group(value:RadioButtonGroup):void
+    {
+       _group = value;
+    }
+
+       public function get text():String
+       {
+               return textNode.nodeValue as String;
+       }
+       public function set text(value:String):void
+       {
+               textNode.nodeValue = value;
+       }
+
+       /**
+        * @royaleignorecoercion HTMLInputElement
+        * @export
+        */
+       public function get selected():Boolean
+       {
+               return (icon.element as HTMLInputElement).checked;
+       }
+       /**
+        * @royaleignorecoercion HTMLInputElement
+        */
+       public function set selected(value:Boolean):void
+       {
+               (icon.element as HTMLInputElement).checked = value;
+       }
+
+       /**
+        * @royaleignorecoercion HTMLInputElement
+        */
+       public function get value():String
+       {
+               return (icon.element as HTMLInputElement).value;
+       }
+       /**
+        * @royaleignorecoercion HTMLInputElement
+        */
+       public function set value(v:String):void
+       {
+               (icon.element as HTMLInputElement).value = "" + v;
+       }
+
+       /**
+        * @royaleignorecoercion HTMLInputElement
+        */
+       public function get selectedValue():Object
+       {
+               var buttons:NodeList;
+               var groupName:String;
+               var i:int;
+               var n:int;
+
+               groupName = (icon.element as HTMLInputElement).name;
+               buttons = document.getElementsByName(groupName);
+               n = buttons.length;
+
+               for (i = 0; i < n; i++) {
+                       if (buttons[i].checked) {
+                               return buttons[i].value;
+                       }
+               }
+               return null;
+       }
+
+       /**
+        * @royaleignorecoercion Array
+        * @royaleignorecoercion HTMLInputElement
+        */
+       public function set selectedValue(value:Object):void
+       {
+               var buttons:NodeList;
+               var groupName:String;
+               var i:int;
+               var n:int;
+
+               groupName = (icon.element as HTMLInputElement).name;
+               buttons = document.getElementsByName(groupName);
+               n = buttons.length;
+               for (i = 0; i < n; i++) {
+                       if (buttons[i].value === value) {
+                               buttons[i].checked = true;
+                               break;
+                       }
+               }
+       }
+}
+
+}
diff --git 
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButtonGroup.as 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButtonGroup.as
new file mode 100644
index 0000000..397d003
--- /dev/null
+++ 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButtonGroup.as
@@ -0,0 +1,596 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 mx.controls
+{
+COMPILE::JS {
+       import goog.DEBUG;
+}
+import org.apache.royale.core.IDocument;
+import org.apache.royale.events.EventDispatcher;
+/*
+import flash.display.DisplayObject;
+import flash.display.DisplayObjectContainer;
+import flash.display.InteractiveObject;
+import flash.events.Event;
+import flash.events.EventDispatcher;
+
+import mx.core.FlexGlobals;
+import mx.core.IFlexDisplayObject;
+import mx.core.IMXMLObject;
+import mx.core.IRawChildrenContainer;
+import mx.core.UIComponent;
+import mx.core.mx_internal;
+import mx.events.FlexEvent;
+import mx.events.ItemClickEvent;
+
+use namespace mx_internal;
+*/
+
+//--------------------------------------
+//  Events
+//--------------------------------------
+
+/**
+ *  Dispatched when the value of the selected RadioButton control in
+ *  this group changes.
+ *
+ *  @eventType flash.events.Event.CHANGE
+ *
+ *  @langversion 3.0
+ *  @playerversion Flash 9
+ *  @playerversion AIR 1.1
+ *  @productversion Flex 3
+ */
+[Event(name="change", type="org.apache.royale.events.Event")]
+
+/**
+ *  Dispatched when a user selects a RadioButton control in the group.
+ *  You can also set a handler for individual RadioButton controls.
+ *
+ *  @eventType mx.events.ItemClickEvent.ITEM_CLICK
+ *
+ *  @langversion 3.0
+ *  @playerversion Flash 9
+ *  @playerversion AIR 1.1
+ *  @productversion Flex 3
+ */
+[Event(name="itemClick", type="org.apache.royale.events.ItemClickEvent")]
+
+/**
+ *  The RadioButtonGroup control defines a group of RadioButton controls
+ *  that act as a single mutually exclusive control; therefore,
+ *  a user can select only one RadioButton control at a time. While grouping
+ *  RadioButton instances
+ *  in a RadioButtonGroup is optional, a group lets you do things
+ *  like set a single event handler on a group of buttons, rather than
+ *  on each individual button.
+ *
+ *  <p>The <code>id</code> property is required when you use the
+ *  <code>&lt;mx:RadioButtonGroup&gt;</code> tag to define the name
+ *  of the group.</p>
+ *
+ *  <p>Notice that the RadioButtonGroup control is a subclass of 
EventDispatcher, not UIComponent,
+ *  and implements the IMXMLObject interface.
+ *  All other Flex visual components are subclasses of UIComponent, which 
implements
+ *  the IUIComponent interface.
+ *  The RadioButtonGroup control has support built into the Flex compiler
+ *  that allows you to use the RadioButtonGroup control as a child of a Flex 
container,
+ *  even though it does not implement IUIComponent.
+ *  All other container children must implement the IUIComponent interface.</p>
+ *
+ *  <p>Therefore, if you try to define a visual component as a subclass of
+ *  EventDispatcher that implements the IMXMLObject interface,
+ *  you will not be able to use it as the child of a container.</p>
+ *
+ *  @mxml
+ *
+ *  <p>The <code>&lt;mx:RadioButtonGroup&gt;</code> tag inherits all of the
+ *  tag attributes of its superclass, and adds the following tag 
attributes:</p>
+ *
+ *  <pre>
+ *  &lt;mx:RadioButtonGroup
+ *    <strong>Properties</strong>
+ *    enabled="true|false"
+ *    id="<i>No default</i>"
+ *    labelPlacement="right|left|top|bottom"
+ *
+ *    <strong>Events</strong>
+ *    change="<i>No default</i>"
+ *    itemClick="<i>No default</i>"
+ *  /&gt;
+ *  </pre>
+ *
+ *  @includeExample examples/RadioButtonGroupExample.mxml
+ *
+ *  @see mx.controls.RadioButton
+ *
+ *  @langversion 3.0
+ *  @playerversion Flash 9
+ *  @playerversion AIR 1.1
+ *  @productversion Flex 3
+ */
+public class RadioButtonGroup extends EventDispatcher
+{
+    
//--------------------------------------------------------------------------
+    //
+    //  Constructor
+    //
+    
//--------------------------------------------------------------------------
+
+    /**
+     *  Constructor.
+     *
+     *  @param document In simple cases where a class extends EventDispatcher,
+     *  the <code>document</code> parameter should not be used.
+     *
+     *  @see flash.events.EventDispatcher
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function RadioButtonGroup(document:IDocument = null)
+    {
+        super();
+    }
+
+    
//--------------------------------------------------------------------------
+    //
+    //  Variables
+    //
+    
//--------------------------------------------------------------------------
+
+    /**
+     *  @private
+     *  The document containing a reference to this RadioButtonGroup.
+     */
+    private var document:IDocument;
+
+    /**
+     *  @private
+     *  An Array of the RadioButtons that belong to this group.
+     */
+    private var radioButtons:Array /* of RadioButton */ = [];
+
+    
//--------------------------------------------------------------------------
+    //
+    //  Properties
+    //
+    
//--------------------------------------------------------------------------
+
+    //----------------------------------
+    //  enabled
+    //----------------------------------
+
+    [Bindable("enabledChanged")]
+    [Inspectable(category="General", defaultValue="true")]
+
+    /**
+     *  Determines whether selection is allowed.
+     *
+     *  @default true
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function get enabled():Boolean
+    {
+        var s:Number = 0;
+
+        var n:int = numRadioButtons;
+        for (var i:int = 0; i < n; i++)
+        {
+            s = s + getRadioButtonAt(i).enabled;
+        }
+
+        if (s == 0)
+            return false;
+
+        if (s == n)
+            return true;
+
+        return false;
+    }
+
+    /**
+     *  @private
+     */
+    public function set enabled(value:Boolean):void
+    {
+        var n:int = numRadioButtons;
+        for (var i:int = 0; i < n; i++)
+        {
+            getRadioButtonAt(i).enabled = value;
+        }
+
+        dispatchEvent(new Event("enabledChanged"));
+    }
+
+    //----------------------------------
+    //  labelPlacement
+    //----------------------------------
+
+    /**
+     *  @private
+     *  Storage for the labelPlacement property.
+     */
+    private var _labelPlacement:String = "right";
+
+    [Bindable("labelPlacementChanged")]
+    [Inspectable(category="General", enumeration="left,right,top,bottom", 
defaultValue="right")]
+
+    /**
+     *  Position of the RadioButton label relative to the RadioButton icon
+     *  for each control in the group.
+     *  You can override this setting for the individual controls.
+     *
+     *  <p>Valid values in MXML are <code>"right"</code>, <code>"left"</code>,
+     *  <code>"bottom"</code>, and <code>"top"</code>. </p>
+     *
+     *  <p>In ActionScript, you use the following constants to set this 
property:
+     *  <code>ButtonLabelPlacement.RIGHT</code>, 
<code>ButtonLabelPlacement.LEFT</code>,
+     *  <code>ButtonLabelPlacement.BOTTOM</code>, and 
<code>ButtonLabelPlacement.TOP</code>.</p>
+     *
+     *  @default "right"
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function get labelPlacement():String
+    {
+        return _labelPlacement;
+    }
+
+    /**
+     *  @private
+     */
+    public function set labelPlacement(value:String):void
+    {
+        _labelPlacement = value;
+
+        var n:int = numRadioButtons;
+        for (var i:int = 0; i < n; i++)
+        {
+            getRadioButtonAt(i).labelPlacement = value;
+        }
+    }
+
+    //----------------------------------
+    //  numRadioButtons
+    //----------------------------------
+
+    [Bindable("numRadioButtonsChanged")]
+
+    /**
+     *  The number of RadioButtons that belong to this RadioButtonGroup.
+     *
+     *  @default "undefined"
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function get numRadioButtons():int
+    {
+        return radioButtons.length;
+    }
+
+    //----------------------------------
+    //  selectedValue
+    //----------------------------------
+
+    /**
+     *  @private
+     *  Storage for the selectedValue property.
+     */
+    private var _selectedValue:Object;
+
+    [Bindable("change")]
+    [Bindable("valueCommit")]
+    [Inspectable(category="General")]
+
+    /**
+     *  The value of the <code>value</code> property of the selected
+     *  RadioButton control in the group, if this has been set
+     *  to be something other than <code>null</code> (the default value).
+     *  Otherwise, <code>selectedValue</code> is the value of the
+     *  <code>label</code> property of the selected RadioButton.
+     *  If no RadioButton is selected, this property is <code>null</code>.
+     *
+     *  <p>If you set <code>selectedValue</code>, Flex selects the
+     *  RadioButton control whose <code>value</code> or
+     *  <code>label</code> property matches this value.</p>
+     *
+     *  @default null
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function get selectedValue():Object
+    {
+        if (selection)
+        {
+            return selection.value != null ?
+                   selection.value :
+                   selection.label;
+        }
+
+        return null;
+    }
+
+    /**
+     *  @private.
+     */
+    public function set selectedValue(value:Object):void
+    {
+        _selectedValue = value;
+
+        // Clear the exisiting selecton if there is one.
+        if (value == null)
+        {
+            setSelection(null, false);
+            return;
+        }
+
+        // Find the radio button value specified.
+        var n:int = numRadioButtons;
+        for (var i:int = 0; i < n; i++)
+        {
+            var radioButton:RadioButton = getRadioButtonAt(i);
+            if (radioButton.value == value ||
+                radioButton.label == value)
+            {
+                changeSelection(i, false);
+                break;
+            }
+        }
+
+        dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
+    }
+
+    //----------------------------------
+    //  selection
+    //----------------------------------
+
+    /**
+     *  @private
+     *  Reference to the selected radio button.
+     */
+    private var _selection:RadioButton;
+
+    [Bindable("change")]
+    [Bindable("valueCommit")]
+    [Inspectable(category="General")]
+
+    /**
+     *  Contains a reference to the currently selected
+     *  RadioButton control in the group.
+     *  You can access the property in ActionScript only;
+     *  it is not settable in MXML.
+     *  Setting this property to <code>null</code> deselects the currently 
selected RadioButton control.
+     *
+     *  @default null
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function get selection():RadioButton
+    {
+        return _selection;
+    }
+
+    /**
+     *  @private
+     */
+    public function set selection(value:RadioButton):void
+    {
+        // Going through the selection setter should never fire a change event.
+        setSelection(value, false);
+    }
+
+    
//--------------------------------------------------------------------------
+    //
+    //  Methods
+    //
+    
//--------------------------------------------------------------------------
+
+
+    /**
+     *  Returns the RadioButton control at the specified index.
+     *
+     *  @param index The index of the RadioButton control in the
+     *  RadioButtonGroup control, where the index of the first control is 0.
+     *
+     *  @return The specified RadioButton control.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function getRadioButtonAt(index:int):RadioButton
+    {
+        return RadioButton(radioButtons[index]);
+    }
+
+    /**
+     *  @private
+     *  Add a radio button to the group.
+     */
+    mx_internal function addInstance(instance:RadioButton):void
+    {
+        instance.addEventListener(Event.REMOVED, radioButton_removedHandler);
+        radioButtons.push(instance);
+
+        // Apply group indices in "tab order" or "breadth-first" order.
+        radioButtons.sort(readOrderCompare);
+        for (var i:int = 0; i < radioButtons.length; i++)
+            radioButtons[i].indexNumber = i;
+
+        if (_selectedValue != null)
+            selectedValue = _selectedValue;
+
+               dispatchEvent(new Event("numRadioButtonsChanged"));
+    }
+
+    /**
+     *  @private
+     *  Remove a radio button from the group.
+     */
+    mx_internal function removeInstance(instance:RadioButton):void
+    {
+        if (instance)
+        {
+
+            var foundInstance:Boolean = false;
+            for (var i:int = 0; i < numRadioButtons; i++)
+            {
+                var rb:RadioButton = getRadioButtonAt(i);
+
+                if (foundInstance)
+                {
+                    // Decrement the indexNumber for each button after the 
removed button.
+                    rb.indexNumber--;
+                }
+                else if (rb == instance)
+                {
+                       rb.group = null;
+
+                    if (instance == _selection)
+                    {
+                        _selection = null;
+                    }
+                    // Remove the radio button from the internal array
+                    radioButtons.splice(i,1);
+                    foundInstance = true;
+                    // redo the same index because we removed the previous 
item at this index
+                    i--;
+                }
+            }
+
+            if (foundInstance)
+                               dispatchEvent(new 
Event("numRadioButtonsChanged"));
+        }
+    }
+
+    /**
+     *  @private
+     *  Return the value or the label value
+     *  of the selected radio button.
+     */
+    private function getValue():String
+    {
+        if (selection)
+        {
+            return selection.value &&
+                   selection.value is String &&
+                   String(selection.value).length != 0 ?
+                   String(selection.value) :
+                   selection.label;
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+    /**
+     *  @private
+     */
+    mx_internal function setSelection(value:RadioButton, fireChange:Boolean = 
true):void
+    {
+        if (value == null)
+        {
+            if (selection != null)
+            {
+                _selection.selected = false;
+                _selection = null;
+                if (fireChange)
+                    dispatchEvent(new Event(Event.CHANGE));
+            }
+        }
+        else
+        {
+            var n:int = numRadioButtons;
+            for (var i:int = 0; i < n; i++)
+            {
+                if (value == getRadioButtonAt(i))
+                {
+                    changeSelection(i, fireChange);
+                    break;
+                }
+            }
+        }
+
+        //dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
+    }
+
+    /**
+     *  @private
+     */
+    private function changeSelection(index:int, fireChange:Boolean = true):void
+    {
+        if (getRadioButtonAt(index))
+        {
+            // Unselect the currently selected radio
+            if (selection)
+                selection.selected = false;
+
+            // Change the focus to the new radio.
+            // Set the state of the new radio to true.
+            // Fire a click event for the new radio.
+            // Fire a click event for the radio group.
+            _selection = getRadioButtonAt(index);
+            _selection.selected = true;
+            if (fireChange)
+                dispatchEvent(new Event(Event.CHANGE));
+        }
+    }
+
+    
//--------------------------------------------------------------------------
+    //
+    //  Event Handlers
+    //
+    
//--------------------------------------------------------------------------
+     /**
+     *  @private
+     */
+    private function radioButton_removedHandler(event:Event):void
+    {
+        var rb:RadioButton = event.target as RadioButton;
+        if (rb)
+        {
+               rb.removeEventListener(Event.REMOVED, 
radioButton_removedHandler);
+            removeInstance(RadioButton(event.target));
+        }
+    }
+}
+
+}

-- 
To stop receiving notification emails like this one, please contact
p...@apache.org.

Reply via email to