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/12/04 22:46:20 UTC
[royale-asjs] 03/03: Spark DropDownList
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
commit 56233b20ba864cb215e0273600fa97325c7434cb
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Dec 4 14:46:02 2018 -0800
Spark DropDownList
---
.../SparkRoyale/src/main/resources/defaults.css | 7 +
.../src/main/royale/SparkRoyaleClasses.as | 2 +
.../main/royale/spark/components/DropDownList.as | 31 ++++
.../spark/components/beads/DropDownListView.as | 176 +++++++++++++++++++++
.../beads/controllers/DropDownListController.as | 111 +++++++++++++
.../components/supportClasses/DropDownListBase.as | 21 +--
6 files changed, 339 insertions(+), 9 deletions(-)
diff --git a/frameworks/projects/SparkRoyale/src/main/resources/defaults.css b/frameworks/projects/SparkRoyale/src/main/resources/defaults.css
index ddde944..9e93095 100644
--- a/frameworks/projects/SparkRoyale/src/main/resources/defaults.css
+++ b/frameworks/projects/SparkRoyale/src/main/resources/defaults.css
@@ -78,6 +78,13 @@ DataGroup
IViewportModel: ClassReference("org.apache.royale.html.beads.models.ViewportModel");
}
+DropDownList
+{
+ IBeadModel: ClassReference("mx.controls.beads.models.SingleSelectionICollectionViewModel");
+ IBeadView: ClassReference("spark.components.beads.DropDownListView");
+ IBeadController: ClassReference("spark.components.beads.controllers.DropDownListController");
+}
+
List
{
IBeadView: ClassReference("spark.components.beads.SkinnableContainerView");
diff --git a/frameworks/projects/SparkRoyale/src/main/royale/SparkRoyaleClasses.as b/frameworks/projects/SparkRoyale/src/main/royale/SparkRoyaleClasses.as
index 4dc8cee..d9f4357 100644
--- a/frameworks/projects/SparkRoyale/src/main/royale/SparkRoyaleClasses.as
+++ b/frameworks/projects/SparkRoyale/src/main/royale/SparkRoyaleClasses.as
@@ -76,6 +76,8 @@ internal class SparkRoyaleClasses
import spark.components.beads.PanelView; PanelView;
import spark.components.beads.SkinnableContainerView; SkinnableContainerView;
+ import spark.components.beads.DropDownListView; DropDownListView;
+ import spark.components.beads.controllers.DropDownListController; DropDownListController;
}
diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/DropDownList.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/DropDownList.as
index ffea061..f17a8bd 100644
--- a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/DropDownList.as
+++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/DropDownList.as
@@ -32,6 +32,7 @@ import spark.utils.LabelUtil;
*/
import spark.components.supportClasses.DropDownListBase;
+ import spark.components.beads.DropDownListView;
//--------------------------------------
@@ -379,5 +380,35 @@ public class DropDownList extends DropDownListBase
labelDisplay.text = prompt;
}
} */
+
+ /**
+ * @private
+ * Because DropDown extends List which overrides numChildren to point to
+ * the DataGroup, the default measurement code will be incorrect
+ *
+ * @royaleignorecoercion spark.components.beads.DropDownListView
+ */
+ override public function get measuredWidth():Number
+ {
+ var mw:Number = super.measuredWidth;
+ if (mw == 0)
+ mw = (view as DropDownListView).label.measuredWidth;
+ return mw;
+ }
+
+ /**
+ * @private
+ * Because DropDown extends List which overrides numChildren to point to
+ * the DataGroup, the default measurement code will be incorrect
+ *
+ * @royaleignorecoercion spark.components.beads.DropDownListView
+ */
+ override public function get measuredHeight():Number
+ {
+ var mh:Number = super.measuredHeight;
+ if (mh == 0)
+ mh = (view as DropDownListView).label.measuredHeight;
+ return mh;
+ }
}
}
\ No newline at end of file
diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/DropDownListView.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/DropDownListView.as
new file mode 100644
index 0000000..b0a2ee1
--- /dev/null
+++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/DropDownListView.as
@@ -0,0 +1,176 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 spark.components.beads
+{
+
+import mx.core.IFlexDisplayObject;
+import mx.core.IUIComponent;
+import mx.managers.PopUpManager;
+
+import spark.components.Button;
+import spark.components.DropDownList;
+
+import org.apache.royale.core.IBead;
+import org.apache.royale.core.IChild;
+import org.apache.royale.core.IContainer;
+import org.apache.royale.core.ILayoutChild;
+import org.apache.royale.core.IPopUpHost;
+import org.apache.royale.core.ISelectionModel;
+import org.apache.royale.core.IStrand;
+import org.apache.royale.core.IStrandWithModel;
+import org.apache.royale.core.IUIBase;
+import org.apache.royale.events.Event;
+import org.apache.royale.html.beads.IDropDownListView;
+
+/**
+ * @private
+ * The SkinnableContainerView for emulation.
+ */
+public class DropDownListView extends SkinnableContainerView implements IDropDownListView
+{
+ //--------------------------------------------------------------------------
+ //
+ // Constructor
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * Constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Flex 3
+ */
+ public function DropDownListView()
+ {
+ super();
+ }
+
+ public var label:Button;
+
+ private var selectionModel:ISelectionModel;
+
+ /**
+ */
+ override public function set strand(value:IStrand):void
+ {
+ super.strand = value;
+
+ selectionModel = (value as IStrandWithModel).model as ISelectionModel;
+ selectionModel.addEventListener("selectedIndexChanged", selectionChangeHandler);
+ selectionModel.addEventListener("dataProviderChanged", selectionChangeHandler);
+
+ // remove the DataGroup. It will be the dropdown
+ var chost:IContainer = host as IContainer;
+ chost.strandChildren.removeElement(viewport.contentView);
+
+ label = new Button();
+ if (selectionModel.selectedIndex == -1)
+ label.label = (host as DropDownList).prompt;
+ chost.strandChildren.addElement(label);
+
+
+ value.addBead(new DropDownListLayout());
+
+ }
+
+ private function selectionChangeHandler(event:Event):void
+ {
+ if (selectionModel.selectedItem == null)
+ label.label = (host as DropDownList).prompt;
+ else if (selectionModel.labelField != null)
+ label.label = selectionModel.selectedItem[selectionModel.labelField].toString();
+ else
+ label.label = selectionModel.selectedItem.toString();
+ }
+
+ /**
+ * The dropdown/popup that displays the set of choices.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.0
+ */
+ public function get popUp():IStrand
+ {
+ return viewport.contentView as IStrand;
+ }
+
+ private var _popUpVisible:Boolean;
+
+ /**
+ * A flag that indicates whether the dropdown/popup is
+ * visible.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.0
+ */
+ public function get popUpVisible():Boolean
+ {
+ return _popUpVisible;
+ }
+
+ /**
+ * @private
+ */
+ public function set popUpVisible(value:Boolean):void
+ {
+ if (value != _popUpVisible)
+ {
+ _popUpVisible = value;
+ if (value)
+ {
+ PopUpManager.addPopUp(popUp as IFlexDisplayObject, _strand);
+ (popUp as IUIComponent).setActualSize((popUp as IUIComponent).width, 100);
+ }
+ else
+ {
+ PopUpManager.removePopUp(popUp as IFlexDisplayObject);
+ }
+ }
+ }
+}
+
+}
+
+import spark.components.Button;
+import spark.components.DropDownList;
+import spark.components.beads.DropDownListView;
+
+import org.apache.royale.core.LayoutBase;
+
+// this layouts out the one Label/Button.
+class DropDownListLayout extends LayoutBase
+{
+ override public function layout():Boolean
+ {
+ var list:DropDownList = host as DropDownList;
+ var view:DropDownListView = list.view as DropDownListView;
+ view.label.setActualSize(list.width, list.height);
+
+ return false;
+ }
+}
+
+
diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/controllers/DropDownListController.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/controllers/DropDownListController.as
new file mode 100644
index 0000000..ffddb69
--- /dev/null
+++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/beads/controllers/DropDownListController.as
@@ -0,0 +1,111 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 spark.components.beads.controllers
+{
+
+
+import org.apache.royale.core.IBead;
+import org.apache.royale.core.IBeadController;
+import org.apache.royale.core.ISelectionModel;
+import org.apache.royale.core.IStrand;
+import org.apache.royale.core.IUIBase;
+import org.apache.royale.core.UIBase;
+import org.apache.royale.events.Event;
+import org.apache.royale.events.IEventDispatcher;
+import org.apache.royale.events.MouseEvent;
+import org.apache.royale.html.beads.IDropDownListView;
+import org.apache.royale.geom.Point;
+import org.apache.royale.utils.PointUtils;
+import org.apache.royale.events.MouseEvent;
+
+import mx.core.UIComponent;
+
+/**
+ * @private
+ * The controller for Spark Dropdownlist.
+ *
+ */
+public class DropDownListController implements IBead, IBeadController
+{
+ // NOTE: this is a copy of Basic DropDownListController but the Basic one is SWF-only
+
+
+ private var _strand:IStrand;
+
+ /**
+ * @copy org.apache.royale.core.IBead#strand
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.0
+ */
+ public function set strand(value:IStrand):void
+ {
+ _strand = value;
+ IEventDispatcher(value).addEventListener(org.apache.royale.events.MouseEvent.CLICK, clickHandler);
+ }
+
+ private function clickHandler(event:org.apache.royale.events.MouseEvent):void
+ {
+ var viewBead:IDropDownListView = _strand.getBeadByType(IDropDownListView) as IDropDownListView;
+ var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
+ var popUpModel:ISelectionModel = UIBase(viewBead.popUp).model as ISelectionModel;
+ IUIBase(viewBead.popUp).width = IUIBase(_strand).width;
+ popUpModel.dataProvider = selectionModel.dataProvider;
+ popUpModel.labelField = selectionModel.labelField;
+ viewBead.popUpVisible = true; // adds to display list as well
+ popUpModel.selectedIndex = selectionModel.selectedIndex;
+ var pt:Point = new Point(IUIBase(_strand).x, IUIBase(_strand).y + IUIBase(_strand).height);
+ pt = PointUtils.localToGlobal(pt, _strand);
+ IUIBase(viewBead.popUp).x = pt.x;
+ IUIBase(viewBead.popUp).y = pt.y;
+ IEventDispatcher(viewBead.popUp).addEventListener("change", changeHandler);
+ UIComponent(viewBead.popUp).callLater(registerDismissHandler);
+ }
+
+ // The browser send clicks to listeners added as the event is being dispatched, so if we don't
+ // defer, we pick up the click that opened the dropdown.
+ private function registerDismissHandler():void
+ {
+ IUIBase(_strand).topMostEventDispatcher.addEventListener(org.apache.royale.events.MouseEvent.CLICK, dismissHandler);
+ }
+
+ private function dismissHandler(event:org.apache.royale.events.MouseEvent):void
+ {
+ if (event.target == _strand) return;
+
+ IUIBase(_strand).topMostEventDispatcher.removeEventListener(org.apache.royale.events.MouseEvent.CLICK, dismissHandler);
+ var viewBead:IDropDownListView = _strand.getBeadByType(IDropDownListView) as IDropDownListView;
+ viewBead.popUpVisible = false;
+ }
+
+ private function changeHandler(event:Event):void
+ {
+ var viewBead:IDropDownListView = _strand.getBeadByType(IDropDownListView) as IDropDownListView;
+ viewBead.popUpVisible = false;
+ var selectionModel:ISelectionModel = _strand.getBeadByType(ISelectionModel) as ISelectionModel;
+ var popUpModel:ISelectionModel = UIBase(viewBead.popUp).model as ISelectionModel;
+ selectionModel.selectedIndex = popUpModel.selectedIndex;
+ IEventDispatcher(_strand).dispatchEvent(new Event("change"));
+ }
+}
+
+}
diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/DropDownListBase.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/DropDownListBase.as
index ebfac16..5ee368a 100644
--- a/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/DropDownListBase.as
+++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/components/supportClasses/DropDownListBase.as
@@ -38,6 +38,8 @@ import spark.components.List;
//import spark.events.DropDownEvent;
import spark.events.IndexChangeEvent;
+import org.apache.royale.core.ISelectionModel;
+
import mx.core.mx_internal;
use namespace mx_internal;
@@ -317,7 +319,9 @@ public class DropDownListBase extends List
if (dataProvider === value)
return;
- super.dataProvider = value;
+ super.dataProvider = value; // this passes it to DataGroup
+
+ (model as ISelectionModel).dataProvider = value;
// labelChanged = true;
invalidateProperties();
}
@@ -367,15 +371,14 @@ public class DropDownListBase extends List
/**
* @private
*/
- /* override public function set labelField(value:String):void
+ override public function set labelField(value:String):void
{
- if (labelField == value)
- return;
-
- super.labelField = value;
- labelChanged = true;
- invalidateProperties();
- } */
+ super.labelField = value; // this passes it to DataGroup
+
+ (model as ISelectionModel).labelField = value;
+ //labelChanged = true;
+ //invalidateProperties();
+ }
//----------------------------------
// labelFunction