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 b765925c4d3844ca3f377f2a30f6ecc42c738108
Author: Alex Harui <[email protected]>
AuthorDate: Wed Mar 28 00:16:44 2018 -0700

    checkbox test passes on SWF
---
 .../MXRoyale/src/main/resources/defaults.css       |   2 +-
 .../MXRoyale/src/main/royale/MXRoyaleClasses.as    |   1 +
 .../MXRoyale/src/main/royale/mx/controls/Button.as |   5 +-
 .../main/royale/mx/controls/beads/CheckBoxView.as  | 311 +++++++++++++++++++++
 4 files changed, 316 insertions(+), 3 deletions(-)

diff --git a/frameworks/projects/MXRoyale/src/main/resources/defaults.css 
b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
index c2cd331..a7d26e9 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/defaults.css
+++ b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
@@ -78,7 +78,7 @@ Image
        
        CheckBox
        {
-               IBeadView:  
ClassReference("org.apache.royale.html.beads.CheckBoxView");                    
    
+               IBeadView:  ClassReference("mx.controls.beads.CheckBoxView");   
                
        }
        
        Container
diff --git a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as 
b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
index 2e2bd4f..d27891f 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
@@ -37,6 +37,7 @@ internal class MXRoyaleClasses
     COMPILE::SWF
     {
         import mx.controls.beads.CSSImageAndTextButtonView; 
CSSImageAndTextButtonView;
+        import mx.controls.beads.CheckBoxView; CheckBoxView;
     }
 }
 
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 d8bacec..491f975 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/Button.as
@@ -31,6 +31,7 @@ import mx.core.IDataRenderer;
 import mx.core.UIComponent;
 import mx.events.FlexEvent;
 
+import org.apache.royale.core.ITextModel;
 import org.apache.royale.events.Event;
 import org.apache.royale.html.accessories.ToolTipBead;
 import org.apache.royale.html.beads.models.ImageAndTextModel;
