- Added an initial working example using flexjs
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/b145b025 Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/b145b025 Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/b145b025 Branch: refs/heads/as3httpclient-work Commit: b145b025ca4f9421bdc62e3f79550f70d8aa9c2d Parents: cb3fbd2 Author: Christofer Dutz <christofer.d...@codecentric.de> Authored: Fri May 8 16:41:34 2015 +0200 Committer: Christofer Dutz <christofer.d...@codecentric.de> Committed: Fri May 8 16:41:34 2015 +0200 ---------------------------------------------------------------------- .../examples/flexjs/flexjs-hello-world/pom.xml | 76 ++++++++++ .../src/main/flex/FlexJSTest_basic.mxml | 53 +++++++ .../src/main/flex/MyInitialView.mxml | 143 +++++++++++++++++++ .../src/main/flex/StockDataJSONItemConverter.as | 38 +++++ .../src/main/flex/controllers/MyController.as | 92 ++++++++++++ .../src/main/flex/models/MyModel.as | 59 ++++++++ maven-flex-plugin/examples/flexjs/pom.xml | 40 ++++++ maven-flex-plugin/examples/pom.xml | 1 + 8 files changed, 502 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b145b025/maven-flex-plugin/examples/flexjs/flexjs-hello-world/pom.xml ---------------------------------------------------------------------- diff --git a/maven-flex-plugin/examples/flexjs/flexjs-hello-world/pom.xml b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/pom.xml new file mode 100644 index 0000000..3ad9c85 --- /dev/null +++ b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/pom.xml @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.examples.flexjs</groupId> + <artifactId>flexjs</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <artifactId>flexjs-hello-world</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>swf</packaging> + + <build> + <sourceDirectory>src/main/flex</sourceDirectory> + <plugins> + <plugin> + <groupId>net.flexmojos.oss</groupId> + <artifactId>flexmojos-maven-plugin</artifactId> + <version>7.1.0-SNAPSHOT</version> + <extensions>true</extensions> + <configuration> + <sourceFile>FlexJSTest_basic.mxml</sourceFile> + <!--compilerName>Falcon</compilerName--> + <compilerName>FlexJS</compilerName> + <debug>true</debug> + </configuration> + <dependencies> + <dependency> + <groupId>org.apache.flex.compiler</groupId> + <artifactId>falcon-jx-compiler</artifactId> + <version>0.0.3-SNAPSHOT</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.apache.flex.flexjs</groupId> + <artifactId>framework</artifactId> + <version>0.0.3-SNAPSHOT</version> + <type>pom</type> + </dependency> + <!-- This is still only needed to satisfy check in Flexmojos --> + <dependency> + <groupId>com.adobe.flash.framework</groupId> + <artifactId>playerglobal</artifactId> + <version>14.0</version> + <type>swc</type> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b145b025/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/FlexJSTest_basic.mxml ---------------------------------------------------------------------- diff --git a/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/FlexJSTest_basic.mxml b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/FlexJSTest_basic.mxml new file mode 100644 index 0000000..b000196 --- /dev/null +++ b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/FlexJSTest_basic.mxml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +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. + +--> +<basic:Application xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:local="*" + xmlns:basic="library://ns.apache.org/flexjs/basic" + xmlns:models="models.*" + xmlns:controllers="controllers.*" + initialize="MyModel(model).labelText='Hello World'"> + + <fx:Script><![CDATA[ import models.MyModel; ]]></fx:Script> + + <basic:valuesImpl> + <basic:SimpleCSSValuesImpl /> + </basic:valuesImpl> + <basic:initialView> + <local:MyInitialView /> + </basic:initialView> + <basic:model> + <models:MyModel /> + </basic:model> + <basic:controller> + <controllers:MyController /> + </basic:controller> + <basic:beads> + <basic:HTTPService id="service"> + <basic:LazyCollection id="collection"> + <basic:inputParser> + <basic:JSONInputParser /> + </basic:inputParser> + <basic:itemConverter> + <local:StockDataJSONItemConverter /> + </basic:itemConverter> + </basic:LazyCollection> + </basic:HTTPService> + </basic:beads> +</basic:Application> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b145b025/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/MyInitialView.mxml ---------------------------------------------------------------------- diff --git a/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/MyInitialView.mxml b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/MyInitialView.mxml new file mode 100644 index 0000000..9a910cc --- /dev/null +++ b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/MyInitialView.mxml @@ -0,0 +1,143 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +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. + +--> +<basic:ViewBase xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:basic="library://ns.apache.org/flexjs/basic" + > + <fx:Script> + <![CDATA[ + import org.apache.flex.events.CustomEvent; + import org.apache.flex.events.Event; + import org.apache.flex.utils.Timer; + + private var timer:org.apache.flex.utils.Timer; + + public function get symbol():String + { + return list.selectedItem as String; + } + + public function get city():String + { + return cityList.selectedItem as String; + } + + public function get inputText():String + { + return input.text; + } + + public function get comboBoxValue():String + { + return String(comboBox.selectedItem); + } + + public function startTimer():void + { + timer = new org.apache.flex.utils.Timer(1000); + timer.addEventListener('timer', timerHandler); + timer.start() + } + + public function timerHandler(event:org.apache.flex.events.Event):void + { + timerLabel.text = timer.currentCount.toString(); + } + ]]> + </fx:Script> + <fx:Style> + @namespace basic "library://ns.apache.org/flexjs/basic"; + + .skinned { + background-image: url('ButtonImageUp.png'); + border-style: none; + } + + .skinned:hover { + background-image: url('ButtonImageOver.png'); + } + + .skinned:active { + background-image: url('ButtonImageDown.png'); + } + + </fx:Style> + <basic:Label id="lbl" x="100" y="25" > + <basic:beads> + <basic:SimpleBinding eventName="labelTextChanged" + sourceID="applicationModel" + sourcePropertyName="labelText" + destinationPropertyName="text" /> + </basic:beads> + </basic:Label> + <basic:TextButton text="Start Timer" x="100" y="75" click="startTimer()" /> + <basic:TextButton text="Stop Timer" x="100" y="100" click="timer.removeEventListener('timer', timerHandler);timer.stop()" /> + <basic:Label id="timerLabel" x="100" y="125" /> + + <basic:List id="cityList" x="200" y="75" width="100" height="75" change="dispatchEvent(new CustomEvent('cityListChanged'))"> + <basic:beads> + <basic:ConstantBinding + sourceID="applicationModel" + sourcePropertyName="cities" + destinationPropertyName="dataProvider" /> + </basic:beads> + </basic:List> + + <basic:TextArea x="320" y="25" width="150" height="75"> + <basic:beads> + <basic:SimpleBinding eventName="labelTextChanged" + sourceID="applicationModel" + sourcePropertyName="labelText" + destinationPropertyName="text" /> + </basic:beads> + </basic:TextArea> + <basic:TextInput id="input" x="320" y="110" /> + <basic:TextButton text="Transfer" x="320" y="138" click="dispatchEvent(new CustomEvent('transferClicked'))" /> + + <basic:CheckBox id="checkbox" x="320" y="170" text="Check Me" /> + + <basic:RadioButton groupName="group1" text="Apples" value="0" x="100" y="150" /> + <basic:RadioButton groupName="group1" text="Oranges" value="1" x="100" y="170" selected="true" /> + <basic:RadioButton groupName="group1" text="Grapes" value="2" x="100" y="190" /> + + <basic:RadioButton groupName="group2" text="Red" value="red" x="100" y="250" selected="true" /> + <basic:RadioButton groupName="group2" text="Green" value="green" x="100" y="270" /> + <basic:RadioButton groupName="group2" text="Blue" value="blue" x="100" y="290" /> + + <basic:DropDownList id="list" x="200" y="200" width="100" height="18" change="dispatchEvent(new CustomEvent('listChanged'))"> + <basic:beads> + <basic:ConstantBinding + sourceID="applicationModel" + sourcePropertyName="strings" + destinationPropertyName="dataProvider" /> + </basic:beads> + </basic:DropDownList> + <basic:TextButton text="OK" x="200" y="230" click="dispatchEvent(new CustomEvent('buttonClicked'))" /> + <basic:TextButton text="Skinned" x="200" y="260" width="80" height="24" className="skinned" click="dispatchEvent(new CustomEvent('buttonClicked'))" /> + + <basic:ComboBox id="comboBox" x="320" y="200" width="100" change="dispatchEvent(new CustomEvent('comboBoxChanged'))"> + <basic:beads> + <basic:ConstantBinding + sourceID="applicationModel" + sourcePropertyName="cities" + destinationPropertyName="dataProvider" /> + </basic:beads> + </basic:ComboBox> + +</basic:ViewBase> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b145b025/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/StockDataJSONItemConverter.as ---------------------------------------------------------------------- diff --git a/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/StockDataJSONItemConverter.as b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/StockDataJSONItemConverter.as new file mode 100644 index 0000000..5ad0c38 --- /dev/null +++ b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/StockDataJSONItemConverter.as @@ -0,0 +1,38 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ +import org.apache.flex.collections.converters.JSONItemConverter; + + public class StockDataJSONItemConverter extends JSONItemConverter + { + public function StockDataJSONItemConverter() + { + super(); + } + + override public function convertItem(data:String):Object + { + var obj:Object = super.convertItem(data); + if (obj['query']['results'] == null) + return 'No Quote Available'; + return obj['query']['results']['quote']['Ask']; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b145b025/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/controllers/MyController.as ---------------------------------------------------------------------- diff --git a/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/controllers/MyController.as b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/controllers/MyController.as new file mode 100644 index 0000000..636ed30 --- /dev/null +++ b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/controllers/MyController.as @@ -0,0 +1,92 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 controllers +{ + import org.apache.flex.core.Application; + import org.apache.flex.core.IDocument; + import org.apache.flex.events.Event; + + + import models.MyModel; + + public class MyController implements IDocument + { + public function MyController(app:Application = null) + { + if (app) + { + this.app = app as FlexJSTest_basic; + app.addEventListener("viewChanged", viewChangeHandler); + } + } + + private var queryBegin:String = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22"; + private var queryEnd:String = "%22)%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json"; + private var app:FlexJSTest_basic; + + private function viewChangeHandler(event:Event):void + { + app.initialView.addEventListener("buttonClicked", buttonClickHandler); + app.initialView.addEventListener("listChanged", listChangedHandler); + app.initialView.addEventListener("cityListChanged", cityListChangeHandler); + app.initialView.addEventListener("transferClicked", transferClickHandler); + app.initialView.addEventListener("comboBoxChanged", comboBoxChangeHandler); + } + + private function buttonClickHandler(event:Event):void + { + var sym:String = MyInitialView(app.initialView).symbol; + app.service.url = queryBegin + sym + queryEnd; + app.service.send(); + app.service.addEventListener("complete", completeHandler); + } + + private function completeHandler(event:Event):void + { + MyModel(app.model).labelText = app.collection.getItemAt(0) as String; + } + + private function listChangedHandler(event:Event):void + { + MyModel(app.model).labelText = MyInitialView(app.initialView).symbol; + } + + private function cityListChangeHandler(event:Event):void + { + MyModel(app.model).labelText = MyInitialView(app.initialView).city; + } + + private function transferClickHandler(event:Event):void + { + MyModel(app.model).labelText = MyInitialView(app.initialView).inputText; + } + + private function comboBoxChangeHandler(event:Event):void + { + MyModel(app.model).labelText = MyInitialView(app.initialView).comboBoxValue; + } + + public function setDocument(document:Object, id:String = null):void + { + this.app = document as FlexJSTest_basic; + app.addEventListener("viewChanged", viewChangeHandler); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b145b025/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/models/MyModel.as ---------------------------------------------------------------------- diff --git a/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/models/MyModel.as b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/models/MyModel.as new file mode 100644 index 0000000..1dc23e6 --- /dev/null +++ b/maven-flex-plugin/examples/flexjs/flexjs-hello-world/src/main/flex/models/MyModel.as @@ -0,0 +1,59 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 models +{ + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + + public class MyModel extends EventDispatcher + { + public function MyModel() + { + } + + private var _labelText:String; + + public function get labelText():String + { + return _labelText; + } + + public function set labelText(value:String):void + { + if (value != _labelText) + { + _labelText = value; + dispatchEvent(new Event("labelTextChanged")); + } + } + + private var _strings:Array = ["AAPL", "ADBE", "GOOG", "MSFT", "YHOO"]; + public function get strings():Array + { + return _strings; + } + + private var _cities:Array = ["London", "Miami", "Paris", "Sydney", "Tokyo"]; + public function get cities():Array + { + return _cities; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b145b025/maven-flex-plugin/examples/flexjs/pom.xml ---------------------------------------------------------------------- diff --git a/maven-flex-plugin/examples/flexjs/pom.xml b/maven-flex-plugin/examples/flexjs/pom.xml new file mode 100644 index 0000000..8d01b07 --- /dev/null +++ b/maven-flex-plugin/examples/flexjs/pom.xml @@ -0,0 +1,40 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.flex.examples</groupId> + <artifactId>parent</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + + <groupId>org.apache.flex.examples.flexjs</groupId> + <artifactId>flexjs</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>pom</packaging> + + <modules> + <module>flexjs-hello-world</module> + </modules> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b145b025/maven-flex-plugin/examples/pom.xml ---------------------------------------------------------------------- diff --git a/maven-flex-plugin/examples/pom.xml b/maven-flex-plugin/examples/pom.xml index 36f9a77..b83d09e 100644 --- a/maven-flex-plugin/examples/pom.xml +++ b/maven-flex-plugin/examples/pom.xml @@ -28,6 +28,7 @@ <packaging>pom</packaging> <modules> + <module>flexjs</module> <module>i18n</module> </modules>