You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2013/06/14 18:52:56 UTC

[2/5] git commit: [flex-asjs] [refs/heads/develop] - Support states in FlexJS. Must use mx:States because of MXMLC hard-coded expectations, but includeIn and property.state syntax now works

Support states in FlexJS.  Must use mx:States because of MXMLC hard-coded expectations, but includeIn and property.state syntax now works


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/fe9a9ac1
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/fe9a9ac1
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/fe9a9ac1

Branch: refs/heads/develop
Commit: fe9a9ac13212c4ad2d8cfed91383c4d5367a4439
Parents: c557d7a
Author: Alex Harui <ah...@apache.org>
Authored: Thu May 30 22:29:09 2013 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Thu Jun 13 23:23:21 2013 -0700

----------------------------------------------------------------------
 frameworks/as/compile-config.xml                |   5 +
 frameworks/as/defaults.css                      |   2 +-
 frameworks/as/mx-manifest.xml                   |  26 ++++
 frameworks/as/src/mx/states/AddItems.as         |  65 +++++++++
 frameworks/as/src/mx/states/SetProperty.as      |  60 ++++++++
 frameworks/as/src/mx/states/State.as            |  34 +++++
 .../as/src/org/apache/flex/core/IStatesImpl.as  |  26 ++++
 .../org/apache/flex/core/SimpleStatesImpl.as    | 137 +++++++++++++++++++
 .../as/src/org/apache/flex/core/UIBase.as       |  39 ++++++
 .../as/src/org/apache/flex/core/ViewBase.as     |  56 +++++++-
 .../flex/html/staticControls/Container.as       |  17 ++-
 11 files changed, 463 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/fe9a9ac1/frameworks/as/compile-config.xml
----------------------------------------------------------------------
diff --git a/frameworks/as/compile-config.xml b/frameworks/as/compile-config.xml
index f96ddcf..aa41d8e 100644
--- a/frameworks/as/compile-config.xml
+++ b/frameworks/as/compile-config.xml
@@ -35,6 +35,10 @@
                 <manifest>basic-manifest.xml</manifest>
             </namespace>
             <namespace>
+                <uri>library://ns.adobe.com/flex/mx</uri>
+                <manifest>mx-manifest.xml</manifest>
+            </namespace>
+            <namespace>
                 <uri>library://ns.apache.org/flexjs/html5</uri>
                 <manifest>html5-manifest.xml</manifest>
             </namespace>
@@ -66,6 +70,7 @@
     
     <include-namespaces>
         <uri>library://ns.apache.org/flexjs/basic</uri>
+        <uri>library://ns.adobe.com/flex/mx</uri>
         <uri>library://ns.apache.org/flexjs/html5</uri>
         <uri>library://ns.apache.org/flexjs/jquery</uri>
         <uri>library://ns.apache.org/flexjs/createjs</uri>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/fe9a9ac1/frameworks/as/defaults.css
