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

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

commit dbe59ec1a4e30f16bdfc0add894d3dab6b7e6f19
Author: Yishay Weiss <[email protected]>
AuthorDate: Wed Jun 16 11:03:55 2021 +0300

    Beginning of infra for refactoring mx buttonbar
    
    Reference #116
---
 .../src/main/resources/mx-royale-manifest.xml      |   2 +
 .../royale/mx/containers/beads/ButtonBarLayout.as  |  50 ++++++++
 .../royale/mx/supportClasses/ButtonItemRenderer.as | 132 +++++++++++++++++++++
 3 files changed, 184 insertions(+)

diff --git 
a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml 
b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
index a7b3ef2..8732f23 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
+++ b/frameworks/projects/MXRoyale/src/main/resources/mx-royale-manifest.xml
@@ -57,6 +57,7 @@
        <component id="ApplicationLayout" 
class="mx.containers.beads.ApplicationLayout" />
        <component id="BasicLayout" 
class="mx.containers.beads.layouts.BasicLayout" />
        <component id="BoxLayout" class="mx.containers.beads.BoxLayout" />
+       <component id="ButtonBarLayout" 
class="mx.containers.beads.ButtonBarLayout" />
        <component id="CanvasLayout" class="mx.containers.beads.CanvasLayout" />
        <component id="TitleWindow" class="mx.containers.TitleWindow"/>
     <component id="PopUpButton" class="mx.controls.PopUpButton"/>
@@ -78,6 +79,7 @@
        <component id="State" class="mx.states.State" />
     <component id="Transition" class="mx.states.Transition" />
        <component id="ListItemRenderer" 
class="mx.controls.listClasses.ListItemRenderer" />
+       <component id="ButtonItemRenderer" 
class="mx.supportClasses.ButtonItemRenderer" />
        <component id="ArrayList" class="mx.collections.ArrayList"/>
        <component id="UIComponent" class="mx.core.UIComponent"/>
        <component id="Container" class="mx.core.Container"/>
diff --git 
a/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/ButtonBarLayout.as
 
b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/ButtonBarLayout.as
new file mode 100644
index 0000000..40b867a
--- /dev/null
+++ 
b/frameworks/projects/MXRoyale/src/main/royale/mx/containers/beads/ButtonBarLayout.as
@@ -0,0 +1,50 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.containers.beads
+{
+       
+       import mx.containers.BoxDirection;
+       
+       [ExcludeClass]
+       
+       /**
+        *  @private
+        *  The ButtonBarLayout class is for internal use only.
+        */
+       public class ButtonBarLayout extends BoxLayout
+       {               
+               /**
+                *  @private
+                */
+               private var _direction:String = BoxDirection.HORIZONTAL;
+               
+               override public function get direction():String
+               {
+                       return _direction;
+               }
+               
+               override public function set direction(value:String):void
+               {
+                       _direction = value;
+               }
+               
+       }
+       
+}
diff --git 
a/frameworks/projects/MXRoyale/src/main/royale/mx/supportClasses/ButtonItemRenderer.as
 
b/frameworks/projects/MXRoyale/src/main/royale/mx/supportClasses/ButtonItemRenderer.as
new file mode 100644
index 0000000..70e2405
--- /dev/null
+++ 
b/frameworks/projects/MXRoyale/src/main/royale/mx/supportClasses/ButtonItemRenderer.as
@@ -0,0 +1,132 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.supportClasses
+{
+       import org.apache.royale.core.IItemRenderer;
+       import org.apache.royale.core.IItemRendererOwnerView;
+       import org.apache.royale.core.UIBase;
+       import org.apache.royale.core.SimpleCSSStylesWithFlex;
+       import org.apache.royale.events.Event;
+       import org.apache.royale.events.MouseEvent;
+       import org.apache.royale.html.beads.ITextItemRenderer;
+       import org.apache.royale.events.ItemClickedEvent;
+       import org.apache.royale.html.util.getLabelFromData;
+       import mx.controls.Button;
+
+       COMPILE::JS
+       {
+               import org.apache.royale.core.WrappedHTMLElement;
+       }
+
+       /**
+        * The ButtonItemRenderer class extends Button and turns it into an 
itemRenderer
+        * suitable for use in most DataContainer/List/DataGrid applications.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.8
+        */
+       public class ButtonItemRenderer extends Button implements 
ITextItemRenderer
+       {
+               public function ButtonItemRenderer()
+               {
+                       super();
+
+                       addEventListener('click',handleClickEvent);
+               }
+
+               /**
+                * @royaleignorecoercion String
+                */
+               protected function updateButtonLabelFromData():void
+               {
+                       var valueAsString:String;
+
+                       if (data == null) return;
+                       valueAsString = getLabelFromData(this,data);
+                       if (!valueAsString && data.hasOwnProperty("title")) {
+                               valueAsString = "" + data["title"];
+                       }
+
+                       if (valueAsString) text = valueAsString;
+               }
+
+               /**
+                * @private
+                */
+               public function set text(value:String):void
+               {
+                       label = value;
+               }
+
+               /**
+                * @private
+                */
+               public function get text():String
+               {
+                       return label;
+               }
+
+
+               /**
+                * @private
+                */
+               protected function handleClickEvent(event:MouseEvent):void
+               {
+                       var newEvent:ItemClickedEvent = new 
ItemClickedEvent("itemClicked");
+                       newEvent.index = index;
+                       newEvent.data = data;
+                       dispatchEvent(newEvent);
+               }
+
+               /*
+                * IItemRenderer, ISelectableItemRenderer
+                */
+
+               private var _labelField:String = null;
+
+               /**
+                * The name of the field within the data to use as a label. 
Some itemRenderers use this field to
+                * identify the value they should show while other 
itemRenderers ignore this if they are showing
+                * complex information.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.8
+                */
+               public function get labelField():String
+               {
+                       return _labelField;
+               }
+
+               public function set labelField(value:String):void
+               {
+                       _labelField = value;
+                       updateButtonLabelFromData();
+               }
+
+               override public function set data(value:Object):void
+               {
+                       super.data = value;
+                       updateButtonLabelFromData();
+               }
+       }
+}

Reply via email to