royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [royale-asjs] 10/14: AlternatingBackgroundColor renderer
Date Fri, 02 Feb 2018 22:09:13 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 41eb80478d3ca7755915386a0331c3d446d17cc5
Author: Alex Harui <aharui@apache.org>
AuthorDate: Fri Feb 2 11:24:25 2018 -0800

    AlternatingBackgroundColor renderer
---
 .../ASDoc/src/main/royale/ASDocMainView.mxml       |  8 +-
 .../Basic/src/main/resources/basic-manifest.xml    |  1 +
 ...AlternatingBackgroundColorStringItemRenderer.as | 96 ++++++++++++++++++++++
 3 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/examples/royale/ASDoc/src/main/royale/ASDocMainView.mxml b/examples/royale/ASDoc/src/main/royale/ASDocMainView.mxml
index efbc016..19f92dc 100644
--- a/examples/royale/ASDoc/src/main/royale/ASDocMainView.mxml
+++ b/examples/royale/ASDoc/src/main/royale/ASDocMainView.mxml
@@ -90,6 +90,11 @@ limitations under the License.
         }
         
 	</fx:Style>
+	<fx:Declarations>
+		<fx:Component className="AltBGRenderer">
+		    <js:AlternatingBackgroundColorStringItemRenderer backgroundColor0="#ffffff" backgroundColor1="#ffeeee"
/>
+		</fx:Component>
+	</fx:Declarations>
 	<js:states>
 	  <js:State name="packages" />
 	  <js:State name="classDetail" />
@@ -130,7 +135,8 @@ limitations under the License.
 	                <js:VerticalLayout />
 	            </js:beads>
 	            <js:Label className="paneTitle" text="All Packages" width="100%"/>
-	            <js:List className="paneList" id="packagePaneList" dataProvider="{ASDocModel(applicationModel).packageList}"
change="packageListChangedHandler()"/>
+	            <js:List className="paneList" id="packagePaneList" dataProvider="{ASDocModel(applicationModel).packageList}"

+	                itemRenderer="AltBGRenderer" change="packageListChangedHandler()"/>
             </js:Group>
             <js:Group id="detailsPane" width="100%" includeIn="classDetail">
 	            <js:beads>
diff --git a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
index ad0ac29..4da5734 100644
--- a/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Basic/src/main/resources/basic-manifest.xml
@@ -93,6 +93,7 @@
     <component id="Spinner" class="org.apache.royale.html.Spinner"/>
     <component id="Slider" class="org.apache.royale.html.Slider"/>
     <component id="NumericStepper" class="org.apache.royale.html.NumericStepper" />
+    <component id="AlternatingBackgroundColorStringItemRenderer" class="org.apache.royale.html.supportClasses.AlternatingBackgroundColorStringItemRenderer"/>
     <component id="StringItemRenderer" class="org.apache.royale.html.supportClasses.StringItemRenderer"/>
     <component id="AccordionItemRenderer" class="org.apache.royale.html.supportClasses.AccordionItemRenderer"/>
     <component id="AccordionCollapseBead" class="org.apache.royale.html.beads.AccordionCollapseBead"/>
diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/AlternatingBackgroundColorStringItemRenderer.as
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/AlternatingBackgroundColorStringItemRenderer.as
new file mode 100644
index 0000000..a9e3a80
--- /dev/null
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/supportClasses/AlternatingBackgroundColorStringItemRenderer.as
@@ -0,0 +1,96 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 org.apache.royale.html.supportClasses
+{
+
+	/**
+	 *  The AlternatingBackgroundColorStringItemRenderer class displays data in string form
using the data's toString()
+	 *  function and alternates between two background colors.  This is the most simple implementation
for immutable lists
+	 *  and will not handle adding/removing renderers.
+	 *
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.0
+	 */
+	public class AlternatingBackgroundColorStringItemRenderer extends StringItemRenderer
+	{
+		/**
+		 *  constructor.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.0
+		 */
+		public function AlternatingBackgroundColorStringItemRenderer()
+		{
+		}
+
+		private var _color0:String;
+		
+		public function get backgroundColor0():String
+		{
+			return _color0;
+		}
+		public function set backgroundColor0(value:String):void
+		{
+			_color0 = value;
+		}
+		
+		private var _color1:String;
+		
+		public function get backgroundColor1():String
+		{
+			return _color1;
+		}
+		public function set backgroundColor1(value:String):void
+		{
+			_color1 = value;
+		}
+		
+		private var oddIndex:Boolean;
+		
+		override public function addedToParent():void
+		{
+			super.addedToParent();
+
+			var index:int = parent.getElementIndex(this);
+			oddIndex = ((index % 2) == 1)
+			COMPILE::JS
+			{
+				element.style.backgroundColor = oddIndex ? _color1 : _color0;
+			}
+		}
+
+		/**
+		 * @private
+		 */
+		override public function updateRenderer():void
+		{
+			super.updateRenderer();
+			COMPILE::JS
+			{
+				if (element.style.backgroundColor == null || element.style.backgroundColor == "")
+					element.style.backgroundColor = oddIndex ? _color1 : _color0;
+			}
+		}
+
+	}
+}

-- 
To stop receiving notification emails like this one, please contact
aharui@apache.org.

Mime
View raw message