flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [11/14] git commit: [flex-asjs] [refs/heads/develop] - states with transitions
Date Fri, 31 Oct 2014 22:08:46 GMT
states with transitions


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

Branch: refs/heads/develop
Commit: a567ab9b8af808e3b2c905c541b25a9204597d22
Parents: f52c937
Author: Alex Harui <aharui@apache.org>
Authored: Fri Oct 31 14:23:41 2014 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Oct 31 15:08:15 2014 -0700

----------------------------------------------------------------------
 .../as/projects/FlexJSJX/src/FlexJSJXClasses.as |   1 +
 .../flex/core/StatesWithTransitionsImpl.as      | 279 +++++++++++++++++++
 .../src/org/apache/flex/effects/Effect.as       |  24 ++
 .../src/org/apache/flex/effects/IEffect.as      |  22 ++
 .../src/org/apache/flex/effects/Move.as         |  66 ++++-
 .../src/org/apache/flex/core/IStatesObject.as   |  13 +
 6 files changed, 391 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a567ab9b/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as b/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as
index 2c8c944..423ac18 100644
--- a/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as
+++ b/frameworks/as/projects/FlexJSJX/src/FlexJSJXClasses.as
@@ -77,6 +77,7 @@ internal class FlexJSJXClasses
     import org.apache.flex.html.beads.TitleBarMeasurementBead; TitleBarMeasurementBead;
 
     import org.apache.flex.core.ParentDocumentBead; ParentDocumentBead;
+    import org.apache.flex.core.StatesWithTransitionsImpl; StatesWithTransitionsImpl;
 }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a567ab9b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/core/StatesWithTransitionsImpl.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/core/StatesWithTransitionsImpl.as
