home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2012 April / ME_04_2012.iso / Video-Tutorial / iPhoto / media / player.swf / scripts / mx / controls / ToolTip.as < prev    next >
Encoding:
Text File  |  2011-11-11  |  6.8 KB  |  214 lines

  1. package mx.controls
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.text.TextFieldAutoSize;
  5.    import flash.text.TextFormat;
  6.    import mx.core.EdgeMetrics;
  7.    import mx.core.IFlexDisplayObject;
  8.    import mx.core.IFlexModuleFactory;
  9.    import mx.core.IFontContextComponent;
  10.    import mx.core.IRectangularBorder;
  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.styles.ISimpleStyleClient;
  17.    
  18.    use namespace mx_internal;
  19.    
  20.    public class ToolTip extends UIComponent implements IToolTip, IFontContextComponent
  21.    {
  22.       mx_internal static const VERSION:String = "4.5.0.20967";
  23.       
  24.       public static var maxWidth:Number = 300;
  25.       
  26.       mx_internal var border:IFlexDisplayObject;
  27.       
  28.       private var _text:String;
  29.       
  30.       private var textChanged:Boolean;
  31.       
  32.       protected var textField:IUITextField;
  33.       
  34.       public function ToolTip()
  35.       {
  36.          super();
  37.          mouseEnabled = false;
  38.       }
  39.       
  40.       private function get borderMetrics() : EdgeMetrics
  41.       {
  42.          if(this.mx_internal::border is IRectangularBorder)
  43.          {
  44.             return IRectangularBorder(this.mx_internal::border).borderMetrics;
  45.          }
  46.          return EdgeMetrics.EMPTY;
  47.       }
  48.       
  49.       public function get fontContext() : IFlexModuleFactory
  50.       {
  51.          return moduleFactory;
  52.       }
  53.       
  54.       public function set fontContext(param1:IFlexModuleFactory) : void
  55.       {
  56.          this.moduleFactory = param1;
  57.       }
  58.       
  59.       public function get text() : String
  60.       {
  61.          return this._text;
  62.       }
  63.       
  64.       public function set text(param1:String) : void
  65.       {
  66.          this._text = param1;
  67.          this.textChanged = true;
  68.          invalidateProperties();
  69.          invalidateSize();
  70.          invalidateDisplayList();
  71.       }
  72.       
  73.       override protected function createChildren() : void
  74.       {
  75.          super.createChildren();
  76.          this.createBorder();
  77.          this.mx_internal::createTextField(-1);
  78.       }
  79.       
  80.       override protected function commitProperties() : void
  81.       {
  82.          var _loc1_:int = 0;
  83.          var _loc2_:TextFormat = null;
  84.          super.commitProperties();
  85.          if(hasFontContextChanged() && this.textField != null)
  86.          {
  87.             _loc1_ = getChildIndex(DisplayObject(this.textField));
  88.             this.mx_internal::removeTextField();
  89.             this.mx_internal::createTextField(_loc1_);
  90.             invalidateSize();
  91.             this.textChanged = true;
  92.          }
  93.          if(this.textChanged)
  94.          {
  95.             _loc2_ = this.textField.getTextFormat();
  96.             _loc2_.leftMargin = 0;
  97.             _loc2_.rightMargin = 0;
  98.             this.textField.defaultTextFormat = _loc2_;
  99.             this.textField.text = this._text;
  100.             this.textChanged = false;
  101.          }
  102.       }
  103.       
  104.       override protected function measure() : void
  105.       {
  106.          super.measure();
  107.          var _loc1_:EdgeMetrics = this.borderMetrics;
  108.          var _loc2_:Number = _loc1_.left + getStyle("paddingLeft");
  109.          var _loc3_:Number = _loc1_.top + getStyle("paddingTop");
  110.          var _loc4_:Number = _loc1_.right + getStyle("paddingRight");
  111.          var _loc5_:Number = _loc1_.bottom + getStyle("paddingBottom");
  112.          var _loc6_:Number = _loc2_ + _loc4_;
  113.          var _loc7_:Number = _loc3_ + _loc5_;
  114.          this.textField.wordWrap = false;
  115.          if(this.textField.textWidth + _loc6_ > ToolTip.maxWidth)
  116.          {
  117.             this.textField.width = ToolTip.maxWidth - _loc6_;
  118.             this.textField.wordWrap = true;
  119.          }
  120.          measuredWidth = this.textField.width + _loc6_;
  121.          measuredHeight = this.textField.height + _loc7_;
  122.       }
  123.       
  124.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  125.       {
  126.          super.updateDisplayList(param1,param2);
  127.          var _loc3_:EdgeMetrics = this.borderMetrics;
  128.          var _loc4_:Number = _loc3_.left + getStyle("paddingLeft");
  129.          var _loc5_:Number = _loc3_.top + getStyle("paddingTop");
  130.          var _loc6_:Number = _loc3_.right + getStyle("paddingRight");
  131.          var _loc7_:Number = _loc3_.bottom + getStyle("paddingBottom");
  132.          var _loc8_:Number = _loc4_ + _loc6_;
  133.          var _loc9_:Number = _loc5_ + _loc7_;
  134.          this.mx_internal::border.setActualSize(param1,param2);
  135.          this.textField.move(_loc4_,_loc5_);
  136.          this.textField.setActualSize(param1 - _loc8_,param2 - _loc9_);
  137.       }
  138.       
  139.       override public function styleChanged(param1:String) : void
  140.       {
  141.          super.styleChanged(param1);
  142.          if(param1 == "styleName" || param1 == "borderSkin" || param1 == null)
  143.          {
  144.             if(this.mx_internal::border)
  145.             {
  146.                removeChild(DisplayObject(this.mx_internal::border));
  147.                this.mx_internal::border = null;
  148.             }
  149.             this.createBorder();
  150.          }
  151.          else if(param1 == "borderStyle")
  152.          {
  153.             invalidateDisplayList();
  154.          }
  155.       }
  156.       
  157.       mx_internal function createTextField(param1:int) : void
  158.       {
  159.          if(!this.textField)
  160.          {
  161.             this.textField = IUITextField(createInFontContext(UITextField));
  162.             this.textField.autoSize = TextFieldAutoSize.LEFT;
  163.             this.textField.mouseEnabled = false;
  164.             this.textField.multiline = true;
  165.             this.textField.selectable = false;
  166.             this.textField.wordWrap = false;
  167.             this.textField.styleName = this;
  168.             if(param1 == -1)
  169.             {
  170.                addChild(DisplayObject(this.textField));
  171.             }
  172.             else
  173.             {
  174.                addChildAt(DisplayObject(this.textField),param1);
  175.             }
  176.          }
  177.       }
  178.       
  179.       mx_internal function removeTextField() : void
  180.       {
  181.          if(this.textField)
  182.          {
  183.             removeChild(DisplayObject(this.textField));
  184.             this.textField = null;
  185.          }
  186.       }
  187.       
  188.       mx_internal function getTextField() : IUITextField
  189.       {
  190.          return this.textField;
  191.       }
  192.       
  193.       private function createBorder() : void
  194.       {
  195.          var _loc1_:Class = null;
  196.          if(!this.mx_internal::border)
  197.          {
  198.             _loc1_ = getStyle("borderSkin");
  199.             if(_loc1_ != null)
  200.             {
  201.                this.mx_internal::border = new _loc1_();
  202.                if(this.mx_internal::border is ISimpleStyleClient)
  203.                {
  204.                   ISimpleStyleClient(this.mx_internal::border).styleName = this;
  205.                }
  206.                addChildAt(DisplayObject(this.mx_internal::border),0);
  207.                invalidateDisplayList();
  208.             }
  209.          }
  210.       }
  211.    }
  212. }
  213.  
  214.