home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / mx / controls / listClasses / TileListItemRenderer.as < prev   
Encoding:
Text File  |  2010-06-23  |  10.0 KB  |  331 lines

  1. package mx.controls.listClasses
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.geom.Point;
  5.    import flash.geom.Rectangle;
  6.    import mx.core.FlexVersion;
  7.    import mx.core.IDataRenderer;
  8.    import mx.core.IFlexDisplayObject;
  9.    import mx.core.IFlexModuleFactory;
  10.    import mx.core.IFontContextComponent;
  11.    import mx.core.IToolTip;
  12.    import mx.core.IUITextField;
  13.    import mx.core.UIComponent;
  14.    import mx.core.UITextField;
  15.    import mx.core.mx_internal;
  16.    import mx.events.FlexEvent;
  17.    import mx.events.InterManagerRequest;
  18.    import mx.events.ToolTipEvent;
  19.    import mx.managers.ISystemManager;
  20.    
  21.    use namespace mx_internal;
  22.    
  23.    public class TileListItemRenderer extends UIComponent implements IDataRenderer, IDropInListItemRenderer, IListItemRenderer, IFontContextComponent
  24.    {
  25.       mx_internal static const VERSION:String = "3.5.0.12683";
  26.       
  27.       private var iconOnly:Boolean = false;
  28.       
  29.       private var _listData:ListData;
  30.       
  31.       private var _data:Object;
  32.       
  33.       protected var label:IUITextField;
  34.       
  35.       private var listOwner:TileBase;
  36.       
  37.       protected var icon:IFlexDisplayObject;
  38.       
  39.       private var iconClass:Class;
  40.       
  41.       public function TileListItemRenderer()
  42.       {
  43.          super();
  44.          addEventListener(ToolTipEvent.TOOL_TIP_SHOW,toolTipShowHandler);
  45.       }
  46.       
  47.       public function set fontContext(param1:IFlexModuleFactory) : void
  48.       {
  49.          this.moduleFactory = param1;
  50.       }
  51.       
  52.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  53.       {
  54.          var _loc6_:Number = NaN;
  55.          var _loc9_:Number = NaN;
  56.          super.updateDisplayList(param1,param2);
  57.          var _loc3_:Number = iconOnly ? 0 : getStyle("verticalGap");
  58.          var _loc4_:Number = getStyle("paddingLeft");
  59.          var _loc5_:Number = getStyle("paddingRight");
  60.          if(icon)
  61.          {
  62.             icon.width = Math.min(param1 - (_loc4_ + _loc5_),icon.measuredWidth);
  63.             icon.height = Math.min(Math.max(param2 - _loc3_ - label.getExplicitOrMeasuredHeight(),0),icon.measuredHeight);
  64.             icon.x = _loc4_ + (param1 - _loc4_ - _loc5_ - icon.width) / 2;
  65.          }
  66.          label.width = param1 - (_loc4_ + _loc5_);
  67.          label.height = Math.min(label.getExplicitOrMeasuredHeight(),!!icon ? Math.max(param2 - _loc3_ - icon.height,0) : param2);
  68.          label.x = _loc4_;
  69.          if(Boolean(listOwner) && listOwner.showDataTips)
  70.          {
  71.             if(label.textWidth > label.width || listOwner.dataTipField && listOwner.dataTipField != "label" || listOwner.dataTipFunction != null)
  72.             {
  73.                toolTip = listOwner.itemToDataTip(_data);
  74.             }
  75.             else
  76.             {
  77.                toolTip = null;
  78.             }
  79.          }
  80.          else
  81.          {
  82.             toolTip = null;
  83.          }
  84.          var _loc7_:Number = Number(label.height);
  85.          if(icon)
  86.          {
  87.             _loc7_ += icon.height + _loc3_;
  88.          }
  89.          var _loc8_:String = getStyle("verticalAlign");
  90.          if(_loc8_ == "top")
  91.          {
  92.             _loc6_ = 0;
  93.             if(icon)
  94.             {
  95.                icon.y = _loc6_;
  96.                _loc6_ += _loc3_ + icon.height;
  97.             }
  98.             label.y = _loc6_;
  99.          }
  100.          else if(_loc8_ == "bottom")
  101.          {
  102.             _loc6_ = param2 - label.height;
  103.             label.y = _loc6_;
  104.             if(icon)
  105.             {
  106.                _loc6_ -= _loc3_ + icon.height;
  107.                icon.y = _loc6_;
  108.             }
  109.          }
  110.          else
  111.          {
  112.             _loc6_ = (param2 - _loc7_) / 2;
  113.             if(icon)
  114.             {
  115.                icon.y = _loc6_;
  116.                _loc6_ += _loc3_ + icon.height;
  117.             }
  118.             label.y = _loc6_;
  119.          }
  120.          if(Boolean(data) && Boolean(parent))
  121.          {
  122.             if(!enabled)
  123.             {
  124.                _loc9_ = getStyle("disabledColor");
  125.             }
  126.             else if(listOwner.isItemSelected(listData.uid))
  127.             {
  128.                _loc9_ = getStyle("textSelectedColor");
  129.             }
  130.             else if(listOwner.isItemHighlighted(listData.uid))
  131.             {
  132.                _loc9_ = getStyle("textRollOverColor");
  133.             }
  134.             else
  135.             {
  136.                _loc9_ = getStyle("color");
  137.             }
  138.             label.setColor(_loc9_);
  139.          }
  140.       }
  141.       
  142.       protected function toolTipShowHandler(param1:ToolTipEvent) : void
  143.       {
  144.          var _loc5_:Rectangle = null;
  145.          var _loc8_:InterManagerRequest = null;
  146.          var _loc2_:IToolTip = param1.toolTip;
  147.          var _loc3_:ISystemManager = systemManager.topLevelSystemManager;
  148.          var _loc4_:DisplayObject = _loc3_.getSandboxRoot();
  149.          var _loc6_:Point = new Point(0,0);
  150.          _loc6_ = label.localToGlobal(_loc6_);
  151.          _loc6_ = _loc4_.globalToLocal(_loc6_);
  152.          _loc2_.move(_loc6_.x,_loc6_.y + (height - _loc2_.height) / 2);
  153.          if(_loc3_ != _loc4_)
  154.          {
  155.             _loc8_ = new InterManagerRequest(InterManagerRequest.SYSTEM_MANAGER_REQUEST,false,false,"getVisibleApplicationRect");
  156.             _loc4_.dispatchEvent(_loc8_);
  157.             _loc5_ = Rectangle(_loc8_.value);
  158.          }
  159.          else
  160.          {
  161.             _loc5_ = _loc3_.getVisibleApplicationRect();
  162.          }
  163.          var _loc7_:Number = _loc5_.x + _loc5_.width;
  164.          _loc6_.x = _loc2_.x;
  165.          _loc6_.y = _loc2_.y;
  166.          _loc6_ = _loc4_.localToGlobal(_loc6_);
  167.          if(_loc6_.x + _loc2_.width > _loc7_)
  168.          {
  169.             _loc2_.move(_loc2_.x - (_loc6_.x + _loc2_.width - _loc7_),_loc2_.y);
  170.          }
  171.       }
  172.       
  173.       mx_internal function getLabel() : IUITextField
  174.       {
  175.          return label;
  176.       }
  177.       
  178.       public function set listData(param1:BaseListData) : void
  179.       {
  180.          _listData = ListData(param1);
  181.          invalidateProperties();
  182.       }
  183.       
  184.       override protected function commitProperties() : void
  185.       {
  186.          var _loc1_:int = 0;
  187.          var _loc2_:Class = null;
  188.          super.commitProperties();
  189.          if(hasFontContextChanged() && label != null)
  190.          {
  191.             _loc1_ = getChildIndex(DisplayObject(label));
  192.             mx_internal::removeLabel();
  193.             mx_internal::createLabel(_loc1_);
  194.          }
  195.          if(Boolean(icon) && !_data)
  196.          {
  197.             removeChild(DisplayObject(icon));
  198.             icon = null;
  199.             iconClass = null;
  200.          }
  201.          if(_data)
  202.          {
  203.             listOwner = TileBase(_listData.owner);
  204.             if(_listData.icon)
  205.             {
  206.                _loc2_ = _listData.icon;
  207.                if(iconClass != _loc2_)
  208.                {
  209.                   iconClass = _loc2_;
  210.                   if(icon)
  211.                   {
  212.                      removeChild(DisplayObject(icon));
  213.                   }
  214.                   icon = new iconClass();
  215.                   addChild(DisplayObject(icon));
  216.                }
  217.             }
  218.             label.text = _listData.label;
  219.             label.multiline = listOwner.variableRowHeight;
  220.             label.wordWrap = listOwner.wordWrap;
  221.          }
  222.          else
  223.          {
  224.             label.text = " ";
  225.             toolTip = null;
  226.          }
  227.       }
  228.       
  229.       public function set data(param1:Object) : void
  230.       {
  231.          _data = param1;
  232.          invalidateProperties();
  233.          dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
  234.       }
  235.       
  236.       mx_internal function createLabel(param1:int) : void
  237.       {
  238.          if(!label)
  239.          {
  240.             label = IUITextField(createInFontContext(UITextField));
  241.             label.styleName = this;
  242.             if(param1 == -1)
  243.             {
  244.                addChild(DisplayObject(label));
  245.             }
  246.             else
  247.             {
  248.                addChildAt(DisplayObject(label),param1);
  249.             }
  250.          }
  251.       }
  252.       
  253.       override public function get baselinePosition() : Number
  254.       {
  255.          if(FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  256.          {
  257.             super.baselinePosition;
  258.          }
  259.          if(!mx_internal::validateBaselinePosition())
  260.          {
  261.             return NaN;
  262.          }
  263.          return label.y + label.baselinePosition;
  264.       }
  265.       
  266.       override protected function measure() : void
  267.       {
  268.          var _loc2_:Number = NaN;
  269.          var _loc3_:Number = NaN;
  270.          super.measure();
  271.          var _loc1_:Number = 0;
  272.          if(icon)
  273.          {
  274.             _loc1_ += icon.measuredHeight;
  275.          }
  276.          if(label.text == "" || label.text == " " || label.text == null)
  277.          {
  278.             label.explicitHeight = 0;
  279.             iconOnly = true;
  280.          }
  281.          else
  282.          {
  283.             label.explicitHeight = NaN;
  284.             _loc1_ += getStyle("verticalGap");
  285.             iconOnly = false;
  286.          }
  287.          measuredHeight = label.getExplicitOrMeasuredHeight() + _loc1_;
  288.          _loc2_ = getStyle("paddingLeft");
  289.          _loc3_ = getStyle("paddingRight");
  290.          measuredWidth = label.getExplicitOrMeasuredWidth() + _loc2_ + _loc3_;
  291.          if(Boolean(icon) && icon.measuredWidth + _loc2_ + _loc3_ > measuredWidth)
  292.          {
  293.             measuredWidth = icon.measuredWidth + _loc2_ + _loc3_;
  294.          }
  295.       }
  296.       
  297.       mx_internal function removeLabel() : void
  298.       {
  299.          if(label)
  300.          {
  301.             removeChild(DisplayObject(label));
  302.             label = null;
  303.          }
  304.       }
  305.       
  306.       public function get fontContext() : IFlexModuleFactory
  307.       {
  308.          return moduleFactory;
  309.       }
  310.       
  311.       override protected function createChildren() : void
  312.       {
  313.          super.createChildren();
  314.          mx_internal::createLabel(-1);
  315.       }
  316.       
  317.       [Bindable("dataChange")]
  318.       public function get listData() : BaseListData
  319.       {
  320.          return _listData;
  321.       }
  322.       
  323.       [Bindable("dataChange")]
  324.       public function get data() : Object
  325.       {
  326.          return _data;
  327.       }
  328.    }
  329. }
  330.  
  331.