royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlosrov...@apache.org
Subject [royale-asjs] branch develop updated: first example with source code from gihub
Date Wed, 19 Sep 2018 21:48:14 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/develop by this push:
     new 9c16f01  first example with source code from gihub
9c16f01 is described below

commit 9c16f0150595a29f36e6331ff6e82fb2568745c9
Author: Carlos Rovira <carlosrovira@apache.org>
AuthorDate: Wed Sep 19 23:48:04 2018 +0200

    first example with source code from gihub
---
 examples/royale/JewelExample/pom.xml               |  14 +++
 .../src/main/royale/AlertPlayGround.mxml           | 102 +++++++++++++++------
 .../src/main/royale/services/GitHubService.as      |  83 +++++++++++++++++
 3 files changed, 172 insertions(+), 27 deletions(-)

diff --git a/examples/royale/JewelExample/pom.xml b/examples/royale/JewelExample/pom.xml
index 5b2d66c..6c1935d 100644
--- a/examples/royale/JewelExample/pom.xml
+++ b/examples/royale/JewelExample/pom.xml
@@ -116,6 +116,20 @@
     </dependency>
     <dependency>
       <groupId>org.apache.royale.framework</groupId>
+      <artifactId>Network</artifactId>
+      <version>0.9.4-SNAPSHOT</version>
+      <type>swc</type>
+      <classifier>swf</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.royale.framework</groupId>
+      <artifactId>Network</artifactId>
+      <version>0.9.4-SNAPSHOT</version>
+      <type>swc</type>
+      <classifier>js</classifier>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.royale.framework</groupId>
       <artifactId>JewelTheme</artifactId>
       <version>0.9.4-SNAPSHOT</version>
       <type>swc</type>
diff --git a/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml b/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml
index 2845c46..9c749f8 100644
--- a/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml
+++ b/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml
@@ -18,21 +18,23 @@ limitations under the License.
 
 -->
 <j:SectionContent xmlns:fx="http://ns.adobe.com/mxml/2009"
-		xmlns:j="library://ns.apache.org/royale/jewel"
-		xmlns:html="library://ns.apache.org/royale/html">
+                  xmlns:j="library://ns.apache.org/royale/jewel"
+                  xmlns:js="library://ns.apache.org/royale/basic"
+                  xmlns:html="library://ns.apache.org/royale/html"
+                  xmlns:services="services.*">
     
 	<fx:Script>
 		<![CDATA[
-			import org.apache.royale.jewel.Alert;
+			import org.apache.royale.core.IBeadLayout;
+			import org.apache.royale.core.IBeadView;
 			import org.apache.royale.events.CloseEvent;
+			import org.apache.royale.events.Event;
 			import org.apache.royale.events.MouseEvent;
-			import org.apache.royale.core.IBeadView;
-			import org.apache.royale.jewel.beads.views.AlertView;
-			import org.apache.royale.jewel.beads.layouts.HorizontalLayout;
-			import org.apache.royale.core.IBeadLayout;
+			import org.apache.royale.jewel.Alert;
 			import org.apache.royale.jewel.CheckBox;
-			import org.apache.royale.events.Event;
+			import org.apache.royale.jewel.beads.layouts.HorizontalLayout;
 			import org.apache.royale.jewel.beads.layouts.VerticalLayout;
+			import org.apache.royale.jewel.beads.views.AlertView;
 
             // Event handler function uses a static method to show
             // a pop-up window with the title, message, and requested buttons.        
@@ -79,27 +81,73 @@ limitations under the License.
                 else
                     status.text="You answered No";
             }
+
+            import org.apache.royale.collections.ArrayList;
+            import vos.TabBarButtonVO;
+            
+            private function changeHandler(event:Event):void
+            {
+                var item:TabBarButtonVO = (event.target as TabBar).selectedItem as TabBarButtonVO;
+                tabcontent.showContent(item.href);
+            }
+
+            private var _tabBarNavigation:ArrayList = new ArrayList([
+				new TabBarButtonVO("Examples", "exampleTab", null),
+				new TabBarButtonVO("Source Code", "sourceCodeTab", null)		
+			]);
+
+			public function get tabBarNavigation():ArrayList
+			{
+				return _tabBarNavigation;
+			}
+
+			public function dataReadyHandler(event:Event):void
+			{
+                sourceCodeTextHolder.text = event.target.data;
+			}
 		]]>
 	</fx:Script>
