This is an automated email from the ASF dual-hosted git repository. aharui pushed a commit to branch feature/MXRoyale in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 9f46e48e3afbb2217d28afd5e6c3b813a5c39065 Author: Alex Harui <[email protected]> AuthorDate: Mon Apr 2 10:26:45 2018 -0700 mx radiobutton passes checkintests --- .../MXRoyale/src/main/resources/defaults.css | 6 + .../src/main/royale/mx/controls/RadioButton.as | 139 ++++++++++++++- .../main/royale/mx/controls/RadioButtonGroup.as | 191 +++++++++++---------- 3 files changed, 233 insertions(+), 103 deletions(-) diff --git a/frameworks/projects/MXRoyale/src/main/resources/defaults.css b/frameworks/projects/MXRoyale/src/main/resources/defaults.css index 0c25129..8679c05 100644 --- a/frameworks/projects/MXRoyale/src/main/resources/defaults.css +++ b/frameworks/projects/MXRoyale/src/main/resources/defaults.css @@ -106,6 +106,12 @@ NumericStepper iMeasurementBead: ClassReference("org.apache.royale.html.beads.TextFieldLabelMeasurementBead"); } + RadioButton + { + IBeadModel: ClassReference("org.apache.royale.html.beads.models.ValueToggleButtonModel"); + IBeadView: ClassReference("mx.controls.beads.RadioButtonView"); + } + TextInput { IBeadModel: ClassReference("org.apache.royale.html.beads.models.TextModel"); diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButton.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButton.as index 57e7ec0..5d052fa 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButton.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButton.as @@ -22,6 +22,10 @@ package mx.controls COMPILE::JS { import goog.DEBUG; + import window.Text; + import org.apache.royale.core.WrappedHTMLElement; + import org.apache.royale.html.supportClasses.RadioButtonIcon; + import org.apache.royale.html.util.addElementToWrapper; } import org.apache.royale.events.Event; /* @@ -31,8 +35,8 @@ import flash.events.MouseEvent; import flash.ui.Keyboard; import mx.core.IFlexDisplayObject; import mx.core.IFlexModuleFactory; -import mx.core.mx_internal; */ +import mx.core.mx_internal; import mx.events.FlexEvent; /* import mx.core.FlexVersion; @@ -46,8 +50,8 @@ import mx.styles.StyleManager; import flash.text.TextLineMetrics; import flash.utils.getQualifiedClassName; -use namespace mx_internal; */ +use namespace mx_internal; /** * The RadioButton control lets the user make a single choice @@ -208,6 +212,91 @@ public class RadioButton extends Button { } + /** + * @private + * + * @royalesuppresspublicvarwarning + */ + COMPILE::JS + public static var radioCounter:int = 0; + + COMPILE::JS + private var labelFor:HTMLLabelElement; + COMPILE::JS + private var textNode:window.Text; + COMPILE::JS + private var rbicon:RadioButtonIcon; + + /** + * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement + * @royaleignorecoercion HTMLInputElement + * @royaleignorecoercion HTMLLabelElement + * @royaleignorecoercion Text + */ + COMPILE::JS + override protected function createElement():WrappedHTMLElement + { + rbicon = new RadioButtonIcon() + rbicon.id = '_radio_' + RadioButton.radioCounter++; + rbicon.element.addEventListener("change", rbChangeHandler); + + textNode = document.createTextNode('') as window.Text; + + labelFor = addElementToWrapper(this,'label') as HTMLLabelElement; + labelFor.appendChild(rbicon.element); + labelFor.appendChild(textNode); + + (textNode as WrappedHTMLElement).royale_wrapper = this; + (rbicon.element as WrappedHTMLElement).royale_wrapper = this; + + typeNames = 'RadioButton'; + + return element; + } + + /** + * @royaleignorecoercion HTMLInputElement + */ + COMPILE::JS + private function rbChangeHandler(event:Event):void + { + selected = (rbicon.element as HTMLInputElement).checked + } + + COMPILE::JS + override public function set id(value:String):void + { + super.id = value; + labelFor.id = value; + rbicon.element.id = value; + } + + COMPILE::JS + override public function get label():String + { + return textNode.nodeValue as String; + } + + COMPILE::JS + override public function set label(value:String):void + { + textNode.nodeValue = value; + } + + /** + * @royaleignorecoercion HTMLInputElement + */ + override public function set selected(value:Boolean):void + { + super.selected = value; + COMPILE::JS + { + (rbicon.element as HTMLInputElement).checked = value; + } + group.setSelection(this, false); + dispatchEvent(new Event("selectedChanged")); + } + //-------------------------------------------------------------------------- // // Properties @@ -236,6 +325,10 @@ public class RadioButton extends Button */ public function get group():RadioButtonGroup { + if (_group == null) + { + _group = component[groupName]; + } return _group; } @@ -290,8 +383,16 @@ public class RadioButton extends Button { _groupName = value; + groupChanged = true; + + COMPILE::JS + { + (rbicon.element as HTMLInputElement).name = value; + } + dispatchEvent(new Event("groupNameChanged")); } + //---------------------------------- // value @@ -328,6 +429,10 @@ public class RadioButton extends Button public function set value(value:Object):void { _value = value; + COMPILE::JS + { + (rbicon.element as HTMLInputElement).value = "" + value; + } } @@ -337,6 +442,11 @@ public class RadioButton extends Button // //-------------------------------------------------------------------------- + override public function addedToParent():void + { + super.addedToParent(); + commitProperties(); + } /** * @private @@ -345,6 +455,13 @@ public class RadioButton extends Button override protected function commitProperties():void { super.commitProperties(); + + if (groupChanged) + { + addToGroup(); + + groupChanged = false; + } } //-------------------------------------------------------------------------- @@ -353,12 +470,18 @@ public class RadioButton extends Button // //-------------------------------------------------------------------------- - //-------------------------------------------------------------------------- - // - // Overridden event handlers: UIComponent - // - //-------------------------------------------------------------------------- - + /** + * @private + * Create radio button group if it does not exist + * and add the instance to the group. + */ + private function addToGroup():Object + { + var g:RadioButtonGroup = group; // Trigger getting the group + if (g) + g.addInstance(this); + return g; + } } diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButtonGroup.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButtonGroup.as index 4a59ef7..bc9204e 100644 --- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButtonGroup.as +++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/RadioButtonGroup.as @@ -38,14 +38,10 @@ 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 @@ -299,8 +295,7 @@ public class RadioButtonGroup extends EventDispatcher */ public function get numRadioButtons():int { -// return radioButtons.length; - return 0; + return radioButtons.length; } //---------------------------------- @@ -338,12 +333,12 @@ public class RadioButtonGroup extends EventDispatcher */ public function get selectedValue():Object { -// if (selection) -// { -// return selection.value != null ? -// selection.value : -// selection.label; -// } + if (selection) + { + return selection.value != null ? + selection.value : + selection.label; + } return null; } @@ -353,28 +348,28 @@ public class RadioButtonGroup extends EventDispatcher */ 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; -// } -// } -// + _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)); } @@ -449,19 +444,19 @@ public class RadioButtonGroup extends EventDispatcher * @private * Add a radio button to the group. */ - protected function addInstance(instance:RadioButton):void + 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; -// + //instance.addEventListener(Event.REMOVED, radioButton_removedHandler); + radioButtons.push(instance); + + // Apply group indices in "tab order" or "breadth-first" order. + // TODO (aharui) later: radioButtons.sort(readOrderCompare); + //for (var i:int = 0; i < radioButtons.length; i++) + // RadioButton(radioButtons[i]).indexNumber = i; + + if (_selectedValue != null) + selectedValue = _selectedValue; + // dispatchEvent(new Event("numRadioButtonsChanged")); } @@ -469,8 +464,8 @@ public class RadioButtonGroup extends EventDispatcher * @private * Remove a radio button from the group. */ - protected function removeInstance(instance:RadioButton):void - { +// protected function removeInstance(instance:RadioButton):void +// { // if (instance) // { // @@ -503,15 +498,15 @@ public class RadioButtonGroup extends EventDispatcher // if (foundInstance) // dispatchEvent(new Event("numRadioButtonsChanged")); // } - } +// } /** * @private * Return the value or the label value * of the selected radio button. */ - private function getValue():String - { +// private function getValue():String +// { // if (selection) // { // return selection.value && @@ -524,37 +519,43 @@ public class RadioButtonGroup extends EventDispatcher // { // return null; // } - return null; - } +// return null; +// } + private var inSetSelection:Boolean; + /** * @private */ - protected function setSelection(value:RadioButton, fireChange:Boolean = true):void + 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; -// } -// } -// } -// + if (inSetSelection) return; + + 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)) + { + inSetSelection = true; + changeSelection(i, fireChange); + inSetSelection = false; + break; + } + } + } + // dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT)); } @@ -563,21 +564,21 @@ public class RadioButtonGroup extends EventDispatcher */ 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)); -// } + 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)); + } } //-------------------------------------------------------------------------- @@ -588,15 +589,15 @@ public class RadioButtonGroup extends EventDispatcher /** * @private */ - private function radioButton_removedHandler(event:Event):void - { +// 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 [email protected].
