home *** CD-ROM | disk | FTP | other *** search
/ The Complete Idiot's Guide to Microsoft Excel 2010 / CIGExcel.iso / Videos / Flash / controller.swf / scripts / __Packages / com / techsmith / widgets / button / TSRadioButton.as < prev    next >
Encoding:
Text File  |  2010-09-09  |  7.6 KB  |  278 lines

  1. class com.techsmith.widgets.button.TSRadioButton extends com.techsmith.widgets.button.TSSimpleButton
  2. {
  3.    var m_label = null;
  4.    var m_labelField = null;
  5.    var m_labelFormat = null;
  6.    var m_fWidth = null;
  7.    var m_fHeight = null;
  8.    var m_metrics = null;
  9.    var m_highlight = null;
  10.    var m_indent = null;
  11.    var m_margin = null;
  12.    var m_labelIndent = null;
  13.    var m_labelTopIndent = null;
  14.    var m_bIsHighlighted = false;
  15.    var m_highlightColor = null;
  16.    var m_groupName = null;
  17.    var m_radioGroup = null;
  18.    var m_data = null;
  19.    function TSRadioButton()
  20.    {
  21.       super();
  22.       this.tabEnabled = true;
  23.       this.m_highlight = this.createEmptyMovieClip("m_highlight",1);
  24.       this.m_margin = 25;
  25.       this.m_indent = 10;
  26.       this.m_labelIndent = 2;
  27.       this.m_labelTopIndent = 2;
  28.    }
  29.    static function create(container, name, depth, init)
  30.    {
  31.       var _loc1_ = container.attachMovie("TSRadioButton",name,depth,init);
  32.       return com.techsmith.widgets.button.TSRadioButton(_loc1_);
  33.    }
  34.    function init(label, width, group, font, size, weight, highlightColor, fieldProps)
  35.    {
  36.       super.init(new com.techsmith.widgets.button.TSButtonStyle("TSRadioUnselected","TSRadioSelected",true));
  37.       this.m_groupName = group;
  38.       if(this._parent[group] == undefined)
  39.       {
  40.          this._parent[group] = new com.techsmith.widgets.button.TSRadioButtonGroup();
  41.       }
  42.       this.m_radioGroup = this._parent[group];
  43.       if(font == undefined || font == null)
  44.       {
  45.          font = "Arial";
  46.       }
  47.       if(size == undefined || size == null)
  48.       {
  49.          size = 12;
  50.       }
  51.       if(weight == undefined || weight == null)
  52.       {
  53.          weight = false;
  54.       }
  55.       if(highlightColor == undefined || highlightColor == null)
  56.       {
  57.          this.m_highlightColor = 14479870;
  58.       }
  59.       else
  60.       {
  61.          this.m_highlightColor = highlightColor;
  62.       }
  63.       this.m_radioGroup.addRadioButton(this);
  64.       this.m_label = label;
  65.       this.m_fWidth = width;
  66.       this.createLabelFormat(font,size,weight);
  67.       this.setupButton();
  68.       for(var _loc4_ in fieldProps)
  69.       {
  70.          this.m_labelField[_loc4_] = fieldProps[_loc4_];
  71.       }
  72.       this.setLabel(label);
  73.    }
  74.    function setupButton()
  75.    {
  76.       this.m_fGraphicX = this.m_margin;
  77.       this.m_graphic._x = this.m_fGraphicX;
  78.       var _loc2_ = this.m_fWidth - (this.m_margin * 2 + this.m_indent);
  79.       this.measure(this.m_label,_loc2_);
  80.       this.m_fHeight = Math.max(this.m_graphic._height,this.m_metrics.textFieldHeight) + this.m_labelTopIndent;
  81.       this.createLabel();
  82.       this.createHighlight();
  83.    }
  84.    function centerIcon()
  85.    {
  86.       if(this.m_fHeight > this.m_graphic._height)
  87.       {
  88.          this.m_fGraphicY = (this.m_fHeight - this.m_labelTopIndent - this.m_graphic._height) / 2;
  89.          this.m_graphic._y = this.m_fGraphicY;
  90.       }
  91.    }
  92.    function measure(label, width)
  93.    {
  94.       if(width == undefined || width == null)
  95.       {
  96.          this.m_metrics = this.m_labelFormat.getTextExtent(label);
  97.       }
  98.       else
  99.       {
  100.          this.m_metrics = this.m_labelFormat.getTextExtent(label,width);
  101.       }
  102.    }
  103.    function createLabelFormat(font, size, weight)
  104.    {
  105.       this.m_labelFormat = new TextFormat();
  106.       this.m_labelFormat.font = font;
  107.       this.m_labelFormat.size = size;
  108.       this.m_labelFormat.bold = weight;
  109.       this.m_labelFormat.align = "left";
  110.       this.m_labelFormat.color = 6710886;
  111.    }
  112.    function createLabel()
  113.    {
  114.       var _loc2_ = this.m_graphic._x + this.m_graphic._width + this.m_labelIndent;
  115.       this.createTextField("m_labelField",6,_loc2_,0,this.m_fWidth - this.m_margin * 2,this.m_fHeight - this.m_labelTopIndent);
  116.       this.m_labelField._x = this.m_margin + this.m_graphic._width + this.m_indent;
  117.       this.m_labelField._y = this.m_labelTopIndent;
  118.       this.m_labelField.html = true;
  119.       this.m_labelField.multiline = true;
  120.       this.m_labelField.wordWrap = true;
  121.    }
  122.    function createHighlight()
  123.    {
  124.       this.m_highlight.clear();
  125.       com.techsmith.utils.shapes.Rectangle.draw(this.m_highlight,this.m_highlightColor,this.m_fWidth,this.m_fHeight,100,null,null);
  126.       this.m_highlight._visible = this.m_bIsHighlighted;
  127.    }
  128.    function onUnload()
  129.    {
  130.       this.m_dispatcher.removeAllListeners();
  131.       if(this.m_radioGroup.getSelected() == this)
  132.       {
  133.          this.m_radioGroup.setSelected(undefined);
  134.          this.m_radioGroup.removeRadioButton(this);
  135.       }
  136.    }
  137.    function onRollOver()
  138.    {
  139.       super.onRollOver();
  140.       this.m_bIsHighlighted = true;
  141.       this.m_highlight._visible = true;
  142.    }
  143.    function onRollOut()
  144.    {
  145.       super.onRollOut();
  146.       this.m_bIsHighlighted = false;
  147.       this.m_highlight._visible = false;
  148.    }
  149.    function onRelease()
  150.    {
  151.       if(!this.isSelected())
  152.       {
  153.          this.m_radioGroup.enforceSelectionRules(this);
  154.          super.onRelease();
  155.       }
  156.       else
  157.       {
  158.          this.m_graphic = this.attachMovie(this.m_styleObj.m_falseOverSkin,"m_graphic",5);
  159.          this.positionIcon();
  160.       }
  161.    }
  162.    function onReleaseOutside()
  163.    {
  164.       this.m_bIsHighlighted = false;
  165.       this.m_highlight._visible = false;
  166.    }
  167.    function sendEvent(e)
  168.    {
  169.       this.dispatchEvent({target:this,type:"click",data:this.m_data});
  170.    }
  171.    function setEnabled(enable)
  172.    {
  173.       super.setEnabled(enable);
  174.       if(!enable)
  175.       {
  176.          this.m_highlight._visible = false;
  177.       }
  178.    }
  179.    function setSelected(flag, groupInited, fireEvent)
  180.    {
  181.       flag = !flag;
  182.       if(this.m_fToggleState == flag)
  183.       {
  184.          return undefined;
  185.       }
  186.       this.m_fToggleState = flag;
  187.       if(this.m_fToggleState)
  188.       {
  189.          if(this.enabled)
  190.          {
  191.             this.m_graphic = this.attachMovie(this.m_styleObj.m_trueUpSkin,"m_graphic",5);
  192.          }
  193.          else
  194.          {
  195.             this.m_graphic = this.attachMovie(this.m_styleObj.m_trueDisabledSkin,"m_graphic",5);
  196.          }
  197.       }
  198.       else if(this.enabled)
  199.       {
  200.          this.m_graphic = this.attachMovie(this.m_styleObj.m_falseUpSkin,"m_graphic",5);
  201.       }
  202.       else
  203.       {
  204.          this.m_graphic = this.attachMovie(this.m_styleObj.m_falseDisabledSkin,"m_graphic",5);
  205.       }
  206.       this.positionIcon();
  207.       if(!flag && (!groupInited || groupInited == undefined || groupInited == null))
  208.       {
  209.          this.m_radioGroup.enforceSelectionRules(this);
  210.       }
  211.       if(fireEvent)
  212.       {
  213.          this.sendEvent();
  214.       }
  215.    }
  216.    function setLabel(label)
  217.    {
  218.       this.m_label = label;
  219.       if(this.m_labelField.html)
  220.       {
  221.          this.m_labelField.htmlText = label;
  222.       }
  223.       else
  224.       {
  225.          this.m_labelField.text = label;
  226.       }
  227.       this.m_labelField.setTextFormat(this.m_labelFormat);
  228.    }
  229.    function setWidth(width)
  230.    {
  231.       this.m_fHeight = width;
  232.    }
  233.    function getWidth()
  234.    {
  235.       return this.m_fWidth;
  236.    }
  237.    function getHeight()
  238.    {
  239.       return this.m_fHeight;
  240.    }
  241.    function isSelected()
  242.    {
  243.       if(!this.m_fToggleState)
  244.       {
  245.          return true;
  246.       }
  247.       return false;
  248.    }
  249.    function getGroupName()
  250.    {
  251.       return this.m_groupName;
  252.    }
  253.    function getGroup()
  254.    {
  255.       return this.m_radioGroup;
  256.    }
  257.    function getValue()
  258.    {
  259.       if(this.m_data == undefined || this.m_data == null)
  260.       {
  261.          return this.m_label;
  262.       }
  263.       return this.m_data.toString();
  264.    }
  265.    function getData()
  266.    {
  267.       return this.m_data;
  268.    }
  269.    function setData(data)
  270.    {
  271.       this.m_data = data;
  272.    }
  273.    function getLabel()
  274.    {
  275.       return this.m_label;
  276.    }
  277. }
  278.