b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/core/StatesWithTransitionsImpl.as
new file mode 100644
index 0000000..9150d1e
--- /dev/null
+++ b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/core/StatesWithTransitionsImpl.as
@@ -0,0 +1,279 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.AddItems;
+    import mx.states.SetEventHandler;
+    import mx.states.SetProperty;
+    import mx.states.State;
+    
+    import org.apache.flex.core.IParent;
+    import org.apache.flex.core.IStatesObject;
+    import org.apache.flex.effects.Effect;
+    import org.apache.flex.events.Event;
+    import org.apache.flex.events.EventDispatcher;
+    import org.apache.flex.events.IEventDispatcher;
+    import org.apache.flex.events.ValueChangeEvent;
+    import org.apache.flex.states.Transition;
+    import org.apache.flex.utils.MXMLDataInterpreter;
+	
+    /**
+     *  The StatesWithTransitionsImpl class implements a set of
+     *  view state functionality that includes transitions between states.
+     *  It only supports AddItems and SetProperty and SetEventHandler 
+     *  changes at this time.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+     */
+	public class StatesWithTransitionsImpl extends EventDispatcher implements IStatesImpl, IBead
+	{
+        /**
+         *  Constructor.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+		public function StatesWithTransitionsImpl()
+		{
+			super();
+		}
+        
+        private var _strand:IStrand;
+        
+        private var sawInitComplete:Boolean;
+        
+        /**
+         *  @copy org.apache.flex.core.IBead#strand
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        public function set strand(value:IStrand):void
+        {
+            _strand = value;
+            IEventDispatcher(_strand).addEventListener("currentStateChange", stateChangeHandler);
+            IEventDispatcher(_strand).addEventListener("initComplete", initialStateHandler);
+        }
+        
+        private function initialStateHandler(event:org.apache.flex.events.Event):void
+        {
+            sawInitComplete = true;
+            stateChangeHandler(new ValueChangeEvent("currentStateChange", false, false, null,

+                IStatesObject(_strand).currentState));
+        }		
+     
+        private function stateChangeHandler(event:ValueChangeEvent):void
+        {
+            if (!sawInitComplete)
+                return;
+            
+            var doc:IStatesObject = _strand as IStatesObject;
+            var transitions:Array = doc.transitions;
+            if (transitions && transitions.length > 0)
+            {
+                for each (var t:Transition in transitions)
+                {
+                    if (t.fromState == "*" || t.fromState == event.oldValue)
+                    {
+                        if (t.toState == "*" || t.toState == event.newValue)
+                        {
+                            transitionEffects = t.effects.slice();
+                            for each (var e:Effect in transitionEffects)
+                            {
+                                e.captureStartValues();
+                            }
+                            break;
+                        }
+                    }
+                }
+            }
+            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;
+                }
+            }
+            if (transitionEffects && transitionEffects.length > 0)
+            {
+                for each (e in transitionEffects)
+                {
+                    e.captureEndValues();
+                }
+            }
+            var playingTransition:Boolean;
+            if (transitionEffects && transitionEffects.length > 0)
+            {
+                playingTransition = true;
+                for each (e in transitionEffects)
+                {
+                    e.addEventListener(Effect.EFFECT_END, effectEndHandler);
+                    e.play();
+                }
+            }
+            if (!playingTransition)
+                doc.dispatchEvent(new Event("stateChangeComplete"));
+        }
+        
+        private var transitionEffects:Array;
+        
+        private function effectEndHandler(event:Event):void
+        {
+            var n:int = transitionEffects.length;
+            for (var i:int = 0; i < n; i++)   
+            {
+                if (transitionEffects[i] == event.target)
+                    transitionEffects.splice(i, 1);
+            }
+            if (transitionEffects.length == 0)
+            {
+                transitionEffects = null;
+                var doc:IStatesObject = _strand as IStatesObject;
+                doc.dispatchEvent(new Event("stateChangeComplete"));
+            }
+        }
+            
+        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:Object in ai.items)
+                    {
+                        var parent:IParent = item.parent as IParent;
+                        parent.removeElement(item);
+                    }
+                    if (parent is IContainer)
+                        IContainer(parent).childrenAdded();
+                }
+                else if (o is SetProperty)
+                {
+                    var sp:SetProperty = SetProperty(o);
+                    if (sp.target != null)
+                        sp.document[sp.target][sp.name] = sp.previousValue;
+                    else
+                        sp.document[sp.name] = sp.previousValue;
+                }
+                else if (o is SetEventHandler)
+                {
+                    var seh:SetEventHandler = SetEventHandler(o);
+                    if (seh.target != null)
+                    {
+                        seh.document[seh.target].removeEventListener(seh.name, seh.handlerFunction);
+                    }
+                    else
+                    {
+                        seh.document.removeEventListener(seh.name, seh.handlerFunction);
+                    }
+                }
+            }
+        }
+        
+        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 = ai.itemsDescriptor.items as Array;
+                        if (ai.items == null)
+                        {
+                            ai.items = 
+                                MXMLDataInterpreter.generateMXMLArray(ai.document,
+                                    null, ai.itemsDescriptor.descriptor);
+                            ai.itemsDescriptor.items = ai.items;
+                        }
+                    }
+                    for each (var item:Object in ai.items)
+                    {
+                        var parent:IParent = ai.document as IParent;
+                        if (ai.destination != null)
+                            parent = parent[ai.destination] as IParent;
+                        if (ai.relativeTo != null)
+                        {
+                            var child:Object = ai.document[ai.relativeTo];
+                            parent = child.parent as IParent;
+                            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);
+                    if (sp.target != null)
+                    {
+                        sp.previousValue = sp.document[sp.target][sp.name];
+                        sp.document[sp.target][sp.name] = sp.value;
+                    }
+                    else
+                    {
+                        sp.previousValue = sp.document[sp.name];
+                        sp.document[sp.name] = sp.value;                        
+                    }
+                }
+                else if (o is SetEventHandler)
+                {
+                    var seh:SetEventHandler = SetEventHandler(o);
+                    if (seh.target != null)
+                    {
+                        seh.document[seh.target].addEventListener(seh.name, seh.handlerFunction);
+                    }
+                    else
+                    {
+                        seh.document.addEventListener(seh.name, seh.handlerFunction);
+                    }
+                }
+            }            
+        }
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a567ab9b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Effect.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Effect.as b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Effect.as
index 8d37970..7fabe6a 100644
--- a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Effect.as
+++ b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Effect.as
@@ -234,6 +234,30 @@ public class Effect extends EventDispatcher implements IEffect
     public function resume():void
     {
     }   
+
+    /**
+     *  @copy org.apache.flex.effects.IEffect#captureStartValues
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function captureStartValues():void
+    {
+    }   
+
+    /**
+     *  @copy org.apache.flex.effects.IEffect#captureEndValues
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    public function captureEndValues():void
+    {
+    }   
 }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a567ab9b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/IEffect.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/IEffect.as b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/IEffect.as
index 87c48e9..f5b940c 100644
--- a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/IEffect.as
+++ b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/IEffect.as
@@ -109,6 +109,28 @@ public interface IEffect extends IEventDispatcher
      *  @productversion Flex 3
      */
     function resume():void;
+
+    /**
+     *  Tries to compute initial values
+     *  for effect 
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    function captureStartValues():void;
+
+    /**
+     *  Tries to compute final values
+     *  for effect 
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Flex 3
+     */
+    function captureEndValues():void;
 }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a567ab9b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Move.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Move.as b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Move.as