-	
-    <j:Card width="350">
-        <html:H3 text="Jewel Alert"/>
-        
-        <!-- Alert 1-->
-        <j:Label text="Click the button below to display a simple Alert window"
-                multiline="true"/>
-        <j:Button text="Click Me" click="Alert.show('This is an Alert component example
that shows a label text and the default OK button.', 'Alert Example')"/>
-
-        <!-- Alert 2-->
-        <j:Label text="Click the button below to display an Alert window and capture the
button pressed by the user."
-                multiline="true"/>
-        <j:Button text="Click Me" click="clickHandler(event)"/>
-        <j:Label id="status"/>
+
+    <services:GitHubService 
+            sourceCodeUrl="https://api.github.com/repos/apache/royale-asjs/contents/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml"
+            dataReady="dataReadyHandler(event)"/>
+
+    <j:TabBar id="tabbar" className="tabBarIconItemRenderer" change="changeHandler(event)">
+        <j:beads>
+            <js:ConstantBinding
+                sourcePropertyName="tabBarNavigation"
+                destinationPropertyName="dataProvider"/>
+        </j:beads>
+    </j:TabBar>
+    
+    <j:TabBarContent id="tabcontent">
         
-        <!-- Alert 3 (Complex Example)-->
-        <j:Label text="This is a complex example that add and retrieve beads at runtime.
Click the button below to display an Alert window that add content and make changes in some
layout parts."
-                multiline="true"/>
-        <j:Button text="Click Me" click="clickHandler2(event)"/>
-    </j:Card>
+        <j:SectionContent id="exampleTab" isActive="true">
+            <j:Card width="350">
+                <html:H3 text="Jewel Alert"/>
+                
+                <!-- Alert 1-->
+                <j:Label text="Click the button below to display a simple Alert window"
+                        multiline="true"/>
+                <j:Button text="Click Me" click="Alert.show('This is an Alert component
example that shows a label text and the default OK button.', 'Alert Example')"/>
 
+                <!-- Alert 2-->
+                <j:Label text="Click the button below to display an Alert window and capture
the button pressed by the user."
+                        multiline="true"/>
+                <j:Button text="Click Me" click="clickHandler(event)"/>
+                <j:Label id="status"/>
+                
+                <!-- Alert 3 (Complex Example)-->
+                <j:Label text="This is a complex example that add and retrieve beads at
runtime. Click the button below to display an Alert window that add content and make changes
in some layout parts."
+                        multiline="true"/>
+                <j:Button text="Click Me" click="clickHandler2(event)"/>
+            </j:Card>
+        </j:SectionContent>
+
+        <j:SectionContent id="sourceCodeTab">
+            <html:Pre id="sourceCodeTextHolder"/>
+        </j:SectionContent>
+
+    </j:TabBarContent>
+	
 </j:SectionContent>
diff --git a/examples/royale/JewelExample/src/main/royale/services/GitHubService.as b/examples/royale/JewelExample/src/main/royale/services/GitHubService.as
new file mode 100644
index 0000000..092ae71
--- /dev/null
+++ b/examples/royale/JewelExample/src/main/royale/services/GitHubService.as
@@ -0,0 +1,83 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 services
+{
+	import org.apache.royale.net.HTTPService;
+	import org.apache.royale.net.HTTPHeader;
+	import org.apache.royale.events.EventDispatcher;
+	import org.apache.royale.events.Event;
+
+    [Event(name="dataReady", type="org.apache.royale.events.Event")]
+    /**
+     * GitHubService is in charge of getting the source code of some example
+     * so we can show the code in a TabBarContentPanel along with the working example
+     */
+	public class GitHubService extends EventDispatcher
+	{
+        /**
+         * constructor
+         */
+        public function GitHubService():void
+        {
+            // this header makes gihub serve the raw code instead of base64 encoded data
+            var header:HTTPHeader = new HTTPHeader('accept', 'application/vnd.github.VERSION.raw');
+            
+            service = new HTTPService();
+			service.headers.push(header);
+			service.addEventListener("complete", completeHandler);
+        }
+
+        /**
+         * the service that performs the request to Github
+         */
+		private var service:HTTPService;
+
+        /**
+         * we dispatch an event once we have the source code from gihub
+         */
+        private function completeHandler(event:Event):void
+        {
+            dispatchEvent(new Event("dataReady"));
+        }
+
+        //example = "https://api.github.com/repos/apache/royale-asjs/contents/examples/royale/JewelExample/src/main/royale/AlertPlayGround.mxml";
+        private var _sourceCodeUrl:String = null;
+        /**
+         * The source code url we want to retrieve
+         */
+        private function get sourceCodeUrl():String
+        {
+        	return _sourceCodeUrl;
+        }
+        private function set sourceCodeUrl(value:String):void
+        {
+        	_sourceCodeUrl = value;
+            service.url = sourceCodeUrl;
+            service.send();
+        }
+
+        /**
+         * data holds the resulting text code to show
+         */
+        public function get data():String
+        {
+        	return service.data;
+        }
+	}
+}


Mime
View raw message