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