home *** CD-ROM | disk | FTP | other *** search
- class com.techsmith.widgets.button.TSRadioButton extends com.techsmith.widgets.button.TSSimpleButton
- {
- var m_label = null;
- var m_labelField = null;
- var m_labelFormat = null;
- var m_fWidth = null;
- var m_fHeight = null;
- var m_metrics = null;
- var m_highlight = null;
- var m_indent = null;
- var m_margin = null;
- var m_labelIndent = null;
- var m_labelTopIndent = null;
- var m_bIsHighlighted = false;
- var m_highlightColor = null;
- var m_groupName = null;
- var m_radioGroup = null;
- var m_data = null;
- function TSRadioButton()
- {
- super();
- this.tabEnabled = true;
- this.m_highlight = this.createEmptyMovieClip("m_highlight",1);
- this.m_margin = 25;
- this.m_indent = 10;
- this.m_labelIndent = 2;
- this.m_labelTopIndent = 2;
- }
- static function create(container, name, depth, init)
- {
- var _loc1_ = container.attachMovie("TSRadioButton",name,depth,init);
- return com.techsmith.widgets.button.TSRadioButton(_loc1_);
- }
- function init(label, width, group, font, size, weight, highlightColor, fieldProps)
- {
- super.init(new com.techsmith.widgets.button.TSButtonStyle("TSRadioUnselected","TSRadioSelected",true));
- this.m_groupName = group;
- if(this._parent[group] == undefined)
- {
- this._parent[group] = new com.techsmith.widgets.button.TSRadioButtonGroup();
- }
- this.m_radioGroup = this._parent[group];
- if(font == undefined || font == null)
- {
- font = "Arial";
- }
- if(size == undefined || size == null)
- {
- size = 12;
- }
- if(weight == undefined || weight == null)
- {
- weight = false;
- }
- if(highlightColor == undefined || highlightColor == null)
- {
- this.m_highlightColor = 14479870;
- }
- else
- {
- this.m_highlightColor = highlightColor;
- }
- this.m_radioGroup.addRadioButton(this);
- this.m_label = label;
- this.m_fWidth = width;
- this.createLabelFormat(font,size,weight);
- this.setupButton();
- for(var _loc4_ in fieldProps)
- {
- this.m_labelField[_loc4_] = fieldProps[_loc4_];
- }
- this.setLabel(label);
- }
- function setupButton()
- {
- this.m_fGraphicX = this.m_margin;
- this.m_graphic._x = this.m_fGraphicX;
- var _loc2_ = this.m_fWidth - (this.m_margin * 2 + this.m_indent);
- this.measure(this.m_label,_loc2_);
- this.m_fHeight = Math.max(this.m_graphic._height,this.m_metrics.textFieldHeight) + this.m_labelTopIndent;
- this.createLabel();
- this.createHighlight();
- }
- function centerIcon()
- {
- if(this.m_fHeight > this.m_graphic._height)
- {
- this.m_fGraphicY = (this.m_fHeight - this.m_labelTopIndent - this.m_graphic._height) / 2;
- this.m_graphic._y = this.m_fGraphicY;
- }
- }
- function measure(label, width)
- {
- if(width == undefined || width == null)
- {
- this.m_metrics = this.m_labelFormat.getTextExtent(label);
- }
- else
- {
- this.m_metrics = this.m_labelFormat.getTextExtent(label,width);
- }
- }
- function createLabelFormat(font, size, weight)
- {
- this.m_labelFormat = new TextFormat();
- this.m_labelFormat.font = font;
- this.m_labelFormat.size = size;
- this.m_labelFormat.bold = weight;
- this.m_labelFormat.align = "left";
- this.m_labelFormat.color = 6710886;
- }
- function createLabel()
- {
- var _loc2_ = this.m_graphic._x + this.m_graphic._width + this.m_labelIndent;
- this.createTextField("m_labelField",6,_loc2_,0,this.m_fWidth - this.m_margin * 2,this.m_fHeight - this.m_labelTopIndent);
- this.m_labelField._x = this.m_margin + this.m_graphic._width + this.m_indent;
- this.m_labelField._y = this.m_labelTopIndent;
- this.m_labelField.html = true;
- this.m_labelField.multiline = true;
- this.m_labelField.wordWrap = true;
- }
- function createHighlight()
- {
- this.m_highlight.clear();
- com.techsmith.utils.shapes.Rectangle.draw(this.m_highlight,this.m_highlightColor,this.m_fWidth,this.m_fHeight,100,null,null);
- this.m_highlight._visible = this.m_bIsHighlighted;
- }
- function onUnload()
- {
- this.m_dispatcher.removeAllListeners();
- if(this.m_radioGroup.getSelected() == this)
- {
- this.m_radioGroup.setSelected(undefined);
- this.m_radioGroup.removeRadioButton(this);
- }
- }
- function onRollOver()
- {
- super.onRollOver();
- this.m_bIsHighlighted = true;
- this.m_highlight._visible = true;
- }
- function onRollOut()
- {
- super.onRollOut();
- this.m_bIsHighlighted = false;
- this.m_highlight._visible = false;
- }
- function onRelease()
- {
- if(!this.isSelected())
- {
- this.m_radioGroup.enforceSelectionRules(this);
- super.onRelease();
- }
- else
- {
- this.m_graphic = this.attachMovie(this.m_styleObj.m_falseOverSkin,"m_graphic",5);
- this.positionIcon();
- }
- }
- function onReleaseOutside()
- {
- this.m_bIsHighlighted = false;
- this.m_highlight._visible = false;
- }
- function sendEvent(e)
- {
- this.dispatchEvent({target:this,type:"click",data:this.m_data});
- }
- function setEnabled(enable)
- {
- super.setEnabled(enable);
- if(!enable)
- {
- this.m_highlight._visible = false;
- }
- }
- function setSelected(flag, groupInited, fireEvent)
- {
- flag = !flag;
- if(this.m_fToggleState == flag)
- {
- return undefined;
- }
- this.m_fToggleState = flag;
- if(this.m_fToggleState)
- {
- if(this.enabled)
- {
- this.m_graphic = this.attachMovie(this.m_styleObj.m_trueUpSkin,"m_graphic",5);
- }
- else
- {
- this.m_graphic = this.attachMovie(this.m_styleObj.m_trueDisabledSkin,"m_graphic",5);
- }
- }
- else if(this.enabled)
- {
- this.m_graphic = this.attachMovie(this.m_styleObj.m_falseUpSkin,"m_graphic",5);
- }
- else
- {
- this.m_graphic = this.attachMovie(this.m_styleObj.m_falseDisabledSkin,"m_graphic",5);
- }
- this.positionIcon();
- if(!flag && (!groupInited || groupInited == undefined || groupInited == null))
- {
- this.m_radioGroup.enforceSelectionRules(this);
- }
- if(fireEvent)
- {
- this.sendEvent();
- }
- }
- function setLabel(label)
- {
- this.m_label = label;
- if(this.m_labelField.html)
- {
- this.m_labelField.htmlText = label;
- }
- else
- {
- this.m_labelField.text = label;
- }
- this.m_labelField.setTextFormat(this.m_labelFormat);
- }
- function setWidth(width)
- {
- this.m_fHeight = width;
- }
- function getWidth()
- {
- return this.m_fWidth;
- }
- function getHeight()
- {
- return this.m_fHeight;
- }
- function isSelected()
- {
- if(!this.m_fToggleState)
- {
- return true;
- }
- return false;
- }
- function getGroupName()
- {
- return this.m_groupName;
- }
- function getGroup()
- {
- return this.m_radioGroup;
- }
- function getValue()
- {
- if(this.m_data == undefined || this.m_data == null)
- {
- return this.m_label;
- }
- return this.m_data.toString();
- }
- function getData()
- {
- return this.m_data;
- }
- function setData(data)
- {
- this.m_data = data;
- }
- function getLabel()
- {
- return this.m_label;
- }
- }
-