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