home *** CD-ROM | disk | FTP | other *** search
/ Champak 132 (Alt) / Vol 132.iso / interfac / it.dig / scripts / __Packages / mx / controls / listclasses / SelectableRow.as < prev   
Encoding:
Text File  |  2011-06-09  |  11.2 KB  |  372 lines

  1. class mx.controls.listclasses.SelectableRow extends mx.core.UIComponent
  2. {
  3.    var __height;
  4.    var cell;
  5.    var owner;
  6.    var rowIndex;
  7.    var icon_mc;
  8.    var __width;
  9.    var backGround;
  10.    var highlight;
  11.    var highlightColor;
  12.    var listOwner;
  13.    var item;
  14.    var isChangedToSelected;
  15.    var bGTween;
  16.    var grandOwner;
  17.    static var LOWEST_DEPTH = -16384;
  18.    var state = "normal";
  19.    var disabledColor = 15263976;
  20.    var normalColor = 16777215;
  21.    function SelectableRow()
  22.    {
  23.       super();
  24.    }
  25.    function setValue(itmObj, state)
  26.    {
  27.       var _loc6_ = this.__height;
  28.       var _loc2_ = this.cell;
  29.       var _loc5_ = this.owner;
  30.       var _loc8_ = this.itemToString(itmObj);
  31.       if(_loc2_.getValue() != _loc8_)
  32.       {
  33.          _loc2_.setValue(_loc8_,itmObj,state);
  34.       }
  35.       var _loc4_ = _loc5_.getPropertiesAt(this.rowIndex + _loc5_.__vPosition).icon;
  36.       if(_loc4_ == undefined)
  37.       {
  38.          _loc4_ = _loc5_.__iconFunction(itmObj);
  39.          if(_loc4_ == undefined)
  40.          {
  41.             _loc4_ = itmObj[_loc5_.__iconField];
  42.             if(_loc4_ == undefined)
  43.             {
  44.                _loc4_ = _loc5_.getStyle("defaultIcon");
  45.             }
  46.          }
  47.       }
  48.       var _loc3_ = this.icon_mc;
  49.       if(_loc4_ != undefined && itmObj != undefined)
  50.       {
  51.          _loc3_ = this.createObject(_loc4_,"icon_mc",20);
  52.          _loc3_._x = 2;
  53.          _loc3_._y = (_loc6_ - _loc3_._height) / 2;
  54.          _loc2_._x = 4 + _loc3_._width;
  55.       }
  56.       else
  57.       {
  58.          _loc3_.removeMovieClip();
  59.          _loc2_._x = 2;
  60.       }
  61.       var _loc9_ = _loc3_ != undefined ? _loc3_._width : 0;
  62.       _loc2_.setSize(this.__width - _loc9_,Math.min(_loc6_,_loc2_.getPreferredHeight()));
  63.       _loc2_._y = (_loc6_ - _loc2_._height) / 2;
  64.    }
  65.    function size(Void)
  66.    {
  67.       var _loc3_ = this.backGround;
  68.       var _loc2_ = this.cell;
  69.       var _loc4_ = this.__height;
  70.       var _loc5_ = this.__width;
  71.       var _loc6_ = this.icon_mc != undefined ? this.icon_mc._width : 0;
  72.       _loc2_.setSize(_loc5_ - _loc6_,Math.min(_loc4_,_loc2_.getPreferredHeight()));
  73.       _loc2_._y = (_loc4_ - _loc2_._height) / 2;
  74.       this.icon_mc._y = (_loc4_ - this.icon_mc._height) / 2;
  75.       _loc3_._x = 0;
  76.       _loc3_._width = _loc5_;
  77.       _loc3_._height = _loc4_;
  78.       this.drawRowFill(_loc3_,this.normalColor);
  79.       this.drawRowFill(this.highlight,this.highlightColor);
  80.    }
  81.    function setCellRenderer(forceSizing)
  82.    {
  83.       var _loc3_ = this.owner.__cellRenderer;
  84.       var _loc4_ = undefined;
  85.       if(this.cell != undefined)
  86.       {
  87.          _loc4_ = this.cell._x;
  88.          this.cell.removeMovieClip();
  89.          this.cell.removeTextField();
  90.       }
  91.       var _loc2_ = undefined;
  92.       if(_loc3_ == undefined)
  93.       {
  94.          var _loc0_ = null;
  95.          _loc2_ = this.cell = this.createLabel("cll",0,{styleName:this});
  96.          _loc2_.styleName = this.owner;
  97.          _loc2_.selectable = false;
  98.          _loc2_.tabEnabled = false;
  99.          _loc2_.background = false;
  100.          _loc2_.border = false;
  101.       }
  102.       else if(typeof _loc3_ == "string")
  103.       {
  104.          var _loc0_ = null;
  105.          _loc2_ = this.cell = this.createObject(_loc3_,"cll",0,{styleName:this});
  106.       }
  107.       else
  108.       {
  109.          var _loc0_ = null;
  110.          _loc2_ = this.cell = this.createClassObject(_loc3_,"cll",0,{styleName:this});
  111.       }
  112.       _loc2_.owner = this;
  113.       _loc2_.listOwner = this.owner;
  114.       _loc2_.getCellIndex = this.getCellIndex;
  115.       _loc2_.getDataLabel = this.getDataLabel;
  116.       if(_loc4_ != undefined)
  117.       {
  118.          _loc2_._x = _loc4_;
  119.       }
  120.       if(forceSizing)
  121.       {
  122.          this.size();
  123.       }
  124.    }
  125.    function getCellIndex(Void)
  126.    {
  127.       return {columnIndex:0,itemIndex:this.owner.rowIndex + this.listOwner.__vPosition};
  128.    }
  129.    function getDataLabel()
  130.    {
  131.       return this.listOwner.labelField;
  132.    }
  133.    function init(Void)
  134.    {
  135.       super.init();
  136.       this.tabEnabled = false;
  137.    }
  138.    function createChildren(Void)
  139.    {
  140.       this.setCellRenderer(false);
  141.       this.setupBG();
  142.       this.setState(this.state,false);
  143.    }
  144.    function drawRow(itmObj, state, transition)
  145.    {
  146.       this.item = itmObj;
  147.       this.setState(state,transition);
  148.       this.setValue(itmObj,state,transition);
  149.    }
  150.    function itemToString(itmObj)
  151.    {
  152.       if(itmObj == undefined)
  153.       {
  154.          return " ";
  155.       }
  156.       var _loc2_ = this.owner.__labelFunction(itmObj);
  157.       if(_loc2_ == undefined)
  158.       {
  159.          _loc2_ = !(itmObj instanceof XMLNode) ? itmObj[this.owner.__labelField] : itmObj.attributes[this.owner.__labelField];
  160.          if(_loc2_ == undefined)
  161.          {
  162.             _loc2_ = " ";
  163.             if(typeof itmObj == "object")
  164.             {
  165.                for(var _loc4_ in itmObj)
  166.                {
  167.                   if(_loc4_ != "__ID__")
  168.                   {
  169.                      _loc2_ = itmObj[_loc4_] + ", " + _loc2_;
  170.                   }
  171.                }
  172.                _loc2_ = _loc2_.substring(0,_loc2_.length - 2);
  173.             }
  174.             else
  175.             {
  176.                _loc2_ = itmObj;
  177.             }
  178.          }
  179.       }
  180.       return _loc2_;
  181.    }
  182.    function setupBG(Void)
  183.    {
  184.       var _loc0_ = null;
  185.       var _loc2_ = this.backGround = this.createEmptyMovieClip("bG_mc",mx.controls.listclasses.SelectableRow.LOWEST_DEPTH);
  186.       this.drawRowFill(_loc2_,this.normalColor);
  187.       this.highlight = this.createEmptyMovieClip("tran_mc",mx.controls.listclasses.SelectableRow.LOWEST_DEPTH + 10);
  188.       _loc2_.owner = this;
  189.       _loc2_.grandOwner = this.owner;
  190.       _loc2_.onPress = this.bGOnPress;
  191.       _loc2_.onRelease = this.bGOnRelease;
  192.       _loc2_.onRollOver = this.bGOnRollOver;
  193.       _loc2_.onRollOut = this.bGOnRollOut;
  194.       _loc2_.onDragOver = this.bGOnDragOver;
  195.       _loc2_.onDragOut = this.bGOnDragOut;
  196.       _loc2_.useHandCursor = false;
  197.       _loc2_.trackAsMenu = true;
  198.       _loc2_.drawRect = this.drawRect;
  199.       this.highlight.drawRect = this.drawRect;
  200.    }
  201.    function drawRowFill(mc, newClr)
  202.    {
  203.       mc.clear();
  204.       mc.beginFill(newClr);
  205.       mc.drawRect(1,0,this.__width,this.__height);
  206.       mc.endFill();
  207.       mc._width = this.__width;
  208.       mc._height = this.__height;
  209.    }
  210.    function setState(newState, transition)
  211.    {
  212.       var _loc2_ = this.highlight;
  213.       var _loc9_ = this.backGround;
  214.       var _loc4_ = this.__height;
  215.       var _loc3_ = this.owner;
  216.       if(!_loc3_.enabled)
  217.       {
  218.          if(newState == "selected" || this.state == "selected")
  219.          {
  220.             this.highlightColor = _loc3_.getStyle("selectionDisabledColor");
  221.             this.drawRowFill(_loc2_,this.highlightColor);
  222.             _loc2_._visible = true;
  223.             _loc2_._y = 0;
  224.             _loc2_._height = _loc4_;
  225.          }
  226.          else
  227.          {
  228.             _loc2_._visible = false;
  229.             this.normalColor = _loc3_.getStyle("backgroundDisabledColor");
  230.             this.drawRowFill(_loc9_,this.normalColor);
  231.          }
  232.          this.cell.__enabled = false;
  233.          this.cell.setColor(_loc3_.getStyle("disabledColor"));
  234.       }
  235.       else
  236.       {
  237.          this.cell.__enabled = true;
  238.          if(transition && (newState == this.state || newState == "highlighted" && this.state == "selected"))
  239.          {
  240.             this.isChangedToSelected = true;
  241.             return undefined;
  242.          }
  243.          var _loc6_ = _loc3_.getStyle("selectionDuration");
  244.          var _loc7_ = 0;
  245.          if(this.isChangedToSelected && newState == "selected")
  246.          {
  247.             transition = false;
  248.          }
  249.          var _loc8_ = transition && _loc6_ != 0;
  250.          if(newState == "normal")
  251.          {
  252.             _loc7_ = _loc3_.getStyle("color");
  253.             this.normalColor = this.getNormalColor();
  254.             this.drawRowFill(_loc9_,this.normalColor);
  255.             if(_loc8_)
  256.             {
  257.                _loc6_ /= 2;
  258.                _loc2_._height = _loc4_;
  259.                _loc2_._width = this.__width;
  260.                _loc2_._y = 0;
  261.                this.bGTween = new mx.effects.Tween(this,_loc4_ + 2,_loc4_ * 0.2,_loc6_,5);
  262.             }
  263.             else
  264.             {
  265.                _loc2_._visible = false;
  266.             }
  267.             delete this.isChangedToSelected;
  268.          }
  269.          else
  270.          {
  271.             this.highlightColor = _loc3_.getStyle(newState != "highlighted" ? "selectionColor" : "rollOverColor");
  272.             this.drawRowFill(_loc2_,this.highlightColor);
  273.             _loc2_._visible = true;
  274.             _loc7_ = _loc3_.getStyle(newState != "highlighted" ? "textSelectedColor" : "textRollOverColor");
  275.             if(_loc8_)
  276.             {
  277.                _loc2_._height = _loc4_ * 0.5;
  278.                _loc2_._y = (_loc4_ - _loc2_._height) / 2;
  279.                this.bGTween = new mx.effects.Tween(this,_loc2_._height,_loc4_ + 2,_loc6_,5);
  280.                var _loc10_ = _loc3_.getStyle("selectionEasing");
  281.                if(_loc10_ != undefined)
  282.                {
  283.                   this.bGTween.easingEquation = _loc10_;
  284.                }
  285.             }
  286.             else
  287.             {
  288.                _loc2_._y = 0;
  289.                _loc2_._height = _loc4_;
  290.             }
  291.          }
  292.          this.cell.setColor(_loc7_);
  293.       }
  294.       this.state = newState;
  295.    }
  296.    function onTweenUpdate(val)
  297.    {
  298.       this.highlight._height = val;
  299.       this.highlight._y = (this.__height - val) / 2;
  300.    }
  301.    function onTweenEnd(val)
  302.    {
  303.       this.onTweenUpdate(val);
  304.       this.highlight._visible = this.state != "normal";
  305.    }
  306.    function getNormalColor(Void)
  307.    {
  308.       var _loc3_ = undefined;
  309.       var _loc2_ = this.owner;
  310.       if(!this.owner.enabled)
  311.       {
  312.          _loc3_ = _loc2_.getStyle("backgroundDisabledColor");
  313.       }
  314.       else
  315.       {
  316.          var _loc5_ = this.rowIndex + _loc2_.__vPosition;
  317.          if(this.rowIndex == undefined)
  318.          {
  319.             _loc3_ = _loc2_.getPropertiesOf(this.item).backgroundColor;
  320.          }
  321.          else
  322.          {
  323.             _loc3_ = _loc2_.getPropertiesAt(_loc5_).backgroundColor;
  324.          }
  325.          if(_loc3_ == undefined)
  326.          {
  327.             var _loc4_ = _loc2_.getStyle("alternatingRowColors");
  328.             if(_loc4_ == undefined)
  329.             {
  330.                _loc3_ = _loc2_.getStyle("backgroundColor");
  331.             }
  332.             else
  333.             {
  334.                _loc3_ = _loc4_[_loc5_ % _loc4_.length];
  335.             }
  336.          }
  337.       }
  338.       return _loc3_;
  339.    }
  340.    function invalidateStyle(propName)
  341.    {
  342.       this.cell.invalidateStyle(propName);
  343.       super.invalidateStyle(propName);
  344.    }
  345.    function bGOnPress(Void)
  346.    {
  347.       this.grandOwner.pressFocus();
  348.       this.grandOwner.onRowPress(this.owner.rowIndex);
  349.    }
  350.    function bGOnRelease(Void)
  351.    {
  352.       this.grandOwner.releaseFocus();
  353.       this.grandOwner.onRowRelease(this.owner.rowIndex);
  354.    }
  355.    function bGOnRollOver(Void)
  356.    {
  357.       this.grandOwner.onRowRollOver(this.owner.rowIndex);
  358.    }
  359.    function bGOnRollOut(Void)
  360.    {
  361.       this.grandOwner.onRowRollOut(this.owner.rowIndex);
  362.    }
  363.    function bGOnDragOver(Void)
  364.    {
  365.       this.grandOwner.onRowDragOver(this.owner.rowIndex);
  366.    }
  367.    function bGOnDragOut(Void)
  368.    {
  369.       this.grandOwner.onRowDragOut(this.owner.rowIndex);
  370.    }
  371. }
  372.