Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DFFF610F26 for ; Mon, 18 Nov 2013 21:02:59 +0000 (UTC) Received: (qmail 29501 invoked by uid 500); 18 Nov 2013 21:02:57 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 29424 invoked by uid 500); 18 Nov 2013 21:02:57 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 29059 invoked by uid 99); 18 Nov 2013 21:02:56 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Nov 2013 21:02:56 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A77F135DF0; Mon, 18 Nov 2013 21:02:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aharui@apache.org To: commits@flex.apache.org Date: Mon, 18 Nov 2013 21:03:12 -0000 Message-Id: In-Reply-To: <8ac04100b51c448eb9e3ca087eb86c82@git.apache.org> References: <8ac04100b51c448eb9e3ca087eb86c82@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [17/21] move AS code into a projects/FlexJSUI http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IValuesImpl.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IValuesImpl.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IValuesImpl.as new file mode 100644 index 0000000..530861c --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IValuesImpl.as @@ -0,0 +1,28 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + public interface IValuesImpl + { + function getValue(thisObject:Object, valueName:String, state:String = null, attrs:Object = null):*; + function getInstance(valueName:String):Object; + + function init(mainClass:Object):void; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ItemRendererClassFactory.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ItemRendererClassFactory.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ItemRendererClassFactory.as new file mode 100644 index 0000000..0dc1959 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ItemRendererClassFactory.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 org.apache.flex.core +{ + import flash.display.DisplayObject; + import flash.display.DisplayObjectContainer; + + import org.apache.flex.utils.MXMLDataInterpreter; + + [DefaultProperty("mxmlContent")] + public class ItemRendererClassFactory extends Strand implements IItemRendererClassFactory, IDocument, IBead + { + public function ItemRendererClassFactory() + { + super(); + } + + private var _strand:IStrand; + + public function set strand(value:IStrand):void + { + _strand = value; + itemRendererClass = ValuesManager.valuesImpl.getValue(_strand, "iItemRenderer") as Class; + if (itemRendererClass) + createFunction = createFromClass; + } + + public function get MXMLDescriptor():Array + { + return null; + } + + public function get MXMLProperties():Array + { + return null; + } + + public var mxmlContent:Array; + + public function createItemRenderer(parent:IItemRendererParent):IItemRenderer + { + return createFunction(parent); + } + + public var createFunction:Function = createFromMXMLContent; + + protected function createFromMXMLContent(parent:IItemRendererParent):IItemRenderer + { + return MXMLDataInterpreter.generateMXMLArray(document, parent as IParent, MXMLDescriptor, true)[0]; + } + + public var itemRendererClass:Class; + + public function createFromClass(parent:IItemRendererParent):IItemRenderer + { + var renderer:IItemRenderer = new itemRendererClass(); + parent.addElement(renderer); + return renderer; + } + + private var document:Object; + public function setDocument(document:Object, id:String = null):void + { + this.document = document; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/PopUpManager.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/PopUpManager.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/PopUpManager.as new file mode 100644 index 0000000..862d70c --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/PopUpManager.as @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + import flash.display.DisplayObject; + import flash.display.DisplayObjectContainer; + import flash.events.Event; + + public class PopUpManager implements IDocument + { + public function PopUpManager() + { + } + + private var document:DisplayObjectContainer; + + public function setDocument(document:Object, id:String = null):void + { + this.document = document as DisplayObjectContainer; + this.document.addEventListener(Event.ADDED, addedHandler); + } + + private function addedHandler(event:Event):void + { + if (event.target != document) + return; + + var n:int = document.numChildren; + var lastPopUp:int = n - 1; + + for (var i:int = n - 1; i >= 0; i--) + { + var child:DisplayObject = document.getChildAt(n); + if (child is IPopUp) + { + if (i < lastPopUp) + { + document.setChildIndex(child, lastPopUp); + lastPopUp--; + } + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleCSSValuesImpl.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleCSSValuesImpl.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleCSSValuesImpl.as new file mode 100644 index 0000000..6f9ad06 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleCSSValuesImpl.as @@ -0,0 +1,301 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + import flash.system.ApplicationDomain; + import flash.utils.getQualifiedClassName; + import flash.utils.getQualifiedSuperclassName; + import flash.utils.getDefinitionByName; + + import org.apache.flex.events.ValueChangeEvent; + import org.apache.flex.events.EventDispatcher; + + public class SimpleCSSValuesImpl extends EventDispatcher implements IValuesImpl + { + public function SimpleCSSValuesImpl() + { + super(); + } + + private var mainClass:Object; + + private var conditionCombiners:Object; + + public function init(mainClass:Object):void + { + var styleClassName:String; + var c:Class; + if (!values) + { + values = {}; + this.mainClass = mainClass; + var mainClassName:String = getQualifiedClassName(mainClass); + styleClassName = "_" + mainClassName + "_Styles"; + c = ApplicationDomain.currentDomain.getDefinition(styleClassName) as Class; + } + else + { + var className:String = getQualifiedClassName(mainClass); + c = ApplicationDomain.currentDomain.getDefinition(className) as Class; + } + generateCSSStyleDeclarations(c["factoryFunctions"], c["data"]); + } + + public function generateCSSStyleDeclarations(factoryFunctions:Object, arr:Array):void + { + if (factoryFunctions == null) + return; + if (arr == null) + return; + + var declarationName:String = ""; + var segmentName:String = ""; + var n:int = arr.length; + for (var i:int = 0; i < n; i++) + { + var className:int = arr[i]; + if (className == CSSClass.CSSSelector) + { + var selectorName:String = arr[++i]; + segmentName = selectorName + segmentName; + if (declarationName != "") + declarationName += " "; + declarationName += segmentName; + segmentName = ""; + } + else if (className == CSSClass.CSSCondition) + { + if (!conditionCombiners) + { + conditionCombiners = {}; + conditionCombiners["class"] = "."; + conditionCombiners["id"] = "#"; + conditionCombiners["pseudo"] = ':'; + } + var conditionType:String = arr[++i]; + var conditionName:String = arr[++i]; + segmentName = segmentName + conditionCombiners[conditionType] + conditionName; + } + else if (className == CSSClass.CSSStyleDeclaration) + { + var factoryName:int = arr[++i]; // defaultFactory or factory + var defaultFactory:Boolean = factoryName == CSSFactory.DefaultFactory; + /* + if (defaultFactory) + { + mergedStyle = styleManager.getMergedStyleDeclaration(declarationName); + style = new CSSStyleDeclaration(selector, styleManager, mergedStyle == null); + } + else + { + style = styleManager.getStyleDeclaration(declarationName); + if (!style) + { + style = new CSSStyleDeclaration(selector, styleManager, mergedStyle == null); + if (factoryName == CSSFactory.Override) + newSelectors.push(style); + } + } + */ + var finalName:String; + var valuesFunction:Function; + var valuesObject:Object; + if (defaultFactory) + { + valuesFunction = factoryFunctions[declarationName]; + valuesObject = new valuesFunction(); + finalName = fixNames(declarationName); + values[finalName] = valuesObject; + } + else + { + valuesFunction = factoryFunctions[declarationName]; + valuesObject = new valuesFunction(); + var o:Object = values[declarationName]; + finalName = fixNames(declarationName); + if (o == null) + values[finalName] = valuesObject; + else + { + valuesFunction.prototype = o; + values[finalName] = new valuesFunction(); + } + } + declarationName = ""; + } + } + + } + + private function fixNames(s:String):String + { + if (s == "") + return "*"; + + var arr:Array = s.split(" "); + var n:int = arr.length; + for (var i:int = 0; i < n; i++) + { + var segmentName:String = arr[i]; + if (segmentName.charAt(0) == "#" || segmentName.charAt(0) == ".") + continue; + + var c:int = segmentName.lastIndexOf("."); + if (c > -1) // it is 0 for class selectors + { + segmentName = segmentName.substr(0, c) + "::" + segmentName.substr(c + 1); + arr[i] = segmentName; + } + } + return arr.join(" "); + } + + public var values:Object; + + public function getValue(thisObject:Object, valueName:String, state:String = null, attrs:Object = null):* + { + var c:int = valueName.indexOf("-"); + while (c != -1) + { + valueName = valueName.substr(0, c) + + valueName.charAt(c + 1).toUpperCase() + + valueName.substr(c + 2); + c = valueName.indexOf("-"); + } + + var value:*; + var o:Object; + var className:String; + var selectorName:String; + + if ("className" in thisObject) + { + className = thisObject.className; + if (state) + { + selectorName = className + ":" + state; + o = values["." + selectorName]; + if (o) + { + value = o[valueName]; + if (value !== undefined) + return value; + } + } + + o = values["." + className]; + if (o) + { + value = o[valueName]; + if (value !== undefined) + return value; + } + } + + className = getQualifiedClassName(thisObject); + while (className != "Object") + { + if (state) + { + selectorName = className + ":" + state; + o = values[selectorName]; + if (o) + { + value = o[valueName]; + if (value !== undefined) + return value; + } + } + + o = values[className]; + if (o) + { + value = o[valueName]; + if (value !== undefined) + return value; + } + className = getQualifiedSuperclassName(thisObject); + thisObject = getDefinitionByName(className); + } + o = values["global"]; + if (o) + { + value = o[valueName]; + if (value !== undefined) + return value; + } + o = values["*"]; + if(o) + { + return o[valueName]; + } + return null; + } + + public function setValue(thisObject:Object, valueName:String, value:*):void + { + var c:int = valueName.indexOf("-"); + while (c != -1) + { + valueName = valueName.substr(0, c) + + valueName.charAt(c + 1).toUpperCase() + + valueName..substr(c + 2); + c = valueName.indexOf("-"); + } + var oldValue:Object = values[valueName]; + if (oldValue != value) + { + values[valueName] = value; + dispatchEvent(new ValueChangeEvent(ValueChangeEvent.VALUE_CHANGE, false, false, oldValue, value)); + } + } + + public function getInstance(valueName:String):Object + { + var o:Object = values["global"]; + if (o is Class) + { + o[valueName] = new o[valueName](); + if (o[valueName] is IDocument) + o[valueName].setDocument(mainClass); + } + return o[valueName]; + } + } +} + +class CSSClass +{ + public static const CSSSelector:int = 0; + public static const CSSCondition:int = 1; + public static const CSSStyleDeclaration:int = 2; +} + +class CSSFactory +{ + public static const DefaultFactory:int = 0; + public static const Factory:int = 1; + public static const Override:int = 2; +} + +class CSSDataType +{ + public static const Native:int = 0; + public static const Definition:int = 1; +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleStatesImpl.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleStatesImpl.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleStatesImpl.as new file mode 100644 index 0000000..1e850a6 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleStatesImpl.as @@ -0,0 +1,137 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + import flash.display.DisplayObject; + import flash.events.IEventDispatcher; + + import mx.states.AddItems; + import mx.states.SetProperty; + import mx.states.State; + + import org.apache.flex.core.IParent; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.events.ValueChangeEvent; + import org.apache.flex.utils.MXMLDataInterpreter; + + public class SimpleStatesImpl extends EventDispatcher implements IStatesImpl, IBead + { + public function SimpleStatesImpl() + { + super(); + } + + private var _strand:IStrand; + + public function set strand(value:IStrand):void + { + _strand = value; + IEventDispatcher(_strand).addEventListener("currentStateChanged", stateChangeHandler); + } + + private function stateChangeHandler(event:ValueChangeEvent):void + { + var doc:Object = event.target; + var arr:Array = doc.states; + for each (var s:State in arr) + { + if (s.name == event.oldValue) + { + revert(s); + break; + } + } + for each (s in arr) + { + if (s.name == event.newValue) + { + apply(s); + break; + } + } + + } + + private function revert(s:State):void + { + var arr:Array = s.overrides; + for each (var o:Object in arr) + { + if (o is AddItems) + { + var ai:AddItems = AddItems(o); + for each (var item:DisplayObject in ai.items) + { + var parent:IParent = ai.document[ai.destination] as IParent; + parent.removeElement(item); + } + if (parent is IContainer) + IContainer(parent).childrenAdded(); + } + else if (o is SetProperty) + { + var sp:SetProperty = SetProperty(o); + sp.document[sp.target][sp.name] = sp.previousValue; + } + } + } + + private function apply(s:State):void + { + var arr:Array = s.overrides; + for each (var o:Object in arr) + { + if (o is AddItems) + { + var ai:AddItems = AddItems(o); + if (ai.items == null) + { + ai.items = MXMLDataInterpreter.generateMXMLArray(ai.document, + null, ai.itemsDescriptor, true); + } + for each (var item:DisplayObject in ai.items) + { + var parent:IParent = ai.document[ai.destination] as IParent; + if (ai.relativeTo != null) + { + var child:Object = ai.document[ai.relativeTo]; + var index:int = parent.getElementIndex(child); + if (ai.position == "after") + index++; + parent.addElementAt(item, index); + } + else + { + parent.addElement(item); + } + } + if (parent is IContainer) + IContainer(parent).childrenAdded(); + } + else if (o is SetProperty) + { + var sp:SetProperty = SetProperty(o); + sp.previousValue = sp.document[sp.target][sp.name]; + sp.document[sp.target][sp.name] = sp.value; + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleValuesImpl.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleValuesImpl.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleValuesImpl.as new file mode 100644 index 0000000..eda53de --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/SimpleValuesImpl.as @@ -0,0 +1,58 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.events.ValueChangeEvent; + + public class SimpleValuesImpl extends EventDispatcher implements IValuesImpl + { + public function SimpleValuesImpl() + { + super(); + } + + public var values:Object; + + public function getValue(thisObject:Object, valueName:String, state:String = null, attrs:Object = null):* + { + return values[valueName]; + } + + public function setValue(thisObject:Object, valueName:String, value:Object):void + { + var oldValue:Object = values[valueName]; + if (oldValue != value) + { + values[valueName] = value; + dispatchEvent(new ValueChangeEvent(ValueChangeEvent.VALUE_CHANGE, false, false, oldValue, value)); + } + } + + public function getInstance(valueName:String):Object + { + return values[valueName]; + } + + public function init(mainClass:Object):void + { + // do nothing + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/Strand.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/Strand.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/Strand.as new file mode 100644 index 0000000..daeca4b --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/Strand.as @@ -0,0 +1,109 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + + /** + * Base class for non-display objects implementing a IStrand + */ + public class Strand extends EventDispatcher implements IStrand + { + public function Strand() + { + super(); + } + + + private var _model:IBeadModel; + public function get model():IBeadModel + { + if (_model == null) + { + // addbead will set _model + addBead(new (ValuesManager.valuesImpl.getValue(this, "iBeadModel")) as IBead); + } + return _model; + } + public function set model(value:IBeadModel):void + { + if (_model != value) + { + addBead(value as IBead); + dispatchEvent(new Event("modelChanged")); + } + } + + private var _id:String; + public function get id():String + { + return _id; + } + public function set id(value:String):void + { + if (_id != value) + { + _id = value; + dispatchEvent(new Event("idChanged")); + } + } + + // beads declared in MXML are added to the strand. + // from AS, just call addBead() + public var beads:Array; + + private var _beads:Vector.; + public function addBead(bead:IBead):void + { + if (!_beads) + _beads = new Vector.; + _beads.push(bead); + if (bead is IBeadModel) + _model = bead as IBeadModel; + bead.strand = this; + } + + public function getBeadByType(classOrInterface:Class):IBead + { + for each (var bead:IBead in _beads) + { + if (bead is classOrInterface) + return bead; + } + return null; + } + + public function removeBead(value:IBead):IBead + { + var n:int = _beads.length; + for (var i:int = 0; i < n; i++) + { + var bead:IBead = _beads[i]; + if (bead == value) + { + _beads.splice(i, 1); + return bead; + } + } + return null; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIBase.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIBase.as new file mode 100644 index 0000000..cdd3841 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIBase.as @@ -0,0 +1,348 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + import flash.display.DisplayObject; + import flash.display.Sprite; + + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + public class UIBase extends Sprite implements IStrand, IEventDispatcher, IUIBase, IParent + { + public function UIBase() + { + super(); + } + + private var _explicitWidth:Number; + public function get explicitWidth():Number + { + return _explicitWidth; + } + public function set explicitWidth(value:Number):void + { + if (_explicitWidth == value) + return; + + // width can be pixel or percent not both + if (!isNaN(value)) + _percentWidth = NaN; + + _explicitWidth = value; + + dispatchEvent(new Event("explicitWidthChanged")); + } + + private var _explicitHeight:Number; + public function get explicitHeight():Number + { + return _explicitHeight; + } + public function set explicitHeight(value:Number):void + { + if (_explicitHeight == value) + return; + + // height can be pixel or percent not both + if (!isNaN(value)) + _percentHeight = NaN; + + _explicitHeight = value; + + dispatchEvent(new Event("explicitHeightChanged")); + } + + private var _percentWidth:Number; + public function get percentWidth():Number + { + return _percentWidth; + } + public function set percentWidth(value:Number):void + { + if (_percentWidth == value) + return; + + if (!isNaN(value)) + _explicitWidth = NaN; + + _percentWidth = value; + + dispatchEvent(new Event("percentWidthChanged")); + } + private var _percentHeight:Number; + public function get percentHeight():Number + { + return _percentHeight; + } + public function set percentHeight(value:Number):void + { + if (_percentHeight == value) + return; + + if (!isNaN(value)) + _explicitHeight = NaN; + + _percentHeight = value; + + dispatchEvent(new Event("percentHeightChanged")); + } + + private var _width:Number; + override public function get width():Number + { + if (isNaN(_width)) + { + var value:* = ValuesManager.valuesImpl.getValue(this, "width"); + if (value === undefined) + return $width; + _width = Number(value); + } + return _width; + } + override public function set width(value:Number):void + { + if (explicitWidth != value) + { + explicitWidth = value; + } + + if (_width != value) + { + _width = value; + dispatchEvent(new Event("widthChanged")); + } + } + protected function get $width():Number + { + return super.width; + } + + private var _height:Number; + override public function get height():Number + { + if (isNaN(_height)) + { + var value:* = ValuesManager.valuesImpl.getValue(this, "height"); + if (value === undefined) + return $height; + _height = Number(value); + } + return _height; + } + override public function set height(value:Number):void + { + if (explicitHeight != value) + { + explicitHeight = value; + } + + if (_height != value) + { + _height = value; + dispatchEvent(new Event("heightChanged")); + } + } + protected function get $height():Number + { + return super.height; + } + + private var _model:IBeadModel; + public function get model():IBeadModel + { + if (_model == null) + { + // addbead will set _model + addBead(new (ValuesManager.valuesImpl.getValue(this, "iBeadModel")) as IBead); + } + return _model; + } + public function set model(value:IBeadModel):void + { + if (_model != value) + { + addBead(value as IBead); + dispatchEvent(new Event("modelChanged")); + } + } + + private var _id:String; + public function get id():String + { + return _id; + } + public function set id(value:String):void + { + if (_id != value) + { + _id = value; + dispatchEvent(new Event("idChanged")); + } + } + + private var _className:String; + public function get className():String + { + return _className; + } + public function set className(value:String):void + { + if (_className != value) + { + _className = value; + dispatchEvent(new Event("classNameChanged")); + } + } + + public function get element():Object + { + return this; + } + + // beads declared in MXML are added to the strand. + // from AS, just call addBead() + public var beads:Array; + + private var _beads:Vector.; + public function addBead(bead:IBead):void + { + if (!_beads) + _beads = new Vector.; + _beads.push(bead); + if (bead is IBeadModel) + _model = bead as IBeadModel; + bead.strand = this; + + if (bead is IBeadView) { + IEventDispatcher(this).dispatchEvent(new Event("viewChanged")); + } + } + + public function getBeadByType(classOrInterface:Class):IBead + { + for each (var bead:IBead in _beads) + { + if (bead is classOrInterface) + return bead; + } + return null; + } + + public function removeBead(value:IBead):IBead + { + var n:int = _beads.length; + for (var i:int = 0; i < n; i++) + { + var bead:IBead = _beads[i]; + if (bead == value) + { + _beads.splice(i, 1); + return bead; + } + } + return null; + } + + public function addElement(c:Object):void + { + if (c is IUIBase) + { + addChild(IUIBase(c).element as DisplayObject); + IUIBase(c).addedToParent(); + } + else + addChild(c as DisplayObject); + } + + public function addElementAt(c:Object, index:int):void + { + if (c is IUIBase) + { + addChildAt(IUIBase(c).element as DisplayObject, index); + IUIBase(c).addedToParent(); + } + else + addChildAt(c as DisplayObject, index); + } + + public function getElementIndex(c:Object):int + { + if (c is IUIBase) + return getChildIndex(IUIBase(c).element as DisplayObject); + else + return getChildIndex(c as DisplayObject); + } + + public function removeElement(c:Object):void + { + if (c is IUIBase) + removeChild(IUIBase(c).element as DisplayObject); + else + removeChild(c as DisplayObject); + } + + public function addedToParent():void + { + var c:Class; + + if (getBeadByType(IBeadModel) == null) + { + c = ValuesManager.valuesImpl.getValue(this, "iBeadModel") as Class; + if (c) + { + var model:IBeadModel = new c as IBeadModel; + if (model) + addBead(model); + } + } + if (getBeadByType(IBeadView) == null) + { + c = ValuesManager.valuesImpl.getValue(this, "iBeadView") as Class; + if (c) + { + var view:IBeadView = new c as IBeadView; + if (view) + addBead(view); + } + } + if (getBeadByType(IBeadController) == null) + { + c = ValuesManager.valuesImpl.getValue(this, "iBeadController") as Class; + if (c) + { + var controller:IBeadController = new c as IBeadController; + if (controller) + addBead(controller); + } + } + } + + public function get measurementBead() : IMeasurementBead + { + var measurementBead:IMeasurementBead = getBeadByType(IMeasurementBead) as IMeasurementBead; + if( measurementBead == null ) { + addBead(measurementBead = new (ValuesManager.valuesImpl.getValue(this, "iMeasurementBead")) as IMeasurementBead); + } + + return measurementBead; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as new file mode 100644 index 0000000..529cc60 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIButtonBase.as @@ -0,0 +1,250 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + import flash.display.DisplayObject; + import flash.display.DisplayObjectContainer; + import flash.display.SimpleButton; + import flash.events.MouseEvent; + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IMeasurementBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.UIBase; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + [Event(name="click", type="org.apache.flex.events.Event")] + + public class UIButtonBase extends SimpleButton implements IStrand, IEventDispatcher, IUIBase + { + public function UIButtonBase(upState:DisplayObject=null, overState:DisplayObject=null, downState:DisplayObject=null, hitTestState:DisplayObject=null) + { + super(upState, overState, downState, hitTestState); + // mouseChildren = true; + // mouseEnabled = true; + addEventListener(MouseEvent.CLICK, clickKiller, false, 9999); + } + + private function clickKiller(event:flash.events.Event):void + { + if (event is MouseEvent) + { + event.stopImmediatePropagation(); + dispatchEvent(new Event("click")); + } + } + + private var _width:Number; + override public function get width():Number + { + if (isNaN(_width)) + { + var value:* = ValuesManager.valuesImpl.getValue(this, "width"); + if (value === undefined) + return $width; + _width = Number(value); + } + return _width; + } + override public function set width(value:Number):void + { + if (_width != value) + { + _width = value; + dispatchEvent(new Event("widthChanged")); + } + } + protected function get $width():Number + { + return super.width; + } + + private var _height:Number; + override public function get height():Number + { + if (isNaN(_height)) + { + var value:* = ValuesManager.valuesImpl.getValue(this, "height"); + if (value === undefined) + return $height; + _height = Number(value); + } + return _height; + } + + override public function set height(value:Number):void + { + if (_height != value) + { + _height = value; + dispatchEvent(new Event("heightChanged")); + } + } + protected function get $height():Number + { + return super.height; + } + + private var _model:IBeadModel; + public function get model():IBeadModel + { + if (_model == null) + { + // addbead will set _model + addBead(new (ValuesManager.valuesImpl.getValue(this, "iBeadModel")) as IBead); + } + return _model; + } + public function set model(value:IBeadModel):void + { + if (_model != value) + { + addBead(value as IBead); + dispatchEvent(new Event("modelChanged")); + } + } + + private var _id:String; + public function get id():String + { + return _id; + } + public function set id(value:String):void + { + if (_id != value) + { + _id = value; + dispatchEvent(new Event("idChanged")); + } + } + + private var _className:String; + public function get className():String + { + return _className; + } + public function set className(value:String):void + { + if (_className != value) + { + _className = value; + dispatchEvent(new Event("classNameChanged")); + } + } + + public function get element():Object + { + return this; + } + + // beads declared in MXML are added to the strand. + // from AS, just call addBead() + public var beads:Array; + + private var strand:Vector.; + public function addBead(bead:IBead):void + { + if (!strand) + strand = new Vector.; + strand.push(bead); + if (bead is IBeadModel) + _model = bead as IBeadModel; + bead.strand = this; + } + + public function getBeadByType(classOrInterface:Class):IBead + { + for each (var bead:IBead in strand) + { + if (bead is classOrInterface) + return bead; + } + return null; + } + + public function removeBead(value:IBead):IBead + { + var n:int = strand.length; + for (var i:int = 0; i < n; i++) + { + var bead:IBead = strand[i]; + if (bead == value) + { + strand.splice(i, 1); + return bead; + } + } + return null; + } + + public function addedToParent():void + { + var c:Class; + + if (getBeadByType(IBeadModel) == null) + { + c = ValuesManager.valuesImpl.getValue(this, "iBeadModel") as Class; + if (c) + { + var model:IBeadModel = new c as IBeadModel; + if (model) + addBead(model); + } + } + if (getBeadByType(IBeadView) == null) + { + c = ValuesManager.valuesImpl.getValue(this, "iBeadView") as Class; + if (c) + { + var view:IBeadView = new c as IBeadView; + if (view) + addBead(view); + } + } + if (getBeadByType(IBeadController) == null) + { + c = ValuesManager.valuesImpl.getValue(this, "iBeadController") as Class; + if (c) + { + var controller:IBeadController = new c as IBeadController; + if (controller) + addBead(controller); + } + } + + _width = $width; + _height = $height; + + } + + public function get measurementBead() : IMeasurementBead + { + var measurementBead:IMeasurementBead = getBeadByType(IMeasurementBead) as IMeasurementBead; + if( measurementBead == null ) { + addBead(measurementBead = new (ValuesManager.valuesImpl.getValue(this, "iMeasurementBead")) as IMeasurementBead); + } + + return measurementBead; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIMetrics.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIMetrics.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIMetrics.as new file mode 100644 index 0000000..65cd424 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/UIMetrics.as @@ -0,0 +1,35 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + public class UIMetrics + { + public function UIMetrics() + { + } + + public var top:Number; + + public var left:Number; + + public var bottom:Number; + + public var right:Number; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ValuesManager.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ValuesManager.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ValuesManager.as new file mode 100644 index 0000000..8bc8fa2 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ValuesManager.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 org.apache.flex.core +{ + public class ValuesManager + { + public function ValuesManager() + { + } + + private static var _valuesImpl:IValuesImpl; + + public static function get valuesImpl():IValuesImpl + { + return _valuesImpl; + } + public static function set valuesImpl(value:IValuesImpl):void + { + _valuesImpl = value; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ViewBase.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ViewBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ViewBase.as new file mode 100644 index 0000000..afeb04d --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ViewBase.as @@ -0,0 +1,131 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + import mx.states.State; + + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.ValueChangeEvent; + import org.apache.flex.utils.MXMLDataInterpreter; + + [Event(name="initComplete", type="org.apache.flex.events.Event")] + [DefaultProperty("mxmlContent")] + public class ViewBase extends UIBase implements IPopUpHost + { + public function ViewBase() + { + super(); + } + + override public function addedToParent():void + { + // each MXML file can also have styles in fx:Style block + ValuesManager.valuesImpl.init(this); + + MXMLDataInterpreter.generateMXMLProperties(this, mxmlProperties); + MXMLDataInterpreter.generateMXMLInstances(this, this, MXMLDescriptor); + + dispatchEvent(new Event("initComplete")) + } + + public function get MXMLDescriptor():Array + { + return null; + } + + private var mxmlProperties:Array ; + + public function generateMXMLAttributes(data:Array):void + { + mxmlProperties = data; + } + + public var mxmlContent:Array; + + private var _applicationModel:Object; + + [Bindable("modelChanged")] + public function get applicationModel():Object + { + return _applicationModel; + } + public function set applicationModel(value:Object):void + { + _applicationModel = value; + dispatchEvent(new Event("modelChanged")); + } + + private var _states:Array; + + public function get states():Array + { + return _states; + } + public function set states(value:Array):void + { + _states = value; + try{ + if (getBeadByType(IStatesImpl) == null) + addBead(new (ValuesManager.valuesImpl.getValue(this, "iStatesImpl")) as IBead); + } + //TODO: Need to handle this case more gracefully + catch(e:Error) + { + trace(e.message); + } + + } + + public function hasState(state:String):Boolean + { + for each (var s:State in _states) + { + if (s.name == state) + return true; + } + return false; + } + + private var _currentState:String; + + public function get currentState():String + { + return _currentState; + } + public function set currentState(value:String):void + { + var event:ValueChangeEvent = new ValueChangeEvent("currentStateChanged", false, false, _currentState, value) + _currentState = value; + dispatchEvent(event); + } + + private var _transitions:Array; + + public function get transitions():Array + { + return _transitions; + } + public function set transitions(value:Array):void + { + _transitions = value; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ViewBaseDataBinding.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ViewBaseDataBinding.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ViewBaseDataBinding.as new file mode 100644 index 0000000..0bff3a4 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/ViewBaseDataBinding.as @@ -0,0 +1,266 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.core +{ + import org.apache.flex.binding.ConstantBinding; + import org.apache.flex.binding.GenericBinding; + import org.apache.flex.binding.PropertyWatcher; + import org.apache.flex.binding.SimpleBinding; + import org.apache.flex.binding.WatcherBase; + import org.apache.flex.core.IBead; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + public class ViewBaseDataBinding implements IBead + { + public function ViewBaseDataBinding() + { + super(); + } + + private var _strand:IStrand; + public function set strand(value:IStrand):void + { + _strand = value; + IEventDispatcher(_strand).addEventListener("initComplete", initCompleteHandler); + } + + private function initCompleteHandler(event:Event):void + { + var fieldWatcher:Object; + var sb:SimpleBinding; + if (!("_bindings" in _strand)) + return; + var bindingData:Array = _strand["_bindings"]; + var n:int = bindingData[0]; + var bindings:Array = []; + var i:int; + var index:int = 1; + for (i = 0; i < n; i++) + { + var binding:Object = {}; + binding.source = bindingData[index++]; + binding.destFunc = bindingData[index++]; + binding.destination = bindingData[index++]; + bindings.push(binding); + } + var watchers:Object = decodeWatcher(bindingData.slice(index)); + for (i = 0; i < n; i++) + { + binding = bindings[i]; + if (binding.source is Array) + { + if (binding.source[0] == "applicationModel") + { + if (binding.source.length == 2 && binding.destination.length == 2) + { + var destination:IStrand; + // can be simplebinding or constantbinding + var modelWatcher:Object = watchers.watcherMap["applicationModel"]; + fieldWatcher = modelWatcher.children.watcherMap[binding.source[1]]; + if (fieldWatcher.eventNames is String) + { + sb = new SimpleBinding(); + sb.destinationPropertyName = binding.destination[1]; + sb.eventName = fieldWatcher.eventNames as String; + sb.sourceID = binding.source[0]; + sb.sourcePropertyName = binding.source[1]; + sb.setDocument(_strand); + destination = _strand[binding.destination[0]] as IStrand; + if (destination) + destination.addBead(sb); + else + { + deferredBindings[binding.destination[0]] = sb; + IEventDispatcher(_strand).addEventListener("valueChange", deferredBindingsHandler); + } + } + else if (fieldWatcher.eventNames == null) + { + var cb:ConstantBinding = new ConstantBinding(); + cb.destinationPropertyName = binding.destination[1]; + cb.sourceID = binding.source[0]; + cb.sourcePropertyName = binding.source[1]; + cb.setDocument(_strand); + destination = _strand[binding.destination[0]] as IStrand; + if (destination) + destination.addBead(cb); + else + { + deferredBindings[binding.destination[0]] = cb; + IEventDispatcher(_strand).addEventListener("valueChange", deferredBindingsHandler); + } + } + } + } + } + else if (binding.source is String) + { + fieldWatcher = watchers.watcherMap[binding.source]; + if (fieldWatcher.eventNames is String) + { + sb = new SimpleBinding(); + sb.destinationPropertyName = binding.destination[1]; + sb.eventName = fieldWatcher.eventNames as String; + sb.sourcePropertyName = binding.source; + sb.setDocument(_strand); + destination = _strand[binding.destination[0]] as IStrand; + if (destination) + destination.addBead(sb); + else + { + deferredBindings[binding.destination[0]] = sb; + IEventDispatcher(_strand).addEventListener("valueChange", deferredBindingsHandler); + } + } + } + else + { + makeGenericBinding(binding, i, watchers); + } + } + } + + private function makeGenericBinding(binding:Object, index:int, watchers:Object):void + { + var gb:GenericBinding = new GenericBinding(); + gb.setDocument(_strand); + gb.destinationData = binding.destination; + gb.destinationFunction = binding.destFunc; + gb.source = binding.source; + setupWatchers(gb, index, watchers.watchers, null); + } + + private function setupWatchers(gb:GenericBinding, index:int, watchers:Array, parentWatcher:WatcherBase):void + { + var n:int = watchers.length; + for (var i:int = 0; i < n; i++) + { + var watcher:Object = watchers[i]; + if (watcher.bindings.indexOf(index) != -1) + { + var type:String = watcher.type; + switch (type) + { + case "property": + { + var pw:PropertyWatcher = new PropertyWatcher(this, + watcher.propertyName, + watcher.eventNames, + watcher.getterFunction); + watcher.watcher = pw; + if (parentWatcher) + pw.parentChanged(parentWatcher.value); + else + pw.parentChanged(_strand); + if (parentWatcher) + parentWatcher.addChild(pw); + if (watcher.children == null) + pw.addBinding(gb); + break; + } + } + if (watcher.children) + { + setupWatchers(gb, index, watcher.children, watcher.watcher); + } + } + } + } + + private function decodeWatcher(bindingData:Array):Object + { + var watcherMap:Object = {}; + var watchers:Array = []; + var n:int = bindingData.length; + var index:int = 0; + var watcherData:Object; + while (index < n) + { + var watcherIndex:int = bindingData[index++]; + var type:int = bindingData[index++]; + switch (type) + { + case 0: + { + watcherData = { type: "function" }; + watcherData.functionName = bindingData[index++]; + watcherData.paramFunction = bindingData[index++]; + watcherData.eventNames = bindingData[index++]; + watcherData.bindings = bindingData[index++]; + break; + } + case 1: + { + watcherData = { type: "static" }; + watcherData.propertyName = bindingData[index++]; + watcherData.eventNames = bindingData[index++]; + watcherData.bindings = bindingData[index++]; + watcherData.getterFunction = bindingData[index++]; + watcherData.parentObj = bindingData[index++]; + watcherMap[watcherData.propertyName] = watcherData; + break; + } + case 2: + { + watcherData = { type: "property" }; + watcherData.propertyName = bindingData[index++]; + watcherData.eventNames = bindingData[index++]; + watcherData.bindings = bindingData[index++]; + watcherData.getterFunction = bindingData[index++]; + watcherMap[watcherData.propertyName] = watcherData; + break; + } + case 3: + { + watcherData = { type: "xml" }; + watcherData.propertyName = bindingData[index++]; + watcherData.bindings = bindingData[index++]; + watcherMap[watcherData.propertyName] = watcherData; + break; + } + } + watcherData.children = bindingData[index++]; + if (watcherData.children != null) + { + watcherData.children = decodeWatcher(watcherData.children); + } + watcherData.index = watcherIndex; + watchers.push(watcherData); + } + return { watchers: watchers, watcherMap: watcherMap }; + } + + private var deferredBindings:Object = {}; + private function deferredBindingsHandler(event:Event):void + { + for (var p:String in deferredBindings) + { + if (_strand[p] != null) + { + var destination:IStrand = _strand[p] as IStrand; + destination.addBead(deferredBindings[p]); + delete deferredBindings[p]; + } + } + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/Application.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/Application.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/Application.as new file mode 100644 index 0000000..2214325 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/Application.as @@ -0,0 +1,140 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.createjs +{ + import flash.display.DisplayObject; + import flash.display.Sprite; + import flash.display.StageAlign; + import flash.display.StageScaleMode; + import flash.events.IOErrorEvent; + + import org.apache.flex.core.IBead; + import org.apache.flex.core.IFlexInfo; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.IValuesImpl; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.createjs.core.ViewBase; + import org.apache.flex.events.Event; + import org.apache.flex.utils.MXMLDataInterpreter; + + //-------------------------------------- + // Events + //-------------------------------------- + + /** + * Dispatched at startup. + */ + [Event(name="initialize", type="org.apache.flex.events.Event")] + + public class Application extends Sprite implements IStrand, IFlexInfo + { + public function Application() + { + super(); + if (stage) + { + stage.align = StageAlign.TOP_LEFT; + stage.scaleMode = StageScaleMode.NO_SCALE; + } + + loaderInfo.addEventListener(flash.events.Event.INIT, initHandler); + } + + private function initHandler(event:flash.events.Event):void + { + MXMLDataInterpreter.generateMXMLProperties(this, MXMLProperties); + + ValuesManager.valuesImpl = valuesImpl; + ValuesManager.valuesImpl.init(this); + + dispatchEvent(new Event("initialize")); + + addElement(initialView); + initialView.initUI(model); + dispatchEvent(new Event("viewChanged")); + } + + public var valuesImpl:IValuesImpl; + + public var initialView:ViewBase; + + public var model:Object; + + public var controller:Object; + + public function get MXMLDescriptor():Array + { + return null; + } + + public function get MXMLProperties():Array + { + return null; + } + + // beads declared in MXML are added to the strand. + // from AS, just call addBead() + public var beads:Array; + + private var _beads:Vector.; + public function addBead(bead:IBead):void + { + if (!_beads) + _beads = new Vector.; + _beads.push(bead); + bead.strand = this; + } + + public function getBeadByType(classOrInterface:Class):IBead + { + for each (var bead:IBead in _beads) + { + if (bead is classOrInterface) + return bead; + } + return null; + } + + public function removeBead(value:IBead):IBead + { + var n:int = _beads.length; + for (var i:int = 0; i < n; i++) + { + var bead:IBead = _beads[i]; + if (bead == value) + { + _beads.splice(i, 1); + return bead; + } + } + return null; + } + + public function get info():Object + { + return {}; + } + + public function addElement(c:Object):void + { + addChild(c as DisplayObject); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/core/UIBase.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/core/UIBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/core/UIBase.as new file mode 100644 index 0000000..d0761a0 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/core/UIBase.as @@ -0,0 +1,141 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.createjs.core +{ + import flash.display.DisplayObjectContainer; + import flash.display.Sprite; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IBead; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + + public class UIBase extends Sprite implements IStrand, IEventDispatcher + { + public function UIBase() + { + super(); + } + + private var _width:Number = 0; + override public function get width():Number + { + return _width; + } + override public function set width(value:Number):void + { + if (_width != value) + { + _width = value; + dispatchEvent(new Event("widthChanged")); + } + } + protected function get $width():Number + { + return super.width; + } + + private var _height:Number = 0; + override public function get height():Number + { + return _height; + } + override public function set height(value:Number):void + { + if (_height != value) + { + _height = value; + dispatchEvent(new Event("heightChanged")); + } + } + protected function get $height():Number + { + return super.height; + } + + private var _model:IBeadModel; + public function get model():IBeadModel + { + return _model; + } + public function set model(value:IBeadModel):void + { + if (_model != value) + { + addBead(value as IBead); + dispatchEvent(new Event("modelChanged")); + } + } + + private var _id:String; + public function get id():String + { + return _id; + } + public function set id(value:String):void + { + if (_id != value) + { + _id = value; + dispatchEvent(new Event("idChanged")); + } + } + + // beads declared in MXML are added to the strand. + // from AS, just call addBead() + public var beads:Array; + + private var _beads:Vector.; + public function addBead(bead:IBead):void + { + if (!_beads) + _beads = new Vector.; + _beads.push(bead); + if (bead is IBeadModel) + _model = bead as IBeadModel; + bead.strand = this; + } + + public function getBeadByType(classOrInterface:Class):IBead + { + for each (var bead:IBead in _beads) + { + if (bead is classOrInterface) + return bead; + } + return null; + } + + public function removeBead(value:IBead):IBead + { + var n:int = _beads.length; + for (var i:int = 0; i < n; i++) + { + var bead:IBead = _beads[i]; + if (bead == value) + { + _beads.splice(i, 1); + return bead; + } + } + return null; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/core/ViewBase.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/core/ViewBase.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/core/ViewBase.as new file mode 100644 index 0000000..195821f --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/core/ViewBase.as @@ -0,0 +1,86 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.createjs.core +{ + import flash.display.DisplayObject; + + import org.apache.flex.core.IParent; + import org.apache.flex.core.IUIBase; + import org.apache.flex.events.Event; + import org.apache.flex.utils.MXMLDataInterpreter; + + [DefaultProperty("mxmlContent")] + public class ViewBase extends UIBase implements IParent + { + public function ViewBase() + { + super(); + } + + public function initUI(model:Object):void + { + _applicationModel = model; + dispatchEvent(new Event("modelChanged")); + MXMLDataInterpreter.generateMXMLProperties(this, MXMLProperties); + MXMLDataInterpreter.generateMXMLInstances(this, this, MXMLDescriptor); + } + + public function get MXMLDescriptor():Array + { + return null; + } + + public function get MXMLProperties():Array + { + return null; + } + + public var mxmlContent:Array; + + private var _applicationModel:Object; + + [Bindable("modelChanged")] + public function get applicationModel():Object + { + return _applicationModel; + } + + public function addElement(c:Object):void + { + addChild(c as DisplayObject); + } + + public function addElementAt(c:Object, index:int):void + { + addChildAt(c as DisplayObject, index); + } + + public function getElementIndex(c:Object):int + { + return getChildIndex(c as DisplayObject); + } + + public function removeElement(c:Object):void + { + removeChild(c as DisplayObject); + } + + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/CheckBox.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/CheckBox.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/CheckBox.as new file mode 100644 index 0000000..b4dc469 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/CheckBox.as @@ -0,0 +1,26 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.createjs.staticControls +{ + import org.apache.flex.html.staticControls.CheckBox; + + public class CheckBox extends org.apache.flex.html.staticControls.CheckBox + { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/Label.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/Label.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/Label.as new file mode 100644 index 0000000..fb8fb7e --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/Label.as @@ -0,0 +1,27 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.createjs.staticControls +{ + import org.apache.flex.html.staticControls.Label; + + public class Label extends org.apache.flex.html.staticControls.Label + { + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/TextButton.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/TextButton.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/TextButton.as new file mode 100644 index 0000000..6764b22 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/createjs/staticControls/TextButton.as @@ -0,0 +1,52 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.createjs.staticControls +{ + import flash.display.DisplayObject; + + import org.apache.flex.core.ITextModel; + import org.apache.flex.html.staticControls.Button; + + public class TextButton extends Button + { + public function TextButton(upState:DisplayObject=null, overState:DisplayObject=null, downState:DisplayObject=null, hitTestState:DisplayObject=null) + { + super(upState, overState, downState, hitTestState); + } + + public function get text():String + { + return ITextModel(model).text; + } + public function set text(value:String):void + { + ITextModel(model).text = value; + } + + public function get html():String + { + return ITextModel(model).html; + } + public function set html(value:String):void + { + ITextModel(model).html = value; + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/data/ICollection.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/data/ICollection.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/data/ICollection.as new file mode 100644 index 0000000..b1d706f --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/data/ICollection.as @@ -0,0 +1,25 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.data +{ + public interface ICollection + { + function getItemAt(index:int):Object + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/66246d8a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/data/IStringCollection.as ---------------------------------------------------------------------- diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/data/IStringCollection.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/data/IStringCollection.as new file mode 100644 index 0000000..b978a58 --- /dev/null +++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/data/IStringCollection.as @@ -0,0 +1,25 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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.flex.data +{ + public interface IStringCollection + { + function getItemAt(index:int):String + } +} \ No newline at end of file