You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by yi...@apache.org on 2019/08/12 07:14:11 UTC
[royale-asjs] 01/03: Added controller to mx radio button.
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 41ee718a2d1f59378e1edc7867a92893b42157f3
Author: DESKTOP-RH4S838\Yishay <yi...@hotmail.com>
AuthorDate: Sun Aug 11 15:01:05 2019 +0300
Added controller to mx radio button.
Reference #443
---
.../MXRoyale/src/main/resources/defaults.css | 6 ++
.../MXRoyale/src/main/royale/MXRoyaleClasses.as | 1 +
.../controllers/RadioButtonMouseController.as | 78 ++++++++++++++++++++++
3 files changed, 85 insertions(+)
diff --git a/frameworks/projects/MXRoyale/src/main/resources/defaults.css b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
index 6c51083..df73449 100644
--- a/frameworks/projects/MXRoyale/src/main/resources/defaults.css
+++ b/frameworks/projects/MXRoyale/src/main/resources/defaults.css
@@ -639,6 +639,11 @@ GridLines
verticalTickAligned: true;
}
+RadioButton
+{
+ IBeadController: ClassReference("mx.controls.beads.controllers.RadioButtonMouseController");
+}
+
.bothGridLines
{
gridDirection : "both";
@@ -778,6 +783,7 @@ charts|DataTip
{
IBeadModel: ClassReference("org.apache.royale.html.beads.models.ValueToggleButtonModel");
IBeadView: ClassReference("mx.controls.beads.RadioButtonView");
+ IBeadController: ClassReference("mx.controls.beads.controllers.RadioButtonMouseController");
}
TextArea
diff --git a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
index fab546e..2ae8d66 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/MXRoyaleClasses.as
@@ -220,6 +220,7 @@ internal class MXRoyaleClasses
import mx.controls.beads.CheckBoxView; CheckBoxView;
import mx.controls.beads.RadioButtonView; RadioButtonView;
}
+ import mx.controls.beads.controllers.RadioButtonMouseController; RadioButtonMouseController;
import mx.controls.beads.NumericStepperView; NumericStepperView;
import mx.controls.beads.DateFieldView; DateFieldView;
import mx.controls.dateFieldClasses.DateFieldDateChooser; DateFieldDateChooser;
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/controllers/RadioButtonMouseController.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/controllers/RadioButtonMouseController.as
new file mode 100644
index 0000000..0f7339e
--- /dev/null
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/controllers/RadioButtonMouseController.as
@@ -0,0 +1,78 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.controllers
+{
+
+import org.apache.royale.core.IStrand;
+import org.apache.royale.events.IEventDispatcher;
+import org.apache.royale.events.MouseEvent;
+import org.apache.royale.core.IBeadController;
+import mx.controls.RadioButton;
+import org.apache.royale.events.Event;
+import mx.events.ItemClickEvent;
+import mx.controls.RadioButtonGroup;
+
+/**
+ * The RadioButtonMouseController is the default controller for the radio button emulation class.
+ * It is responsible for creating the item click event
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+
+ public class RadioButtonMouseController implements IBeadController
+ {
+ public function set strand(value:IStrand):void
+ {
+ (value as IEventDispatcher).addEventListener(MouseEvent.CLICK, clickHandler);
+ }
+
+ protected function clickHandler(event:Event):void
+ {
+ // Dispatch an itemClick event from the RadioButtonGroup.
+ var radioButton:RadioButton = event.target as RadioButton;
+ var group:RadioButtonGroup = radioButton.group;
+ var itemClickEvent:ItemClickEvent =
+ new ItemClickEvent(ItemClickEvent.ITEM_CLICK);
+ itemClickEvent.label = radioButton.label;
+ // TODO is this worth the performance price?
+ itemClickEvent.index = getRadioIndex(radioButton, group);
+ itemClickEvent.relatedObject = radioButton;
+ itemClickEvent.item = radioButton.value;
+ group.dispatchEvent(itemClickEvent);
+ }
+
+ private function getRadioIndex(radioButton:RadioButton, group:RadioButtonGroup):int
+ {
+ for (var i:int = 0; i < group.numRadioButtons; i++)
+ {
+ if (group.getRadioButtonAt(i) == radioButton)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ }
+
+}