index 74cf73c..2a42b19 100644
--- a/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Move.as
+++ b/frameworks/as/projects/FlexJSJX/src/org/apache/flex/effects/Move.as
@@ -104,10 +104,22 @@ public class Move extends Tween implements IDocument
 	
 	/**
 	 *  @private
-	 *  The staring y.
+	 *  The starting y.
 	 */
 	private var yStart:Number;
 
+    /**
+     *  @private
+     *  The total change for x.
+     */
+    private var xMove:Number;
+    
+    /**
+     *  @private
+     *  The total change for y.
+     */
+    private var yMove:Number;
+    
 	/**
 	 *  Starting x value.  If NaN, the current x value is used
      */
@@ -163,10 +175,12 @@ public class Move extends Tween implements IDocument
         if (isNaN(xBy))
         {
     		if (isNaN(xTo))
-    			xBy = 0;
+                xMove = 0;
     		else
-    			xBy = xTo - xStart;
+                xMove = xTo - xStart;
         }
+        else
+            xMove = xBy;
         
 		if (isNaN(yFrom))
 			yStart = actualTarget.y;
@@ -175,28 +189,52 @@ public class Move extends Tween implements IDocument
         if (isNaN(yBy))
         {
     		if (isNaN(yTo))
-    			yBy = 0;
+                yMove = 0;
     		else
-    			yBy = yTo - yStart;
-        }			
+                yMove = yTo - yStart;
+        }
+        else
+            yMove = yBy;
+        
 		super.play();
 	}
 
 	public function onTweenUpdate(value:Number):void
 	{
-		if (xBy)
-			actualTarget.x = xStart + value * xBy;
-		if (yBy)
-			actualTarget.y = yStart + value * yBy;
+		if (xMove)
+			actualTarget.x = xStart + value * xMove;
+		if (yMove)
+			actualTarget.y = yStart + value * yMove;
 	}
 	
 	public function onTweenEnd(value:Number):void
 	{
-		if (xBy)
-			actualTarget.x = xStart + xBy;
-		if (yBy)
-			actualTarget.y = yStart + yBy;
+		if (xMove)
+			actualTarget.x = xStart + xMove;
+		if (yMove)
+			actualTarget.y = yStart + yMove;
+        
 	}
+    
+    override public function captureStartValues():void
+    {
+        if (target != null)
+        {
+            actualTarget = document[target];
+            xFrom = actualTarget.x;
+            yFrom = actualTarget.y;
+        }
+    }
+    
+    override public function captureEndValues():void
+    {
+        if (target != null)
+        {
+            actualTarget = document[target];
+            xTo = actualTarget.x;
+            yTo = actualTarget.y;
+        }
+    }
 }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/a567ab9b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IStatesObject.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IStatesObject.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IStatesObject.as
index bc2f716..be11ac7 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IStatesObject.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IStatesObject.as
@@ -52,5 +52,18 @@ package org.apache.flex.core
          */
         function get currentState():String;
 
+        /**
+         *  The array of view state transitions. 
+         *  These should
+         *  be instances of org.apache.flex.states.Transition.
+         *  
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion FlexJS 0.0
+         */
+        function get transitions():Array;
+        
+
 	}
 }
\ No newline at end of file


Mime
View raw message