home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Adobe Air 1.5 / AdobeAIRInstaller.exe / setup.swf / scripts / mx / managers / LayoutManager.as < prev    next >
Encoding:
Text File  |  2008-10-29  |  14.5 KB  |  422 lines

  1. package mx.managers
  2. {
  3.    import flash.display.Stage;
  4.    import flash.events.Event;
  5.    import flash.events.EventDispatcher;
  6.    import mx.core.ApplicationGlobals;
  7.    import mx.core.UIComponent;
  8.    import mx.core.mx_internal;
  9.    import mx.events.FlexEvent;
  10.    import mx.managers.layoutClasses.PriorityQueue;
  11.    
  12.    use namespace mx_internal;
  13.    
  14.    public class LayoutManager extends EventDispatcher implements ILayoutManager
  15.    {
  16.       private static var instance:LayoutManager;
  17.       
  18.       mx_internal static const VERSION:String = "3.0.0.0";
  19.       
  20.       private var invalidateClientPropertiesFlag:Boolean = false;
  21.       
  22.       private var invalidateDisplayListQueue:PriorityQueue;
  23.       
  24.       private var updateCompleteQueue:PriorityQueue;
  25.       
  26.       private var invalidateDisplayListFlag:Boolean = false;
  27.       
  28.       private var invalidateClientSizeFlag:Boolean = false;
  29.       
  30.       private var invalidateSizeQueue:PriorityQueue;
  31.       
  32.       private var originalFrameRate:Number;
  33.       
  34.       private var invalidatePropertiesFlag:Boolean = false;
  35.       
  36.       private var invalidatePropertiesQueue:PriorityQueue;
  37.       
  38.       private var invalidateSizeFlag:Boolean = false;
  39.       
  40.       private var callLaterPending:Boolean = false;
  41.       
  42.       private var _usePhasedInstantiation:Boolean = false;
  43.       
  44.       private var callLaterObject:UIComponent;
  45.       
  46.       private var targetLevel:int = 2147483647;
  47.       
  48.       public function LayoutManager()
  49.       {
  50.          updateCompleteQueue = new PriorityQueue();
  51.          invalidatePropertiesQueue = new PriorityQueue();
  52.          invalidateSizeQueue = new PriorityQueue();
  53.          invalidateDisplayListQueue = new PriorityQueue();
  54.          super();
  55.       }
  56.       
  57.       public static function getInstance() : LayoutManager
  58.       {
  59.          if(!instance)
  60.          {
  61.             instance = new LayoutManager();
  62.          }
  63.          return instance;
  64.       }
  65.       
  66.       public function set usePhasedInstantiation(param1:Boolean) : void
  67.       {
  68.          var _loc2_:Stage = null;
  69.          if(_usePhasedInstantiation != param1)
  70.          {
  71.             _usePhasedInstantiation = param1;
  72.             _loc2_ = SystemManagerGlobals.topLevelSystemManagers[0].stage;
  73.             if(param1)
  74.             {
  75.                originalFrameRate = _loc2_.frameRate;
  76.                _loc2_.frameRate = 1000;
  77.             }
  78.             else
  79.             {
  80.                _loc2_.frameRate = originalFrameRate;
  81.             }
  82.          }
  83.       }
  84.       
  85.       private function waitAFrame() : void
  86.       {
  87.          callLaterObject.callLater(doPhasedInstantiation);
  88.       }
  89.       
  90.       public function validateClient(param1:ILayoutManagerClient, param2:Boolean = false) : void
  91.       {
  92.          var _loc3_:ILayoutManagerClient = null;
  93.          var _loc4_:int = 0;
  94.          var _loc5_:Boolean = false;
  95.          var _loc6_:int = targetLevel;
  96.          if(targetLevel == int.MAX_VALUE)
  97.          {
  98.             targetLevel = param1.nestLevel;
  99.          }
  100.          while(!_loc5_)
  101.          {
  102.             _loc5_ = true;
  103.             _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  104.             while(_loc3_)
  105.             {
  106.                _loc3_.validateProperties();
  107.                if(!_loc3_.updateCompletePendingFlag)
  108.                {
  109.                   updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  110.                   _loc3_.updateCompletePendingFlag = true;
  111.                }
  112.                _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  113.             }
  114.             if(invalidatePropertiesQueue.isEmpty())
  115.             {
  116.                invalidatePropertiesFlag = false;
  117.                invalidateClientPropertiesFlag = false;
  118.             }
  119.             _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  120.             while(_loc3_)
  121.             {
  122.                _loc3_.validateSize();
  123.                if(!_loc3_.updateCompletePendingFlag)
  124.                {
  125.                   updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  126.                   _loc3_.updateCompletePendingFlag = true;
  127.                }
  128.                if(invalidateClientPropertiesFlag)
  129.                {
  130.                   _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  131.                   if(_loc3_)
  132.                   {
  133.                      invalidatePropertiesQueue.addObject(_loc3_,_loc3_.nestLevel);
  134.                      _loc5_ = false;
  135.                      break;
  136.                   }
  137.                }
  138.                _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  139.             }
  140.             if(invalidateSizeQueue.isEmpty())
  141.             {
  142.                invalidateSizeFlag = false;
  143.                invalidateClientSizeFlag = false;
  144.             }
  145.             if(!param2)
  146.             {
  147.                _loc3_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallestChild(param1));
  148.                while(_loc3_)
  149.                {
  150.                   _loc3_.validateDisplayList();
  151.                   if(!_loc3_.updateCompletePendingFlag)
  152.                   {
  153.                      updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  154.                      _loc3_.updateCompletePendingFlag = true;
  155.                   }
  156.                   if(invalidateClientPropertiesFlag)
  157.                   {
  158.                      _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  159.                      if(_loc3_)
  160.                      {
  161.                         invalidatePropertiesQueue.addObject(_loc3_,_loc3_.nestLevel);
  162.                         _loc5_ = false;
  163.                         break;
  164.                      }
  165.                   }
  166.                   if(invalidateClientSizeFlag)
  167.                   {
  168.                      _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  169.                      if(_loc3_)
  170.                      {
  171.                         invalidateSizeQueue.addObject(_loc3_,_loc3_.nestLevel);
  172.                         _loc5_ = false;
  173.                         break;
  174.                      }
  175.                   }
  176.                   _loc3_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallestChild(param1));
  177.                }
  178.                if(invalidateDisplayListQueue.isEmpty())
  179.                {
  180.                   invalidateDisplayListFlag = false;
  181.                }
  182.             }
  183.          }
  184.          if(_loc6_ == int.MAX_VALUE)
  185.          {
  186.             targetLevel = int.MAX_VALUE;
  187.             if(!param2)
  188.             {
  189.                _loc3_ = ILayoutManagerClient(updateCompleteQueue.removeLargestChild(param1));
  190.                while(_loc3_)
  191.                {
  192.                   if(!_loc3_.initialized)
  193.                   {
  194.                      _loc3_.initialized = true;
  195.                   }
  196.                   _loc3_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  197.                   _loc3_.updateCompletePendingFlag = false;
  198.                   _loc3_ = ILayoutManagerClient(updateCompleteQueue.removeLargestChild(param1));
  199.                }
  200.             }
  201.          }
  202.       }
  203.       
  204.       private function validateProperties() : void
  205.       {
  206.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallest());
  207.          while(_loc1_)
  208.          {
  209.             _loc1_.validateProperties();
  210.             if(!_loc1_.updateCompletePendingFlag)
  211.             {
  212.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  213.                _loc1_.updateCompletePendingFlag = true;
  214.             }
  215.             _loc1_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallest());
  216.          }
  217.          if(invalidatePropertiesQueue.isEmpty())
  218.          {
  219.             invalidatePropertiesFlag = false;
  220.          }
  221.       }
  222.       
  223.       public function invalidateProperties(param1:ILayoutManagerClient) : void
  224.       {
  225.          if(!invalidatePropertiesFlag && Boolean(ApplicationGlobals.application.systemManager))
  226.          {
  227.             invalidatePropertiesFlag = true;
  228.             if(!callLaterPending)
  229.             {
  230.                if(!callLaterObject)
  231.                {
  232.                   callLaterObject = new UIComponent();
  233.                   callLaterObject.systemManager = ApplicationGlobals.application.systemManager;
  234.                   callLaterObject.callLater(waitAFrame);
  235.                }
  236.                else
  237.                {
  238.                   callLaterObject.callLater(doPhasedInstantiation);
  239.                }
  240.                callLaterPending = true;
  241.             }
  242.          }
  243.          if(targetLevel <= param1.nestLevel)
  244.          {
  245.             invalidateClientPropertiesFlag = true;
  246.          }
  247.          invalidatePropertiesQueue.addObject(param1,param1.nestLevel);
  248.       }
  249.       
  250.       public function invalidateDisplayList(param1:ILayoutManagerClient) : void
  251.       {
  252.          if(!invalidateDisplayListFlag && Boolean(ApplicationGlobals.application.systemManager))
  253.          {
  254.             invalidateDisplayListFlag = true;
  255.             if(!callLaterPending)
  256.             {
  257.                if(!callLaterObject)
  258.                {
  259.                   callLaterObject = new UIComponent();
  260.                   callLaterObject.systemManager = ApplicationGlobals.application.systemManager;
  261.                   callLaterObject.callLater(waitAFrame);
  262.                }
  263.                else
  264.                {
  265.                   callLaterObject.callLater(doPhasedInstantiation);
  266.                }
  267.                callLaterPending = true;
  268.             }
  269.          }
  270.          invalidateDisplayListQueue.addObject(param1,param1.nestLevel);
  271.       }
  272.       
  273.       private function validateDisplayList() : void
  274.       {
  275.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallest());
  276.          while(_loc1_)
  277.          {
  278.             _loc1_.validateDisplayList();
  279.             if(!_loc1_.updateCompletePendingFlag)
  280.             {
  281.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  282.                _loc1_.updateCompletePendingFlag = true;
  283.             }
  284.             _loc1_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallest());
  285.          }
  286.          if(invalidateDisplayListQueue.isEmpty())
  287.          {
  288.             invalidateDisplayListFlag = false;
  289.          }
  290.       }
  291.       
  292.       public function validateNow() : void
  293.       {
  294.          var _loc1_:int = 0;
  295.          if(!usePhasedInstantiation)
  296.          {
  297.             _loc1_ = 0;
  298.             while(callLaterPending && _loc1_++ < 100)
  299.             {
  300.                doPhasedInstantiation();
  301.             }
  302.          }
  303.       }
  304.       
  305.       private function validateSize() : void
  306.       {
  307.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(invalidateSizeQueue.removeLargest());
  308.          while(_loc1_)
  309.          {
  310.             _loc1_.validateSize();
  311.             if(!_loc1_.updateCompletePendingFlag)
  312.             {
  313.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  314.                _loc1_.updateCompletePendingFlag = true;
  315.             }
  316.             _loc1_ = ILayoutManagerClient(invalidateSizeQueue.removeLargest());
  317.          }
  318.          if(invalidateSizeQueue.isEmpty())
  319.          {
  320.             invalidateSizeFlag = false;
  321.          }
  322.       }
  323.       
  324.       private function doPhasedInstantiation() : void
  325.       {
  326.          var _loc1_:ILayoutManagerClient = null;
  327.          if(usePhasedInstantiation)
  328.          {
  329.             if(invalidatePropertiesFlag)
  330.             {
  331.                validateProperties();
  332.                ApplicationGlobals.application.dispatchEvent(new Event("validatePropertiesComplete"));
  333.             }
  334.             else if(invalidateSizeFlag)
  335.             {
  336.                validateSize();
  337.                ApplicationGlobals.application.dispatchEvent(new Event("validateSizeComplete"));
  338.             }
  339.             else if(invalidateDisplayListFlag)
  340.             {
  341.                validateDisplayList();
  342.                ApplicationGlobals.application.dispatchEvent(new Event("validateDisplayListComplete"));
  343.             }
  344.          }
  345.          else
  346.          {
  347.             if(invalidatePropertiesFlag)
  348.             {
  349.                validateProperties();
  350.             }
  351.             if(invalidateSizeFlag)
  352.             {
  353.                validateSize();
  354.             }
  355.             if(invalidateDisplayListFlag)
  356.             {
  357.                validateDisplayList();
  358.             }
  359.          }
  360.          if(invalidatePropertiesFlag || invalidateSizeFlag || invalidateDisplayListFlag)
  361.          {
  362.             callLaterObject.callLater(doPhasedInstantiation);
  363.          }
  364.          else
  365.          {
  366.             usePhasedInstantiation = false;
  367.             callLaterPending = false;
  368.             _loc1_ = ILayoutManagerClient(updateCompleteQueue.removeLargest());
  369.             while(_loc1_)
  370.             {
  371.                if(!_loc1_.initialized && Boolean(_loc1_.processedDescriptors))
  372.                {
  373.                   _loc1_.initialized = true;
  374.                }
  375.                _loc1_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  376.                _loc1_.updateCompletePendingFlag = false;
  377.                _loc1_ = ILayoutManagerClient(updateCompleteQueue.removeLargest());
  378.             }
  379.             dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  380.          }
  381.       }
  382.       
  383.       public function isInvalid() : Boolean
  384.       {
  385.          return invalidatePropertiesFlag || invalidateSizeFlag || invalidateDisplayListFlag;
  386.       }
  387.       
  388.       public function get usePhasedInstantiation() : Boolean
  389.       {
  390.          return _usePhasedInstantiation;
  391.       }
  392.       
  393.       public function invalidateSize(param1:ILayoutManagerClient) : void
  394.       {
  395.          if(!invalidateSizeFlag && Boolean(ApplicationGlobals.application.systemManager))
  396.          {
  397.             invalidateSizeFlag = true;
  398.             if(!callLaterPending)
  399.             {
  400.                if(!callLaterObject)
  401.                {
  402.                   callLaterObject = new UIComponent();
  403.                   callLaterObject.systemManager = ApplicationGlobals.application.systemManager;
  404.                   callLaterObject.callLater(waitAFrame);
  405.                }
  406.                else
  407.                {
  408.                   callLaterObject.callLater(doPhasedInstantiation);
  409.                }
  410.                callLaterPending = true;
  411.             }
  412.          }
  413.          if(targetLevel <= param1.nestLevel)
  414.          {
  415.             invalidateClientSizeFlag = true;
  416.          }
  417.          invalidateSizeQueue.addObject(param1,param1.nestLevel);
  418.       }
  419.    }
  420. }
  421.  
  422.