You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2018/11/28 07:20:06 UTC

[royale-asjs] branch develop updated: Spark Checkbox and RadioButton

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 81b86c5  Spark Checkbox and RadioButton
81b86c5 is described below

commit 81b86c5b3c2f20839049576cbddbdad4644c8d94
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Nov 27 23:19:20 2018 -0800

    Spark Checkbox and RadioButton
---
 .../src/main/royale/spark/components/CheckBox.as   |  69 +++++++++++++
 .../src/main/royale/spark/components/Label.as      |   2 +-
 .../main/royale/spark/components/RadioButton.as    | 109 ++++++++++++++++++++-
 .../royale/spark/components/RadioButtonGroup.as    |  35 ++++---
 4 files changed, 193 insertions(+), 22 deletions(-)

diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/CheckBox.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/CheckBox.as
index 17e2d31..3d11ffa 100644
--- a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/CheckBox.as
+++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/CheckBox.as
@@ -28,6 +28,14 @@ import org.apache.royale.events.MouseEvent;
 import mx.core.mx_internal;
 
 import spark.components.supportClasses.ToggleButtonBase;
+COMPILE::JS
+{
+    
+    import org.apache.royale.core.UIBase;
+    import org.apache.royale.core.WrappedHTMLElement;
+    import org.apache.royale.html.supportClasses.CheckBoxIcon;
+    import org.apache.royale.html.util.addElementToWrapper;
+}
 
 use namespace mx_internal;
 
@@ -313,6 +321,67 @@ public class CheckBox extends ToggleButtonBase
             CheckBox.createAccessibilityImplementation(this);
     } */
 
+    COMPILE::JS
+    private var _label:WrappedHTMLElement;
+    COMPILE::JS
+    private var _icon:CheckBoxIcon;
+    
+    COMPILE::JS
+    private static var _checkNumber:Number = 0;
+    
+    /**
+     * @royaleignorecoercion org.apache.royale.core.WrappedHTMLElement
+     */
+    COMPILE::JS
+    override protected function createElement():WrappedHTMLElement
+    {
+        var cb:HTMLInputElement;
+        addElementToWrapper(this,'label');
+        _label = element;
+        _icon = new CheckBoxIcon();
+        element.appendChild(_icon.element);
+        
+        element.appendChild(document.createTextNode(''));
+        //positioner.style.position = 'relative';
+        _icon.element.royale_wrapper = this;
+        
+        typeNames = 'CheckBox CheckBoxIcon';
+        
+        return element;
+    }
+    
+    COMPILE::JS
+    override public function get label():String
+    {
+        return _label.childNodes.item(1).nodeValue;
+    }
+    
+    COMPILE::JS
+    override public function set label(value:String):void
+    {
+        _label.childNodes.item(1).nodeValue = value;
+    }
+    
+    [Bindable("change")]
+    COMPILE::JS
+    override public function get selected():Boolean
+    {
+        return (_icon.element as HTMLInputElement).checked;
+    }
+    
+    COMPILE::JS
+    override public function set selected(value:Boolean):void
+    {
+        (_icon.element as HTMLInputElement).checked = value;
+    }
+    
+    COMPILE::JS
+    override public function get measuredWidth():Number
+    {
+        var mw:Number = super.measuredWidth;
+        return mw + 1; // factor in gap between icon and label?
+    }
+
 }
 
 }
diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/Label.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/Label.as
index 4cfcaac..cf07f26 100644
--- a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/Label.as
+++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/Label.as
@@ -1698,7 +1698,7 @@ public class Label extends TextBase
         element.style.whiteSpace = "nowrap";
         var mw:Number = super.measuredWidth;
         element.style.whiteSpace = oldValue;
-        return mw;
+        return mw + 1;
     }
     
     COMPILE::JS
diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/RadioButton.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/RadioButton.as
index 3e801f2..7ec51bc 100644
--- a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/RadioButton.as
+++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/RadioButton.as
@@ -25,13 +25,24 @@ import flash.events.KeyboardEvent;
 import flash.events.MouseEvent;
 import flash.ui.Keyboard;
  */
-import spark.components.supportClasses.ToggleButtonBase;
 import mx.core.IFlexDisplayObject;
 import mx.core.UIComponent;
 import mx.core.mx_internal;
 import mx.events.FlexEvent;
-//import mx.events.ItemClickEvent;
 import mx.managers.IFocusManager;
+
+import spark.components.supportClasses.ToggleButtonBase;
+
+import org.apache.royale.events.Event;
+
+COMPILE::JS
+{
+    import window.Text;
+    import org.apache.royale.core.WrappedHTMLElement;
+    import org.apache.royale.html.supportClasses.RadioButtonIcon;
+    import org.apache.royale.html.util.addElementToWrapper;
+}
+
 //import mx.managers.IFocusManagerGroup;
 
 use namespace mx_internal;