----------------------------------------------------------------------
diff --git a/frameworks/as/defaults.css b/frameworks/as/defaults.css
index a68bb5f..04c0492 100644
--- a/frameworks/as/defaults.css
+++ b/frameworks/as/defaults.css
@@ -58,7 +58,7 @@ global
 {
     ITextBead: ClassReference("org.apache.flex.html.staticControls.beads.TextFieldBead");
     ITextModel: ClassReference("org.apache.flex.html.staticControls.beads.models.TextModel");
-
+    IStatesImpl: ClassReference("org.apache.flex.core.SimpleStatesImpl");
 }
 
 CheckBox

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/fe9a9ac1/frameworks/as/mx-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/as/mx-manifest.xml b/frameworks/as/mx-manifest.xml
new file mode 100644
index 0000000..6654ace
--- /dev/null
+++ b/frameworks/as/mx-manifest.xml
@@ -0,0 +1,26 @@
+<?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.
+
+-->
+
+
+<componentPackage>
+
+    <component id="State" class="mx.states.State"/>
+
+</componentPackage>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/fe9a9ac1/frameworks/as/src/mx/states/AddItems.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/mx/states/AddItems.as b/frameworks/as/src/mx/states/AddItems.as
new file mode 100644
index 0000000..dc0049a
--- /dev/null
+++ b/frameworks/as/src/mx/states/AddItems.as
@@ -0,0 +1,65 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+// shim the mx classes for states
+package mx.states
+{
+    import org.apache.flex.core.IDocument;
+    
+	public class AddItems implements IDocument
+	{
+		public function AddItems()
+		{
+			super();
+		}
+		
+        public var items:Array;
+        
+		public var itemsDescriptor:Array;     
+
+        public var destination:String;
+        
+        public var propertyName:String;
+        
+        public var position:String;
+        
+        public var relativeTo:String;
+        
+        public var document:Object;
+        
+        public function setDocument(document:Object, id:String = null):void
+        {
+            this.document = document;
+        }
+        
+        /**
+         * @private 
+         * Initialize this object from a descriptor.
+         */
+        public function initializeFromObject(properties:Object):Object
+        {
+            for (var p:String in properties)
+            {
+                this[p] = properties[p];
+            }
+            
+            return Object(this);
+        }
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/fe9a9ac1/frameworks/as/src/mx/states/SetProperty.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/mx/states/SetProperty.as b/frameworks/as/src/mx/states/SetProperty.as
new file mode 100644
index 0000000..78e0a73
--- /dev/null
+++ b/frameworks/as/src/mx/states/SetProperty.as
@@ -0,0 +1,60 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.
+//
+////////////////////////////////////////////////////////////////////////////////
+// shim the mx classes for states
+package mx.states
+{
+    import org.apache.flex.core.IDocument;
+    
+	public class SetProperty implements IDocument
+	{
+		public function SetProperty()
+		{
+			super();
+		}
+		
+        public var target:String;
+        
+        public var name:String;
+        
+        public var value:*;
+
+        public var previousValue:*;
+        
+        public var document:Object;
+        
+        public function setDocument(document:Object, id:String = null):void
+        {
+            this.document = document;
+        }
+        
+        /**
+         * @private 
+         * Initialize this object from a descriptor.
+         */
+        public function initializeFromObject(properties:Object):Object
+        {
+            for (var p:String in properties)
+            {
+                this[p] = properties[p];
+            }
+            
+            return Object(this);
+        }
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/fe9a9ac1/frameworks/as/src/mx/states/State.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/mx/states/State.as b/frameworks/as/src/mx/states/State.as
new file mode 100644
index 0000000..3a38d54
--- /dev/null
+++ b/frameworks/as/src/mx/states/State.as
@@ -0,0 +1,34 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+// shim the mx classes for states
+package mx.states
+{
+	public class State
+	{
+		public function State(properties:Object = null)
+		{
+			super();
+		}
+		
+		public var name:String;
+        
+        public var overrides:Array;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/fe9a9ac1/frameworks/as/src/org/apache/flex/core/IStatesImpl.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/core/IStatesImpl.as b/frameworks/as/src/org/apache/flex/core/IStatesImpl.as
new file mode 100644
index 0000000..152fe8f
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/core/IStatesImpl.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.core
+{
+	import org.apache.flex.events.IEventDispatcher;
+
+	public interface IStatesImpl extends IEventDispatcher, IBead
+	{
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/fe9a9ac1/frameworks/as/src/org/apache/flex/core/SimpleStatesImpl.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/core/SimpleStatesImpl.as b/frameworks/as/src/org/apache/flex/core/SimpleStatesImpl.as
new file mode 100644
index 0000000..a5f6a14
--- /dev/null
+++ b/frameworks/as/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.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:Object = ai.document[ai.destination];
+                        if (item is UIBase)
+                            UIBase(item).removeFromParent(parent);
+                        parent.dispatchEvent(new Event("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:Object = ai.document[ai.destination];
+                        if (ai.relativeTo != null)
+                        {
+                            var child:Object = ai.document[ai.relativeTo];
+                            var index:int = UIBase(child).getIndexInParent(parent);
+                            if (ai.position == "after")
+                                index++;
+                            if (item is UIBase)
+                                UIBase(item).addToParentAt(parent, index);
+                        }
+                        else
+                        {
+                            if (item is UIBase)
+                                UIBase(item).addToParent(parent);
+                        }
+                        parent.dispatchEvent(new Event("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/fe9a9ac1/frameworks/as/src/org/apache/flex/core/UIBase.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/core/UIBase.as b/frameworks/as/src/org/apache/flex/core/UIBase.as
index 34187ee..fc073fa 100644
--- a/frameworks/as/src/org/apache/flex/core/UIBase.as
+++ b/frameworks/as/src/org/apache/flex/core/UIBase.as
@@ -175,6 +175,30 @@ package org.apache.flex.core
             else
     			p.addChild(this);
 		}
+        
+        public function addToParentAt(p:Object, index:int):void
+        {
+            if (p is UIBase)
+                UIBase(p).internalAddChildAt(this, index);
+            else
+                p.addChild(this, index);
+        }
+        
+        public function getIndexInParent(p:Object):int
+        {
+            if (p is UIBase)
+                return UIBase(p).internalGetChildIndex(this);
+            else
+                return p.getChildIndex(this);
+        }
+
+        public function removeFromParent(p:Object):void
+        {
+            if (p is UIBase)
+                UIBase(p).internalRemoveChild(this);
+            else
+                p.removeChild(this);
+        }
 		
 		/**
 		 * Used internally by addToParent() implementations
@@ -190,6 +214,21 @@ package org.apache.flex.core
 			addChild(child as DisplayObject);
 		}
 
+        public function internalAddChildAt(child:Object, index:int):void
+        {
+            addChildAt(child as DisplayObject, index);
+        }
+        
+        public function internalGetChildIndex(child:Object):int
+        {
+            return getChildIndex(child as DisplayObject);
+        }
+        
+        public function internalRemoveChild(child:Object):void
+        {
+            removeChild(child as DisplayObject);
+        }
+
         /*
         public function addToParent(p:Object):void
         {

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/fe9a9ac1/frameworks/as/src/org/apache/flex/core/ViewBase.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/core/ViewBase.as b/frameworks/as/src/org/apache/flex/core/ViewBase.as
index f9b96f1..177a366 100644
--- a/frameworks/as/src/org/apache/flex/core/ViewBase.as
+++ b/frameworks/as/src/org/apache/flex/core/ViewBase.as
@@ -18,8 +18,11 @@
 ////////////////////////////////////////////////////////////////////////////////
 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.Event;
+	import org.apache.flex.events.ValueChangeEvent;
 	import org.apache.flex.utils.MXMLDataInterpreter;
 
 	[Event(name="initComplete", type="org.apache.flex.events.Event")]
@@ -64,5 +67,54 @@ package org.apache.flex.core
 		{
 			return _applicationModel;
 		}
-	}
+
+        private var _states:Array;
+        
+        public function get states():Array
+        {
+            return _states;
+        }
+        public function set states(value:Array):void
+        {
+            _states = value;
+            if (getBeadByType(IStatesImpl) == null)
+                addBead(new (ValuesManager.valuesImpl.getValue(this, "iStatesImpl")) as IBead);
+            
+        }
+        
+        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/fe9a9ac1/frameworks/as/src/org/apache/flex/html/staticControls/Container.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/Container.as b/frameworks/as/src/org/apache/flex/html/staticControls/Container.as
index 35b2d19..6e31c7f 100644
--- a/frameworks/as/src/org/apache/flex/html/staticControls/Container.as
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/Container.as
@@ -60,7 +60,22 @@ package org.apache.flex.html.staticControls
 			actualParent.addChild(child as DisplayObject);
 		}
 
-		public function getChildren():Array
+        override public function internalAddChildAt(child:Object, index:int):void
+        {
+            actualParent.addChildAt(child as DisplayObject, index);
+        }
+        
+        override public function internalGetChildIndex(child:Object):int
+        {
+            return actualParent.getChildIndex(child as DisplayObject);
+        }
+        
+        override public function internalRemoveChild(child:Object):void
+        {
+            actualParent.removeChild(child as DisplayObject);
+        }
+
+        public function getChildren():Array
 		{
 			var children:Array = [];
 			var n:int = actualParent.numChildren;