// Copyright 2007. Adobe Systems Incorporated. All Rights Reserved. package fl.controls { import fl.controls.ButtonLabelPlacement; import fl.controls.LabelButton; import fl.core.UIComponent; import flash.display.DisplayObject; import flash.display.Graphics; import flash.display.Sprite; import flash.display.Shape; import Error; //-------------------------------------- // Styles //-------------------------------------- /** * @copy fl.controls.LabelButton#style:icon * * @default null * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="icon", type="Class")] /** * @copy fl.controls.LabelButton#style:upIcon * * @default student_ar_fl_controls_CheckBox_upIcon * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="upIcon", type="Class")] /** * @copy fl.controls.LabelButton#style:downIcon * * @default student_ar_fl_controls_CheckBox_downIcon * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="downIcon", type="Class")] /** * @copy fl.controls.LabelButton#style:overIcon * * @default student_ar_fl_controls_CheckBox_overIcon * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="overIcon", type="Class")] /** * @copy fl.controls.LabelButton#style:disabledIcon * * @default student_ar_fl_controls_CheckBox_disabledIcon * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="disabledIcon", type="Class")] /** * @copy fl.controls.LabelButton#style:selectedDisabledIcon * * @default student_ar_fl_controls_CheckBox_selectedDisabledIcon * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="selectedDisabledIcon", type="Class")] /** * @copy fl.controls.LabelButton#style:selectedUpIcon * * @default student_ar_fl_controls_CheckBox_selectedUpIcon * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="selectedUpIcon", type="Class")] /** * @copy fl.controls.LabelButton#style:selectedDownIcon * * @default student_ar_fl_controls_CheckBox_selectedDownIcon * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="selectedDownIcon", type="Class")] /** * @copy fl.controls.LabelButton#style:selectedOverIcon * * @default student_ar_fl_controls_CheckBox_selectedOverIcon * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="selectedOverIcon", type="Class")] /** * @copy fl.controls.LabelButton#style:textPadding * * @default 5 * * @langversion 3.0 * @playerversion Flash 9.0.28.0 */ [Style(name="textPadding", type="Number", format="Length")] //-------------------------------------- // Class description //-------------------------------------- /** * The student_ar_fl_controls_CheckBox component displays a small box that can contain * a check mark. A student_ar_fl_controls_CheckBox component can also display an optional * text label that is positioned to the left, right, top, or bottom * of the student_ar_fl_controls_CheckBox. * *
A student_ar_fl_controls_CheckBox component changes its state in response to a mouse
* click, from selected to cleared, or from cleared to selected.
* student_ar_fl_controls_CheckBox components include a set of true
or false
values
* that are not mutually exclusive.
toggle
property is set to
* true
in the constructor and cannot be changed for a student_ar_fl_controls_CheckBox.
*
* @default true
*
* @throws Error This value cannot be changed for a student_ar_fl_controls_CheckBox component.
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override public function get toggle():Boolean {
return true;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override public function set toggle(value:Boolean):void {
throw new Error("Warning: You cannot change a student_ar_fl_controls_CheckBox's toggle.");
}
/**
* A student_ar_fl_controls_CheckBox never auto-repeats by definition, so the autoRepeat
property is set
* to false
in the constructor and cannot be changed for a student_ar_fl_controls_CheckBox.
*
* @default false
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override public function get autoRepeat():Boolean {
return false;
}
/**
* @private (setter)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override public function set autoRepeat(value:Boolean):void {
return;
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override protected function drawLayout():void{
super.drawLayout();
var textPadding:Number = Number(getStyleValue("textPadding"));
switch(_labelPlacement){
case ButtonLabelPlacement.RIGHT:
icon.x = textPadding;
textField.x = icon.x + (icon.width+textPadding);
background.width = textField.x + textField.width + textPadding;
background.height = Math.max(textField.height, icon.height)+textPadding*2;
break;
case ButtonLabelPlacement.LEFT:
icon.x = width - icon.width - textPadding;
textField.x = width - icon.width - textPadding*2 - textField.width;
background.width = textField.width + icon.width + textPadding*3;
background.height = Math.max(textField.height, icon.height)+textPadding*2;
break;
case ButtonLabelPlacement.TOP:
case ButtonLabelPlacement.BOTTOM:
background.width = Math.max(textField.width, icon.width) + textPadding*2;
background.height = textField.height + icon.height + textPadding*3;
break;
}
background.x = Math.min(icon.x-textPadding, textField.x-textPadding);
background.y = Math.min(icon.y-textPadding, textField.y-textPadding);
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override protected function drawBackground():void {
// do nothing. Checkbox always uses the same empty background.
}
/**
* Shows or hides the focus indicator around this component.
*
* @param focused Show or hide the focus indicator.
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override public function drawFocus(focused:Boolean):void {
super.drawFocus(focused);
// Size focusRect to fit hitArea, not actual width/height
if (focused) {
var focusPadding:Number = Number(getStyleValue('focusRectPadding'));
uiFocusRect.x = background.x - focusPadding;
uiFocusRect.y = background.y - focusPadding;
uiFocusRect.width = background.width + (focusPadding<<1);
uiFocusRect.height = background.height + (focusPadding<<1);
}
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override protected function initializeAccessibility():void {
if (student_ar_fl_controls_CheckBox.createAccessibilityImplementation != null) {
student_ar_fl_controls_CheckBox.createAccessibilityImplementation(this);
}
}
/**
* @private (protected)
*
* @langversion 3.0
* @playerversion Flash 9.0.28.0
*/
override protected function configUI():void {
super.configUI();
super.toggle = true;
var bg:Shape = new Shape();
var g:Graphics = bg.graphics;
g.beginFill(0,0);
g.drawRect(0,0,100,100);
g.endFill();
background = bg as DisplayObject;
addChildAt(background,0);
}
}
}