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/07/21 06:28:09 UTC

[royale-asjs] 01/17: abstract how Panel creates its content area so it can be re-used in emulation (and have fewer class dependencies)

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 a8caeb25bea6619765070e672db5d01bb6151908
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Jul 17 16:31:11 2018 -0700

    abstract how Panel creates its content area so it can be re-used in emulation (and have fewer class dependencies)
---
 .../projects/Basic/src/main/resources/defaults.css |   2 +
 .../main/royale/org/apache/royale/html/Panel.as    |  37 ++++++-
 .../org/apache/royale/html/beads/PanelView.as      |  33 +++----
 .../royale/html/supportClasses/PanelLayoutProxy.as | 108 +++++++++++++++++----
 4 files changed, 141 insertions(+), 39 deletions(-)

diff --git a/frameworks/projects/Basic/src/main/resources/defaults.css b/frameworks/projects/Basic/src/main/resources/defaults.css
index d60a26e..9c284a3 100644
--- a/frameworks/projects/Basic/src/main/resources/defaults.css
+++ b/frameworks/projects/Basic/src/main/resources/defaults.css
@@ -1002,6 +1002,7 @@ global
 		IContentView: ClassReference("org.apache.royale.html.supportClasses.ContainerContentArea");
 		IBorderBead: ClassReference("org.apache.royale.html.beads.SingleLineBorderBead");
 		IBackgroundBead: ClassReference("org.apache.royale.html.beads.SolidBackgroundBead");    
+		IPanelContentArea: ClassReference("org.apache.royale.html.Container");
 	}
 	
 	PanelWithControlBar
@@ -1009,6 +1010,7 @@ global
 		IContentView: ClassReference("org.apache.royale.html.supportClasses.ContainerContentArea");
 		IBorderBead: ClassReference("org.apache.royale.html.beads.SingleLineBorderBead");
 		IBackgroundBead: ClassReference("org.apache.royale.html.beads.SolidBackgroundBead");