@@ -287,7 +288,7 @@ public class Button extends UIComponent implements 
IDataRenderer
        
        public function get label():String
        {
-               return ImageAndTextModel(model).text;
+               return ITextModel(model).text;
        }
        
        /**
@@ -295,7 +296,7 @@ public class Button extends UIComponent implements 
IDataRenderer
         */
        public function set label(value:String):void
        {
-               ImageAndTextModel(model).text = value;
+               ITextModel(model).text = value;
                COMPILE::JS {
                        setInnerHTML();
                }
diff --git 
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/CheckBoxView.as
 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/CheckBoxView.as
new file mode 100644
index 0000000..227cb36
--- /dev/null
+++ 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/CheckBoxView.as
@@ -0,0 +1,311 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.beads
+{
+       import flash.display.Shape;
+       import flash.display.SimpleButton;
+       import flash.display.Sprite;
+       import flash.text.TextFieldAutoSize;
+       import flash.text.TextFieldType;
+       
+    import org.apache.royale.core.BeadViewBase;
+       import org.apache.royale.core.CSSTextField;
+       import org.apache.royale.core.IBeadView;
+       import org.apache.royale.core.IStrand;
+       import org.apache.royale.core.IToggleButtonModel;
+    import org.apache.royale.core.UIBase;
+       import org.apache.royale.events.Event;
+       
+    /**
+     *  The CheckBoxView class is the default view for
+     *  the org.apache.royale.html.CheckBox class.
+     *  It displays a simple checkbox with an 'x' if checked,
+     *  and a label on the right.  There are no styles or
+     *  properties to configure the look of the 'x' or the
+     *  position of the label relative to the checkbox as
+     *  there are no equivalents in the standard HTML checkbox.
+     * 
+     *  A more complex CheckBox could implement more view
+     *  configuration.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion Royale 0.0
+     */
+       public class CheckBoxView extends BeadViewBase implements IBeadView
+       {
+        /**
+         *  Constructor.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+               public function CheckBoxView()
+               {
+                       sprites = [ upSprite = new Sprite(),
+                                       downSprite = new Sprite(),
+                                               overSprite = new Sprite(),
+                                               upAndSelectedSprite = new 
Sprite(),
+                                               downAndSelectedSprite = new 
Sprite(),
+                                               overAndSelectedSprite = new 
Sprite() ];
+                       
+                       for each( var s:Sprite in sprites )
+                       {
+                               var tf:CSSTextField = new CSSTextField();
+                               tf.type = TextFieldType.DYNAMIC;
+                               tf.autoSize = TextFieldAutoSize.LEFT;
+                               tf.name = "textField";
+                               var icon:Shape = new Shape();
+                               icon.name = "icon";
+                               s.addChild(icon);
+                               s.addChild(tf);
+                       }
+               }
+               
+               private var upSprite:Sprite;
+               private var downSprite:Sprite;
+               private var overSprite:Sprite;
+               private var upAndSelectedSprite:Sprite;
+               private var downAndSelectedSprite:Sprite;
+               private var overAndSelectedSprite:Sprite;
+               
+               private var sprites:Array;
+               
+               private var _toggleButtonModel:IToggleButtonModel;
+
+        // TODO: Can we remove this?
+               private function get toggleButtonModel() : IToggleButtonModel
+               {
+                       return _toggleButtonModel;
+               }
+               
+        /**
+         *  @copy org.apache.royale.core.IBead#strand
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+               override public function set strand(value:IStrand):void
+               {
+                       super.strand = value;
+            
+                       _toggleButtonModel = 
value.getBeadByType(IToggleButtonModel) as IToggleButtonModel;
+                       _toggleButtonModel.addEventListener("textChange", 
textChangeHandler);
+                       _toggleButtonModel.addEventListener("htmlChange", 
htmlChangeHandler);
+                       _toggleButtonModel.addEventListener("selectedChange", 
selectedChangeHandler);
+                       if (_toggleButtonModel.text !== null)
+                               text = _toggleButtonModel.text;
+            for each( var s:Sprite in sprites )
+            {
+                var tf:CSSTextField = s.getChildByName("textField") as 
CSSTextField;
+                tf.styleParent = value;
+            }
+            
+                       layoutControl();
+                       
+                       var hitArea:Shape = new Shape();
+                       hitArea.graphics.beginFill(0x000000);
+                       hitArea.graphics.drawRect(0,0,upSprite.width, 
upSprite.height);
+                       hitArea.graphics.endFill();
+                       
+            UIBase(value).$addChild(upSprite);
+            /* TODO switch sprites on mouse state 
+                       SimpleButton(value).downState = downSprite;
+                       SimpleButton(value).overState = overSprite;
+                       SimpleButton(value).hitTestState = hitArea;
+                       */
+            
+                       if (toggleButtonModel.text !== null)
+                               text = toggleButtonModel.text;
+                       if (toggleButtonModel.html !== null)
+                               html = toggleButtonModel.html;
+               }
+               
+        /**
+         *  @copy org.apache.royale.html.Label#text
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+               public function get text():String
+               {
+                       var tf:CSSTextField = 
upSprite.getChildByName('textField') as CSSTextField;
+                       return tf.text;
+               }
+               
+        /**
+         *  @private
+         */
+               public function set text(value:String):void
+               {
+                       for each( var s:Sprite in sprites )
+                       {
+                               var tf:CSSTextField = 
s.getChildByName('textField') as CSSTextField;
+                               tf.text = value;
+                       }
+                       
+                       layoutControl();
+               }
+               
+        /**
+         *  @copy org.apache.royale.html.Label#html
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+               public function get html():String
+               {
+                       var tf:CSSTextField = 
upSprite.getChildByName('textField') as CSSTextField;
+                       return tf.htmlText;
+               }
+               
+        /**
+         *  @private
+         */
+               public function set html(value:String):void
+               {
+                       for each(var s:Sprite in sprites)
+                       {
+                               var tf:CSSTextField = 
s.getChildByName('textField') as CSSTextField;
+                               tf.htmlText = value;
+                       }
+                       
+                       layoutControl();
+               }
+               
+               private function textChangeHandler(event:Event):void
+               {
+                       text = toggleButtonModel.text;
+               }
+               
+               private function htmlChangeHandler(event:Event):void
+               {
+                       html = toggleButtonModel.html;
+               }
+               
+               private var _selected:Boolean;
+               
+        /**
+         *  @copy org.apache.royale.core.IToggleButtonModel#selected
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+               public function get selected():Boolean
+               {
+                       return _selected;
+               }
+               
+        /**
+         *  @private
+         */
+               public function set selected(value:Boolean):void
+               {
+                       _selected = value;
+                       
+                       layoutControl();
+                       
+                       if( value ) {
+                UIBase(_strand).$addChild(upAndSelectedSprite);
+                upAndSelectedSprite.visible = true;
+                upSprite.visible = false;
+                /* TODO switch sprites on mouse state 
+                               SimpleButton(_strand).downState = 
downAndSelectedSprite;
+                               SimpleButton(_strand).overState = 
overAndSelectedSprite;
+                               */
+                       } else {
+                UIBase(_strand).$addChild(upSprite);
+                upAndSelectedSprite.visible = false;
+                upSprite.visible = true;
+                /* TODO switch sprites on mouse state 
+                               SimpleButton(_strand).downState = downSprite;
+                               SimpleButton(_strand).overState = overSprite;
+                */
+                       }
+               }
+               
+               private function selectedChangeHandler(event:Event):void
+               {
+                       selected = toggleButtonModel.selected;
+               }
+               
+        /**
+         *  Display the icon and text label
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+               protected function layoutControl() : void
+               {
+                       for each(var s:Sprite in sprites)
+                       {
+                               var icon:Shape = s.getChildByName("icon") as 
Shape;
+                               var tf:CSSTextField = 
s.getChildByName("textField") as CSSTextField;
+                               
+                               drawCheckBox(icon);
+                               
+                               var mh:Number = Math.max(icon.height,tf.height);
+                               
+                               icon.x = 0;
+                               icon.y = (mh - icon.height)/2;
+                               
+                               tf.x = icon.x + icon.width + 1;
+                               tf.y = (mh - tf.height)/2;
+                       }
+                       
+               }
+               
+        /**
+         *  Draw the checkbox
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+               protected function drawCheckBox(icon:Shape) : void
+               {
+                       icon.graphics.clear();
+                       icon.graphics.beginFill(0xf8f8f8);
+                       icon.graphics.lineStyle(1,0x808080);
+                       icon.graphics.drawRect(0,0,10,10);
+                       icon.graphics.endFill();
+                       
+                       if( _toggleButtonModel.selected ) {
+                icon.graphics.lineStyle(2,0);
+                               icon.graphics.moveTo(3,4);
+                               icon.graphics.lineTo(5,7);
+                               icon.graphics.lineTo(9,0);
+                       }
+               }
+       }
+}

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to