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