home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Darbas / kidoz_v1.air / kidoz.swf / scripts / mx / controls / listClasses / ListItemRenderer.as < prev    next >
Encoding:
Text File  |  2009-05-06  |  8.7 KB  |  299 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.2.0.3958";
  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.          super.measure();
  181.          var _loc1_:Number = 0;
  182.          if(icon)
  183.          {
  184.             _loc1_ = Number(icon.measuredWidth);
  185.          }
  186.          if(label.width < 4 || label.height < 4)
  187.          {
  188.             label.width = 4;
  189.             label.height = 16;
  190.          }
  191.          if(isNaN(explicitWidth))
  192.          {
  193.             _loc1_ += label.getExplicitOrMeasuredWidth();
  194.             measuredWidth = _loc1_;
  195.             measuredHeight = label.getExplicitOrMeasuredHeight();
  196.          }
  197.          else
  198.          {
  199.             measuredWidth = explicitWidth;
  200.             label.setActualSize(Math.max(explicitWidth - _loc1_,4),label.height);
  201.             measuredHeight = label.getExplicitOrMeasuredHeight();
  202.             if(Boolean(icon) && icon.measuredHeight > measuredHeight)
  203.             {
  204.                measuredHeight = icon.measuredHeight;
  205.             }
  206.          }
  207.       }
  208.       
  209.       public function get fontContext() : IFlexModuleFactory
  210.       {
  211.          return moduleFactory;
  212.       }
  213.       
  214.       override protected function createChildren() : void
  215.       {
  216.          super.createChildren();
  217.          if(!label)
  218.          {
  219.             label = IUITextField(createInFontContext(UITextField));
  220.             label.styleName = this;
  221.             addChild(DisplayObject(label));
  222.          }
  223.       }
  224.       
  225.       [Bindable("dataChange")]
  226.       public function get data() : Object
  227.       {
  228.          return _data;
  229.       }
  230.       
  231.       [Bindable("dataChange")]
  232.       public function get listData() : BaseListData
  233.       {
  234.          return _listData;
  235.       }
  236.       
  237.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  238.       {
  239.          var _loc5_:Number = NaN;
  240.          super.updateDisplayList(param1,param2);
  241.          var _loc3_:Number = 0;
  242.          if(icon)
  243.          {
  244.             icon.x = _loc3_;
  245.             _loc3_ = icon.x + icon.measuredWidth;
  246.             icon.setActualSize(icon.measuredWidth,icon.measuredHeight);
  247.          }
  248.          label.x = _loc3_;
  249.          label.setActualSize(param1 - _loc3_,measuredHeight);
  250.          var _loc4_:String = getStyle("verticalAlign");
  251.          if(_loc4_ == "top")
  252.          {
  253.             label.y = 0;
  254.             if(icon)
  255.             {
  256.                icon.y = 0;
  257.             }
  258.          }
  259.          else if(_loc4_ == "bottom")
  260.          {
  261.             label.y = param2 - label.height + 2;
  262.             if(icon)
  263.             {
  264.                icon.y = param2 - icon.height;
  265.             }
  266.          }
  267.          else
  268.          {
  269.             label.y = (param2 - label.height) / 2;
  270.             if(icon)
  271.             {
  272.                icon.y = (param2 - icon.height) / 2;
  273.             }
  274.          }
  275.          if(Boolean(data) && Boolean(parent))
  276.          {
  277.             if(!enabled)
  278.             {
  279.                _loc5_ = getStyle("disabledColor");
  280.             }
  281.             else if(listOwner.isItemHighlighted(listData.uid))
  282.             {
  283.                _loc5_ = getStyle("textRollOverColor");
  284.             }
  285.             else if(listOwner.isItemSelected(listData.uid))
  286.             {
  287.                _loc5_ = getStyle("textSelectedColor");
  288.             }
  289.             else
  290.             {
  291.                _loc5_ = getStyle("color");
  292.             }
  293.             label.setColor(_loc5_);
  294.          }
  295.       }
  296.    }
  297. }
  298.  
  299.