@@ -195,6 +206,98 @@ public class RadioButton extends ToggleButtonBase
         // either explicitly or implicitly.
         groupName = "radioGroup";
     }
+    
+    /**
+     * @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"));
+    }    
+
+    COMPILE::JS
+    override public function get measuredWidth():Number
+    {
+        var mw:Number = super.measuredWidth;
+        return mw + 1; // factor in gap between icon and label?
+    }
          
     //--------------------------------------------------------------------------
     //
@@ -460,12 +563,12 @@ public class RadioButton extends ToggleButtonBase
     
     /**
      *  @private
-     */
     override public function set selected(value:Boolean):void
     {
         super.selected = value;
         invalidateDisplayList();
     }
+     */
 
     //----------------------------------
     //  value
diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/RadioButtonGroup.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/RadioButtonGroup.as
index 566a5e6..5b2507a 100644
--- a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/RadioButtonGroup.as
+++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/RadioButtonGroup.as
@@ -291,7 +291,7 @@ public class RadioButtonGroup extends EventDispatcher
     /**
     *  @private
     */
-    //private var _selectedIndex:int = -1;
+    private var _selectedIndex:int = -1;
 
     //[Bindable("change")]
     //[Bindable("valueCommit")]
@@ -308,15 +308,15 @@ public class RadioButtonGroup extends EventDispatcher
     *  @playerversion AIR 3.4
     *  @productversion Royale 0.9.4
     */
-    /* public function get selectedIndex():int
+    public function get selectedIndex():int
     {
         return _selectedIndex;
-    } */
+    }
 
     /**
     *  @private.
     */
-    /* public function set selectedIndex(newValue:int):void
+    public function set selectedIndex(newValue:int):void
     {
         if (newValue == _selectedIndex)
         {
@@ -334,7 +334,7 @@ public class RadioButtonGroup extends EventDispatcher
         changeSelection(newValue, false)
 
         dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
-    } */
+    }
 
 
     //----------------------------------
@@ -370,12 +370,12 @@ public class RadioButtonGroup extends EventDispatcher
      */
     public function get selectedValue():Object
     {
-        /* if (selection)
+        if (selection)
         {
             return selection.value != null ?
                    selection.value :
                    selection.label;
-        } */
+        }
 
         return null;
     }
@@ -391,7 +391,7 @@ public class RadioButtonGroup extends EventDispatcher
         _selectedValue = value;
         
         // Clear the exisiting selecton if there is one.
-        /* if (value == null)
+        if (value == null)
         {
             setSelection(null, false);
             return;
@@ -412,7 +412,7 @@ public class RadioButtonGroup extends EventDispatcher
 
                 break;
             }
-        } */
+        }
     }
 
     //----------------------------------
@@ -423,7 +423,7 @@ public class RadioButtonGroup extends EventDispatcher
      *  @private
      *  Reference to the selected radio button.
      */
-     private var _selection:Object;//RadioButton;
+     private var _selection:RadioButton;
 
     [Bindable("change")]
     [Bindable("valueCommit")]
@@ -444,7 +444,7 @@ public class RadioButtonGroup extends EventDispatcher
      *  @playerversion AIR 1.5
      *  @productversion Royale 0.9.4
      */
-    public function get selection():Object//RadioButton
+    public function get selection():RadioButton
     {
         return _selection;
     } 
@@ -452,14 +452,13 @@ public class RadioButtonGroup extends EventDispatcher
     /**
      *  @private
      */
-	//public function set selection(value:RadioButton):void
-    public function set selection(value:Object):void
+	public function set selection(value:RadioButton):void
     {
         if ( _selection == value)
             return;
         
         // Going through the selection setter should never fire a change event.
-       // setSelection(value, false);
+        setSelection(value, false);
     } 
 
     //--------------------------------------------------------------------------
@@ -619,7 +618,7 @@ public class RadioButtonGroup extends EventDispatcher
     /**
      *  @private
      */
-    /* mx_internal function setSelection(value:RadioButton, fireChange:Boolean = true):void
+    mx_internal function setSelection(value:RadioButton, fireChange:Boolean = true):void
     {
         if (_selection == value)
             return;
@@ -650,11 +649,11 @@ public class RadioButtonGroup extends EventDispatcher
 
         dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
     }
-    */
+    
     /**
      *  @private
      */
-    /* private function changeSelection(index:int, fireChange:Boolean = true):void
+    private function changeSelection(index:int, fireChange:Boolean = true):void
     {
         var rb:RadioButton = getRadioButtonAt(index);
         if (rb && rb != _selection)
@@ -673,7 +672,7 @@ public class RadioButtonGroup extends EventDispatcher
             if (fireChange)
                 dispatchEvent(new Event(Event.CHANGE));
         }
-    } */
+    }
 
     /**
      *  @private