+		IPanelContentArea: ClassReference("org.apache.royale.html.Container");
 	}
 	
 	RadioButton
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/Panel.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/Panel.as
index f455e2d..9680244 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/Panel.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/Panel.as
@@ -20,6 +20,7 @@ package org.apache.royale.html
 {
 	import org.apache.royale.core.IPanelModel;
 	import org.apache.royale.core.IChild;
+    import org.apache.royale.core.IContainerBaseStrandChildrenHost;
 	import org.apache.royale.html.beads.PanelView;
 	import org.apache.royale.events.Event;
 
@@ -52,7 +53,7 @@ package org.apache.royale.html
 	 *  @playerversion AIR 2.6
 	 *  @productversion Royale 0.0
 	 */
-	public class Panel extends Group
+	public class Panel extends Group implements IContainerBaseStrandChildrenHost
 	{
 		/**
 		 *  constructor.
@@ -74,16 +75,46 @@ package org.apache.royale.html
 			super.addElement(c, dispatchEvent);
 		}
 		
-		public function get $numElements():Number
+        /**
+         * @private
+         * @suppress {undefinedNames}
+         * Support strandChildren.
+         */
+        public function $addElementAt(c:IChild, index:int, dispatchEvent:Boolean = true):void
+        {
+            super.addElementAt(c, index, dispatchEvent);
+        }
+        
+		public function get $numElements():int
 		{
 			return super.numElements;
 		}
 		
-		public function $getElementAt(index:Number):IChild
+		public function $getElementAt(index:int):IChild
 		{
 			return super.getElementAt(index);
 		}
 		
+        /**
+         * @private
+         * @suppress {undefinedNames}
+         * Support strandChildren.
+         */
+        public function $removeElement(c:IChild, dispatchEvent:Boolean = true):void
+        {
+            super.removeElement(c, dispatchEvent);
+        }
+        
+        /**
+         * @private
+         * @suppress {undefinedNames}
+         * Support strandChildren.
+         */
+        public function $getElementIndex(c:IChild):int
+        {
+            return super.getElementIndex(c);
+        }
+        
 		/**
 		 *  The string to display in the org.apache.royale.html.TitleBar.
 		 *
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/PanelView.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/PanelView.as
index d4ff9d7..df42f23 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/PanelView.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/PanelView.as
@@ -18,12 +18,13 @@
 ////////////////////////////////////////////////////////////////////////////////
 package org.apache.royale.html.beads
 {
-	import org.apache.royale.core.IBeadView;
 	import org.apache.royale.core.IBeadLayout;
-	import org.apache.royale.core.ILayoutChild;
-	import org.apache.royale.core.ILayoutView;
+	import org.apache.royale.core.IBeadView;
 	import org.apache.royale.core.IChild;
 	import org.apache.royale.core.IContainer;
+	import org.apache.royale.core.IContainerBaseStrandChildrenHost;
+	import org.apache.royale.core.ILayoutChild;
+	import org.apache.royale.core.ILayoutView;
 	import org.apache.royale.core.IParent;
 	import org.apache.royale.core.IStrand;
 	import org.apache.royale.core.IUIBase;
@@ -35,13 +36,12 @@ package org.apache.royale.html.beads
 	import org.apache.royale.events.IEventDispatcher;
 	import org.apache.royale.geom.Rectangle;
 	import org.apache.royale.geom.Size;
-	import org.apache.royale.html.Group;
 	import org.apache.royale.html.Container;
-	import org.apache.royale.html.Panel;
+	import org.apache.royale.html.Group;
 	import org.apache.royale.html.TitleBar;
-	import org.apache.royale.utils.CSSUtils;
 	import org.apache.royale.html.beads.layouts.VerticalFlexLayout;
 	import org.apache.royale.html.supportClasses.PanelLayoutProxy;
+	import org.apache.royale.utils.CSSUtils;
 
 	COMPILE::SWF {
 		import org.apache.royale.core.SimpleCSSStylesWithFlex;
@@ -97,7 +97,7 @@ package org.apache.royale.html.beads
             _titleBar = value;
         }
 
-		private var _contentArea:Container;
+		private var _contentArea:UIBase;
 
 		/**
 		 * The content area of the panel.
@@ -107,17 +107,15 @@ package org.apache.royale.html.beads
 		 *  @playerversion AIR 2.6
 		 *  @productversion Royale 0.8
 		 */
-		public function get contentArea():Container
+		public function get contentArea():UIBase
 		{
 			return _contentArea;
 		}
-		public function set contentArea(value:Container):void
+		public function set contentArea(value:UIBase):void
 		{
 			_contentArea = value;
 		}
 
-		private var _strand:IStrand;
-
 		/**
 		 *  @copy org.apache.royale.core.IBead#strand
 		 *
@@ -129,13 +127,13 @@ package org.apache.royale.html.beads
 		 *  @royaleignorecoercion org.apache.royale.core.IBeadLayout
 		 *  @royaleignorecoercion org.apache.royale.core.IChild
 		 *  @royaleignorecoercion org.apache.royale.core.IViewport
-		 *  @royaleignorecoercion org.apache.royale.html.Panel
+		 *  @royaleignorecoercion org.apache.royale.core.IContainerBaseStrandChildrenHost
 		 */
 		override public function set strand(value:IStrand):void
 		{
-			_strand = value;
+			super.strand = value;
 
-            var host:UIBase = UIBase(value);
+            var host:UIBase = value as UIBase;
 
 			// Look for a layout and/or viewport bead on the host's beads list. If one
 			// is found, pull it off so it will not be added permanently
@@ -184,11 +182,12 @@ package org.apache.royale.html.beads
 			// be picked up automatically by the TitleBar.
 			titleBar.model = host.model;
 			if (titleBar.parent == null) {
-				(_strand as Panel).$addElement(titleBar);
+				(_strand as IContainerBaseStrandChildrenHost).$addElement(titleBar);
 			}
 
 			if (!_contentArea) {
-				_contentArea = new Container();
+                var cls:Class = ValuesManager.valuesImpl.getValue(_strand, "iPanelContentArea");
+				_contentArea = new cls() as UIBase;
 				_contentArea.id = "panelContent";
 				_contentArea.typeNames = "PanelContent";
 
@@ -225,7 +224,7 @@ package org.apache.royale.html.beads
             super.strand = value;
 
 			if (contentArea.parent == null) {
-				(_strand as Panel).$addElement(contentArea as IChild);
+				(_strand as IContainerBaseStrandChildrenHost).$addElement(contentArea as IChild);
 			}
 
 			// Now give the Panel its own layout
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/PanelLayoutProxy.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/PanelLayoutProxy.as
index 13b2902..c7a4d87 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/PanelLayoutProxy.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/PanelLayoutProxy.as
@@ -19,12 +19,12 @@
 package org.apache.royale.html.supportClasses
 {
 	import org.apache.royale.core.UIBase;
-	import org.apache.royale.core.ILayoutView;
-	import org.apache.royale.core.IChild;
+    import org.apache.royale.core.IChild;
+    import org.apache.royale.core.IContainerBaseStrandChildrenHost;
+    import org.apache.royale.core.ILayoutView;
+    import org.apache.royale.core.IParent;
 	import org.apache.royale.events.IEventDispatcher;
 
-	import org.apache.royale.html.Panel;
-
 	COMPILE::JS {
 		import org.apache.royale.core.WrappedHTMLElement;
 	}
@@ -42,7 +42,7 @@ package org.apache.royale.html.supportClasses
      *  @playerversion AIR 2.6
      *  @productversion Royale 0.0
      */
-	public class PanelLayoutProxy implements ILayoutView
+	public class PanelLayoutProxy implements ILayoutView, IParent
 	{
         /**
          *  Constructor.
@@ -66,7 +66,7 @@ package org.apache.royale.html.supportClasses
 		}
 
 		/**
-		 *  @royaleignorecoercion org.apache.royale.html.Panel
+		 *  @royaleignorecoercion org.apache.royale.core.UIBase
 		 *  The width of the bounding box.
 		 *
 		 *  @langversion 3.0
@@ -75,11 +75,11 @@ package org.apache.royale.html.supportClasses
 		 *  @productversion Royale 0.0
 		 */
 		public function get width():Number {
-			return (host as Panel).width;
+			return (host as UIBase).width;
 		}
 
 		/**
-		 *  @royaleignorecoercion org.apache.royale.html.Panel
+		 *  @royaleignorecoercion org.apache.royale.core.UIBase
 		 * The height of the bounding box.
 		 *
 		 *  @langversion 3.0
@@ -88,11 +88,11 @@ package org.apache.royale.html.supportClasses
 		 *  @productversion Royale 0.0
 		 */
 		public function get height():Number {
-			return (host as Panel).height;
+			return (host as UIBase).height;
 		}
 
 		/**
-		 *  @royaleignorecoercion org.apache.royale.html.Panel
+		 *  @royaleignorecoercion org.apache.royale.core.IContainerBaseStrandChildrenHost
 		 *  The number of elements in the parent.
 		 *
 		 *  @langversion 3.0
@@ -102,11 +102,11 @@ package org.apache.royale.html.supportClasses
 		 */
 		public function get numElements():int
 		{
-			return (host as Panel).$numElements;
+			return (host as IContainerBaseStrandChildrenHost).$numElements;
 		}
 
 		/**
-		 *  @royaleignorecoercion org.apache.royale.html.Panel
+		 *  @royaleignorecoercion org.apache.royale.core.IContainerBaseStrandChildrenHost
 		 *  Get a component from the parent.
 		 *
 		 *  @param c The index of the subcomponent.
@@ -118,29 +118,99 @@ package org.apache.royale.html.supportClasses
 		 */
 		public function getElementAt(index:int):IChild
 		{
-			return (host as Panel).$getElementAt(index);
+			return (host as IContainerBaseStrandChildrenHost).$getElementAt(index);
 		}
 
+        /**
+         *  @royaleignorecoercion org.apache.royale.core.IContainerBaseStrandChildrenHost
+         *  Gets the index of this subcomponent.
+         * 
+         *  @param c The subcomponent to add.
+         *  @return The index (zero-based).
+         * 
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+        public function getElementIndex(c:IChild):int
+        {
+            return (host as IContainerBaseStrandChildrenHost).$getElementIndex(c);
+        }
+        
+        /**
+         *  @royaleignorecoercion org.apache.royale.core.IContainerBaseStrandChildrenHost
+         *  Add a component to the parent.
+         * 
+         *  @param c The subcomponent to add.
+         *  @param dispatchEvent Whether to dispatch an event after adding the child.
+         * 
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+        public function addElement(c:IChild, dispatchEvent:Boolean = true):void
+        {
+            (host as IContainerBaseStrandChildrenHost).$addElement(c);
+        }
+        
+        /**
+         *  @royaleignorecoercion org.apache.royale.core.IContainerBaseStrandChildrenHost
+         *  Add a component to the parent.
+         * 
+         *  @param c The subcomponent to add.
+         *  @param index The index where the subcomponent should be added.
+         *  @param dispatchEvent Whether to dispatch an event after adding the child.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+        public function addElementAt(c:IChild, index:int, dispatchEvent:Boolean = true):void
+        {
+            return (host as IContainerBaseStrandChildrenHost).$addElementAt(c, index);
+        }
+        
+        /**
+         *  @royaleignorecoercion org.apache.royale.core.IContainerBaseStrandChildrenHost
+         *  Remove a component from the parent.
+         * 
+         *  @param c The subcomponent to remove.
+         *  @param dispatchEvent Whether to dispatch an event after removing the child.
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.0
+         */
+        public function removeElement(c:IChild, dispatchEvent:Boolean = true):void
+        {
+            return (host as IContainerBaseStrandChildrenHost).$removeElement(c);
+        }
+        
 		/**
-		 * @royaleignorecoercion org.apache.royale.html.Panel
+		 * @royaleignorecoercion org.apache.royale.core.UIBase
 		 */
 		COMPILE::JS
 		public function get somethingelse():WrappedHTMLElement
 		{
-			return (host as Panel).element;
+			return (host as UIBase).element;
 		}
 
 		/**
-		 * @royaleignorecoercion org.apache.royale.html.Panel
+		 * @royaleignorecoercion org.apache.royale.core.UIBase
 		 */
 		COMPILE::JS
 		public function get element():WrappedHTMLElement
 		{
-			return (host as Panel).element;
+			return (host as UIBase).element;
 		}
 
 		/**
-		 *  @royaleignorecoercion org.apache.royale.html.Panel
+		 *  @royaleignorecoercion org.apache.royale.core.UIBase
 		 *  The display style is used for both visible
 		 *  and layout so is managed as a special case.
 		 *  
@@ -152,7 +222,7 @@ package org.apache.royale.html.supportClasses
 		COMPILE::JS
 		public function setDisplayStyleForLayout(value:String):void
 		{
-			(host as Panel).setDisplayStyleForLayout(value);
+			(host as UIBase).setDisplayStyleForLayout(value);
 		}
 
 	}