first commit

This commit is contained in:
2020-10-20 00:58:15 +02:00
commit 7f1b9bfca5
222 changed files with 56918 additions and 0 deletions
@@ -0,0 +1,5 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.containers.formClasses {␍ import com.yahoo.astra.containers.formClasses.IForm; ␍␍ /**␍ * Event obsever class for form classes. ␍ */␍ public class FormEventObserver implements IFormEventObserver {␍␍ //--------------------------------------␍ // Constructor␍ //--------------------------------------␍ ␍ /**␍ * Constructor.␍ * ␍ */␍ public function FormEventObserver() : void {␍ observers = [];␍ }␍␍ //--------------------------------------␍ // Properties␍ //--------------------------------------␍ /**␍ * @private␍ */␍ private var observers : Array;␍␍ //--------------------------------------␍ // internal Methods␍ //--------------------------------------␍ /**␍ * Adds formItems to be subscribed.␍ * Returns <code>IFormEventObserver</code> to force IForm instance to subscribe this observer class.␍ * ␍ * @param observerItem Iform object to be subscribed events.␍ * @return IFormEventObserver␍ * ␍ */␍ public function subscribeObserver(observerItem : IForm) : IFormEventObserver {␍ var duplicate : Boolean = false;␍ for (var i : uint = 0;i < observers.length; i++) {␍ if (observers[i] == observerItem) {␍ duplicate = true;␍ }␍ }␍ if (!duplicate) {␍ observers.push(observerItem);␍ }␍ return this;␍ }␍␍ /**␍ * Removes <code>Iform</code> from subscription.␍ * ␍ * @param observerItem Iform instance to be unsubscribed.␍ */␍ public function unsubscribeObserver(observerItem : IForm) : void {␍ for (var i : uint = 0;i < observers.length; i++) {␍ if (observers[i] == observerItem) {␍ observers.splice(i, 1);␍ }␍ }␍ }␍␍ /**␍ * Updates events every <code>IForm</code> in subscription.␍ * ␍ * @param target String <code>FormLayoutEvent</code> type and its value.␍ * @param value Object contains value associated <code>FormLayoutEvent</code>␍ * ␍ */␍ public function setUpdate(target : String, value : Object) : void {␍ for (var i:Object in this.observers) {␍ observers[i].update(target, value);␍ }␍ }␍ }␍}
+320
View File
@@ -0,0 +1,320 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.containers.formClasses {
import com.yahoo.astra.containers.formClasses.FormItemContainer;
import com.yahoo.astra.containers.formClasses.FormItemLabel;
import com.yahoo.astra.containers.formClasses.FormLayoutStyle;
import com.yahoo.astra.containers.formClasses.IForm;
import com.yahoo.astra.events.FormDataManagerEvent;
import com.yahoo.astra.events.FormLayoutEvent;
import com.yahoo.astra.layout.LayoutContainer;
import com.yahoo.astra.layout.LayoutManager;
import com.yahoo.astra.layout.events.LayoutEvent;
import com.yahoo.astra.layout.modes.BoxLayout;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
/**
* Defines a label and one or more children arranged horizontally or vertically. ␍ * Similar to Flex FormItem, the label is vertically aligned with the first child in the FormItem container and is right-aligned in the region to the left of the container.␍ * It is designed to be nested in a Form, but it can be used as a standalone class as desired.␍ * ␍ * @example The following code shows a use of <code>FormItem</code>:␍ * <listing version="3.0">␍ * ␍ * var addressInput_line_1:TextInput = new TextInput();␍ * var addressInput_line_2:TextInput = new TextInput();␍ * ␍ * var addressFormItem : FormItem = new FormItem("Address", addressInput_line_1, addressInput_line_2);␍ * addressFormItem.itemAlign = FormLayoutStyle.VERTICAL;␍ * addressFormItem.labelTextFormat = new TextFormat("Arial", 11, 0xFF00FF);␍ * addressFormItem.labelWidth = 60;␍ * addressFormItem.showErrorMessageBox = true;␍ * addressFormItem.required = true;␍ * </listing>
* @see com.yahoo.astra.fl.containers.Form
* @author kayoh
*/
public class FormItem extends LayoutContainer implements IForm {
//--------------------------------------␍ // Constructor␍ //--------------------------------------␍ /**␍ * Constructor.␍ * The parameter can be either String or DisplayObject. ␍ * If the first argument is <code>Sting</code>, it will be set as a label on leftside and any string afterward will be a label aligned with other DisplayObjects.␍ * ␍ * @param args String or DisplayObjectsto be contained in the FormItem.␍ */
public function FormItem( ...args ) {␍ formItemLayout = new BoxLayout();
formItemLayout.horizontalGap = horizontalGap;
super(formItemLayout);␍ ␍ this.autoMask = false;
_skin = new Sprite();␍ formItemLayout.addClient(_skin, {includeInLayout:false});␍ this.addChild(_skin);␍ ␍ ␍ errorGrayBoxSpriteHolder = new Sprite();
formItemLayout.addClient(errorGrayBoxSpriteHolder, {includeInLayout:false});
this.addChild(errorGrayBoxSpriteHolder);␍ ␍ //attach Label␍ var i : int = 0;␍ if(args[0] is String) {
var argStr : String = args[0].toString();␍ labelItem = addLabel(argStr);
i = 1;␍ } else {␍ labelItem = addLabel(null);
horizontalGap = 0;␍ }␍ ␍ //attach ItemContainer␍ itemContainer = new FormItemContainer();␍ if(itemAlign) itemContainer.itemAlign = this.itemAlign;␍ if(itemHorizontalGap) itemContainer.itemHorizontalGap = this.itemHorizontalGap;␍ if(itemVerticalGap) itemContainer.itemVerticalGap = this.itemVerticalGap;␍␍ itemContainer.addEventListener(LayoutEvent.LAYOUT_CHANGE, handler_fomItemContainer_listener, false, 0, true);␍ ␍ for (i;i < args.length; i++) {␍ var curObject : * = args[i];␍ if(curObject is String) {␍ curObject = addTextField(curObject);␍ textfieldArray.push(curObject);␍ }␍ if(curObject is Array) {␍ var curObjectArr : Array = curObject as Array;␍ var curObjectlength : int = curObjectArr.length;␍ for (var j : int = 0;j < curObjectlength; j++) {␍ var curObj : * = curObject[j];␍ if(curObj is String) {␍ curObj = addTextField(curObj);␍ textfieldArray.push(curObj);␍ }␍ itemContainer.addItem(curObj);␍ }␍ } else {␍ itemContainer.addItem(curObject); ␍ }␍ }␍␍ this.addChild(labelItem);␍ this.addChild(itemContainer);␍ }
//--------------------------------------␍ // Properties␍ //--------------------------------------␍ /**␍ * @private␍ */␍ private var formItemLayout : BoxLayout = null;␍ /**␍ * @private␍ */␍ private var errorGrayBoxSprite : Sprite = null;
/**
* @private
*/
private var errorGrayBoxSpriteHolder : Sprite;␍ /**␍ * @private␍ */␍ private var textfieldArray : Array = [];␍ /**␍ * @private␍ */␍ private var formEventObserver : IFormEventObserver = null;
/**
* @private
*/␍ private var sidePadding : Number = NaN;
/**␍ * @private␍ */␍ private var _skin : Sprite ;
/**␍ * Background skin of FormItem.
* ␍ * @param value DisplayObject␍ */
public function get skin() : DisplayObject {␍ return _skin;␍ }
/**␍ * @private␍ */␍ public function set skin(value : DisplayObject) : void {␍ _skin.addChild(value);␍ }
/**␍ * @private␍ */␍ private var _gotResultBool : Boolean = true;
/**␍ * @private␍ * ␍ * When <code>multipleResult</code> is <code>true</code>, used as a reference to determine to pass/fail in validation in <code>FormDataManager</code>.␍ * In case <code>multipleResult</code> is <code>true</code>, ␍ * In case <code>FormItem</code> has multiple form inputs to validate and part of them are not passed the validation, <code>gotResultBool</code> will be set as <code>false</code> to show ErrorMessageBox or ErrorMessageMessage.␍ * ␍ * @default true;␍ */␍ public function get gotResultBool() : Boolean {␍ return _gotResultBool;␍ }
/**␍ * @private␍ */␍ public function set gotResultBool(value : Boolean) : void {␍ _gotResultBool = value;␍ }
/**␍ * @private␍ * Storage for the showErrorMessageBox property.␍ */␍ private var _showErrorMessageBox : Boolean = false;
/**␍ * Decides to present error result message box : a translucent gray box(alpha:.2 , color:0x666666) behind the item that failed to validation.<br>␍ * ␍ * @default false;␍ */␍ public function get showErrorMessageBox() : Boolean {␍ return _showErrorMessageBox;␍ }
/**␍ * @private␍ */␍ public function set showErrorMessageBox(value : Boolean) : void {
if(isFormHeadingLabel) return;
if(_showErrorMessageBox == value) return;␍ _showErrorMessageBox = value;␍ (value) ? this.addListeners() : this.removeListeners();␍ }
/**␍ * @private␍ * Storage for the showErrorMessageText property.␍ */␍ private var _showErrorMessageText : Boolean = false;
/**␍ * Decides to present error result string: a error message returned from <code>FormDataManager</code> that failed to validate.␍ * ␍ * @default false;␍ */␍ public function get showErrorMessageText() : Boolean {␍ return _showErrorMessageText;␍ }
/**␍ * @private␍ */␍ public function set showErrorMessageText(value : Boolean) : void {
if(isFormHeadingLabel) return;
if(_showErrorMessageText == value) return;␍ _showErrorMessageText = value;
if(value) {
if(!instructionText) instructionText = " ";
addListeners();␍ } else {
removeListeners();
}
}
/**␍ * @private␍ * Storage for the itemContainer property.␍ */␍ private var _itemContainer : FormItemContainer = null;
/**␍ * @private␍ */␍ public function get itemContainer() : FormItemContainer {␍ return _itemContainer;␍ }
/**␍ * @private␍ */␍ public function set itemContainer(value : FormItemContainer) : void {␍ _itemContainer = value;␍ }
/**␍ * @private␍ * Storage for the labelItem property.␍ */␍ private var _labelItem : FormItemLabel = null;
/**␍ * @private␍ * FormItemLabel to contain a label in a FormItem.␍ * ␍ * @param value LayoutContainer to be used as label container.␍ */␍ public function get labelItem() : FormItemLabel {␍ return _labelItem;␍ }
/**␍ * @private␍ */␍ public function set labelItem(value : FormItemLabel) : void {␍ _labelItem = value;␍ }
/**␍ * @private␍ * Storage for the errorString property.␍ */␍ private var _errorString : String = FormLayoutStyle.DEFAULT_ERROR_STRING;
/**␍ * Sets and gets the text to be used for validation error. ␍ * ␍ * @param value String to be set as error message.␍ * @default "Invalid input"␍ */␍ public function get errorString() : String {␍ return _errorString;␍ }
/**␍ * @private␍ */␍ public function set errorString(value : String) : void {␍ _errorString = value;␍ }
/**
* @private
*/
private var _instructionText : String;
/**␍ * Sets and gets an additional text label bottom of the item field␍ */
public function get instructionText() : String {
return itemContainer.instructionText;␍ }
/**
* @private
*/␍ public function set instructionText(value : String) : void {
if(!_instructionText) _instructionText = value;
itemContainer.instructionText = value;
}
/**␍ * @private␍ * Storage for the labelAlign property.␍ */␍ private var _labelAlign : String = FormLayoutStyle.DEFAULT_LABELALIGN;
/**␍ * <p>Alignment of labels in each FormItems.</p>
* <p>Acceptable values for the <code>labelAlign</code>:
* <dl>
* <dt><strong><code>FormLayoutStyle.RIGHT</code></strong>(default) : right end of label field.</dt>
* <dt><strong><code>FormLayoutStyle.LEFT</code></strong> : far left of <code>Form</code>.</dt>
* <dt><strong><code>FormLayoutStyle.TOP</code></strong> : will be stacked vertically</dt>
* </dl>
* </p>␍ * @default FormLayoutStyle.DEFAULT_LABELALIGN(FormStyle.RIGHT)␍ * @param value String of alignment.␍ */␍ public function get labelAlign() : String {␍ return _labelAlign;␍ }
/**␍ * @private␍ */␍ public function set labelAlign(value : String) : void {␍ if(_labelAlign == value) return; ␍ _labelAlign = value;␍ ␍ this.updatelabelAlign(value);␍ }
/**␍ * @private␍ * Storage for the labelWidth property.␍ */␍ private var _labelWidth : Number = NaN;
/**␍ * Sets and gets the width of label field.␍ * <code>Form</code> automatically matches the width of labels on the longest label among FormItems in it. ␍ * However, if consistance width of label field needed, you can fix the size of the label by setting <code>labelWidth</code>.
* ␍ * @param value Number of pixels.
* @default NaN␍ */␍ public function get labelWidth() : Number {␍ return _labelWidth;␍ }
/**␍ * @private␍ */␍ public function set labelWidth(value : Number) : void {␍ if(_labelWidth == value) return;␍ _labelWidth = value;␍ ␍ if(this.labelItem) { ␍ this.labelItem.preferredLabelWidth = value;␍ }␍ }
/**␍ * @private␍ * Storage for the required property.␍ */␍ private var _required : Boolean = false;
/**␍ * Sets and gets the requirement of the item(s).␍ * Case of <code>true</code> Form inserts a red asterisk (*) character on the spot that a <code>indicatorLocation</code> has specified. ␍ * ␍ * @default false␍ */␍ public function get required() : Boolean {␍ return _required; ␍ }
/**␍ * @private␍ */␍ public function set required(value : Boolean) : void {␍ _required = value;␍ if(required) labelItem.required = true;␍ if(required) itemContainer.required = true;␍ ␍ if(this.itemContainer) itemContainer.update_indicatiorLocation(indicatorLocation);␍ if(this.labelItem) labelItem.update_indicatiorLocation(indicatorLocation);␍ }
/**␍ * @private␍ * Storage for the indicatiorLocation property.␍ */␍ private var _indicatorLocation : String = FormLayoutStyle.DEFAULT_INDICATOR_LOCATION;
/**␍ * <p>Sets and gets the location of required indicator(~~) when the item is set to be required.</p>␍ * <p>Acceptable values for the <code>indicatorLocation</code>:
* <dl>
* <dt><strong><code>FormLayoutStyle.INDICATOR_LABEL_RIGHT</code></strong>(default) : between a label and items.</dt>␍ * <dt><strong><code>FormLayoutStyle.INDICATOR_LEFT</code></strong> : left of a label.</dt>␍ * <dt><strong><code>FormLayoutStyle.INDICATOR_RIGHT</code></strong> : right of items.</dt>
* </dl>␍ * </p>␍ * @default FormLayoutStyle.DEFAULT_INDICATOR_LOCATION(FormLayoutStyle.RIGHT)␍ */␍ public function get indicatorLocation() : String {␍ return _indicatorLocation; ␍ }
/**␍ * @private␍ */␍ public function set indicatorLocation(value : String) : void {␍ if(_indicatorLocation == value) return;␍ _indicatorLocation = value;␍ if(itemContainer) itemContainer.update_indicatiorLocation(value);␍ if(labelItem) labelItem.update_indicatiorLocation(value);␍ }
/**␍ * @private␍ * Storage for the itemAlign property.␍ */
private var _itemAlign : String = FormLayoutStyle.DEFAULT_ITEM_ALIGN;
/**␍ * <p>Set alignment of multiple items in a FormItem.</p>
* <p>Acceptable values for the <code>itemAlign</code>:
* <dl>
* <dt><strong><code>FormLayoutStyle.HORIZONTAL</code></strong>(default)</dt>
* <dt><strong><code>FormLayoutStyle.VERTICAL</code></strong></dt>
* </dl>␍ * </p>␍ * @default FormLayoutStyle.DEFAULT_ITEM_ALIGN(FormLayoutStyle.HORIZONTAL)␍ */␍ public function get itemAlign() : String {
return _itemAlign;
}
/**␍ * @private␍ */␍ public function set itemAlign(value : String) : void {
if(_itemAlign == value) return;
_itemAlign = value;
if(this.itemContainer) itemContainer.itemAlign = value;
}
/**␍ * @private␍ * Storage for the itemVerticalGap property.␍ */
private var _itemVerticalGap : Number = FormLayoutStyle.DEFAULT_FORMITEM_VERTICAL_GAP;
/**␍ * The number of pixels in gaps between each items in a <code>FormItem</code> verticaly.␍ * ␍ * @default FormLayoutStyle.DEFAULT_FORMITEM_VERTICAL_GAP(6px)␍ */␍ public function get itemVerticalGap() : Number {
return _itemVerticalGap;
}
/**␍ * @private␍ */␍ public function set itemVerticalGap(value : Number) : void {
if(itemVerticalGap == value) return;␍ _itemVerticalGap = itemContainer.itemVerticalGap = value;
}
/**␍ * @private␍ * Storage for the itemHorizontalGap property.␍ */
private var _itemHorizontalGap : Number = FormLayoutStyle.DEFAULT_FORMITEM_HORIZONTAL_GAP;
/**␍ * The number of pixels in gaps between each items in a <code>FormItem</code> horizontaly.␍ * ␍ * @default FormLayoutStyle.DEFAULT_FORMITEM_HORIZONTAL_GAP(6px)␍ */␍ public function get itemHorizontalGap() : Number {
return _itemHorizontalGap;
}
/**␍ * @private␍ */␍ public function set itemHorizontalGap(value : Number) : void {␍ if(itemHorizontalGap == value) return;␍ _itemHorizontalGap = itemContainer.itemHorizontalGap = value;␍ }
/**␍ * @private␍ * Storage for the horizontalGap property.␍ */
private var _horizontalGap : Number = FormLayoutStyle.DEFAULT_HORIZONTAL_GAP;
/**␍ * The number of pixels in gaps between labels and items.␍ * ␍ * @default FormLayoutStyle.DEFAULT_HORIZONTAL_GAP(6 px)␍ * ␍ * @see com.yahoo.astra.containers.formClasses.FormLayoutStyle␍ */␍ public function get horizontalGap() : Number {
return _horizontalGap;
}
/**␍ * @private␍ */␍ public function set horizontalGap(value : Number) : void {
if(_horizontalGap == value) return;
_horizontalGap = value;
formItemLayout.horizontalGap = value;
}
/**␍ * @private␍ * Storage for the multipleResult property.␍ */␍ private var _hasMultipleItems : Boolean = false;
/**␍ * @private␍ * ␍ * A Boolean value whether <code>FormItem</code> has multiple form inputs to collect data. ␍ * <code>Form</code> sets this value to <code>true</code> when the current <code>FormItem</code> has multiple <code>id</code>s.␍ * <p>No explicit use.</p>␍ * ␍ * ␍ * @deafult false␍ */␍ public function get hasMultipleItems() : Boolean {␍ return _hasMultipleItems; ␍ }
/**␍ * @private␍ */␍ public function set hasMultipleItems(value : Boolean) : void {␍ _hasMultipleItems = value;
}
/**␍ * @private␍ * Storage for the isHeadLabel property.␍ */␍ private var _isFormHeadingLabel : Boolean = false;
/**␍ * @private␍ * ␍ * A Boolean value whether current <code>FormItem</code> is used as a container for FromHeading.␍ * <code>Form</code> sets this value to <code>true</code> when the current <code>FormItem</code> is FormHeading container.␍ * ␍ */␍ public function get isFormHeadingLabel() : Boolean {
return _isFormHeadingLabel;␍ }
/**
* @private
*/␍ public function set isFormHeadingLabel(value : Boolean) : void {␍ _isFormHeadingLabel = value;␍ if(itemContainer) itemContainer.isFormHeadingLabel = value;␍ }
/**␍ * @private␍ * Storage for the labelTextFormat property.␍ */␍ private var _labelTextFormat : TextFormat = FormLayoutStyle.defaultStyles["textFormat"];
/**␍ * Gets and sets the <code>TextFormat</code> of the label.␍ * ␍ * @default TextFormat("_sans", 11, 0x000000, false, false, false, "", "", TextFormatAlign.LEFT, 0, 0, 0, 0)␍ */␍ public function get labelTextFormat() : TextFormat {␍ var TxtFormat : TextFormat = (_labelTextFormat) ? _labelTextFormat : FormLayoutStyle.defaultStyles["textFormat"];␍ return TxtFormat;␍ }
/**␍ * @private␍ */␍ public function set labelTextFormat(value : TextFormat) : void {␍ if(_labelTextFormat == value) return;␍ _labelTextFormat = value;␍ if(value is TextFormat && labelItem) {␍ labelItem.preferredLabelTextFormat = value;␍ }␍ }
/**␍ * @private␍ * Storage for the instructionTextFormat property.␍ */␍ private var _instructionTextFormat : TextFormat;
/**␍ * Gets and sets the <code>TextFormat</code> of the <code>instructionText</code>.␍ * @default TextFormat("_sans", 10, 0x000000, false, false, false, "", "", TextFormatAlign.LEFT, 0, 0, 0, 0)␍ */␍ public function get instructionTextFormat() : TextFormat {␍ var TxtFormat : TextFormat = (_instructionTextFormat) ? _instructionTextFormat : FormLayoutStyle.defaultStyles["instructionTextFormat"];␍ return TxtFormat;␍ }
/**␍ * @private␍ */␍ public function set instructionTextFormat(value : TextFormat) : void {␍ _instructionTextFormat = value;␍ if(itemContainer) {␍ if(!formEventObserver) subscribeObserver(new FormEventObserver());␍ formEventObserver.setUpdate(FormLayoutEvent.UPDATE_INSTRUCTION_FONT_CHANGE, value);␍ }␍ }
/**␍ * Gets and sets DisplayObject of the required indicator. Default is "~~" in red(0xff0000). Set any DisplayObject to apply the skin of the indicator.
* @return RequiredIndicator␍ */␍ public function get requiredIndicator() : DisplayObject {␍ return (labelItem.requiredIndicator) ? labelItem.requiredIndicator : (itemContainer.requiredIndicator) ? itemContainer.requiredIndicator : null;␍ }
/**
* @private
*/
public function set requiredIndicator(value : DisplayObject) : void {
FormLayoutStyle.defaultStyles["indicatorSkin"] = value;
}
/**␍ * ␍ * @private ␍ * ␍ * Sets FormEventObserver as an event observer class and register IForm class into it.␍ * Returns <code>IFormEventObserver</code>(the return type of <code>FormEventObserver.subscribeObserver</code>) to force to add IForm instance into formEventObserver's subscription for notifing and updating FormEvents.␍ * ␍ */␍ public function subscribeObserver(formEventObserver : IFormEventObserver ) : IFormEventObserver {␍ this.formEventObserver = formEventObserver;␍ ␍ itemContainer.subscribeObserver(formEventObserver);␍ labelItem.subscribeObserver(formEventObserver);␍ ␍ return formEventObserver.subscribeObserver(this);␍ }
/**␍ * @private ␍ * ␍ * Update FormLayoutEvents and properties.␍ * Mainly, it will be tiggered by <code>setUpdate</code> from <code>FormEventObserver</code> class to notify <code>FormLayoutEvent</code>s.␍ * ␍ */␍ public function update(target : String , value : Object = null) : void {␍ switch(target) {␍ case FormLayoutEvent.UPDATE_LABEL_FONT_CHANGE:␍ updateTextFields(value as TextFormat);␍ break;␍ case FormLayoutEvent.UPDATE_HORIZONTAL_GAP:
this.horizontalGap = Number(value);␍ break;␍ case FormLayoutEvent.UPDATE_LABEL_ALIGN:␍ this.labelAlign = String(value);␍ break;␍ case FormLayoutEvent.UPDATE_ERROR_MSG_TEXT:␍ this.showErrorMessageText = true;␍ break;␍ case FormLayoutEvent.UPDATE_ERROR_MSG_BOX:␍ this.showErrorMessageBox = true;␍ break;
case FormLayoutEvent.UPDATED_PADDING_RIGHT:
this.sidePadding = Number(value);
break;
}␍ }
//--------------------------------------␍ // Private Methods␍ //--------------------------------------␍ /**␍ * @private␍ */␍ private function handler_fomItemContainer_listener(e : LayoutEvent) : void {␍ this.dispatchEvent(new LayoutEvent(LayoutEvent.LAYOUT_CHANGE));
}
/**␍ * @private␍ */␍ private function label_change(e : FormLayoutEvent) : void {␍ ␍ var label : FormItemLabel = e.target as FormItemLabel;␍ if(this.labelWidth != label.actualLabelTextWidth) this.labelWidth = label.actualLabelTextWidth;␍ this.dispatchEvent(new FormLayoutEvent(FormLayoutEvent.LABEL_ADDED));␍ }
/**␍ * @private␍ */␍ private function updateTextFields(textformat : TextFormat) : void {␍ var arrLength : int = textfieldArray.length;␍ if(arrLength < 1) return;␍ for (var i : int = 0;i < arrLength; i++) {␍ var textFieldToChg : TextField = textfieldArray[i];␍ var str : String = textFieldToChg.text;␍ textFieldToChg.defaultTextFormat = textformat;␍ textFieldToChg.htmlText = str;␍ }␍ }
/**␍ * @private␍ */␍ private function updatelabelAlign(value : String) : void {␍ switch(value) {␍ case FormLayoutStyle.TOP:␍ formItemLayout.direction = "vertical";␍ break;␍ ␍ case FormLayoutStyle.LEFT:␍ formItemLayout.direction = "horizontal";␍ break;␍ ␍ case FormLayoutStyle.RIGHT:␍ formItemLayout.direction = "horizontal";␍ break; ␍ }␍ ␍ if(this.labelItem) LayoutManager.update(this.labelItem, "labelAlign", value);␍ }
/**␍ * @private␍ */␍ private function addTextField(value : String) : TextField {
var tf : TextField = FormLayoutStyle.defaultTextField;
tf.defaultTextFormat = FormLayoutStyle.defaultStyles["textFormat"];
tf.autoSize = TextFieldAutoSize.LEFT;
tf.htmlText = value;
return tf;
}
private function addLabel( txt : String = "") : FormItemLabel {
var labelItem : FormItemLabel = new FormItemLabel();
labelItem.addEventListener(FormLayoutEvent.LABEL_ADDED, label_change, false, 0, true);
labelItem.attLabel(txt);
return labelItem;
}
/**␍ * @private␍ */␍ private function handler_validation_passed(e : FormDataManagerEvent = null) : void {
gotResultBool &&= true;
if(!gotResultBool && hasMultipleItems) return;␍ if(showErrorMessageText && itemContainer.instructionTextField) instructionText = " ";␍ if(_instructionText) instructionText = _instructionText;␍ if(errorGrayBoxSprite && showErrorMessageBox) errorGrayBoxSprite.visible = false;
}
/**␍ * @private␍ */␍ private function handler_validation_failed(e : FormDataManagerEvent = null) : void {␍ gotResultBool = false;
if(showErrorMessageText) instructionText = e.errorMessage ? e.errorMessage.toString() : this.errorString;␍ if(!showErrorMessageBox) return;
if(!errorGrayBoxSprite) {␍ // Make gray box around form with 2 px paddings.
var w : Number = this.width;
var form : Object = this.parent.parent;
// If this FormItem is a part of Form, width of gray box will be set to width of Form.
if(this.parent.parent is IForm && form.paddingRight is Number) {
var formWidth : Number = form.width - form.paddingRight - form.paddingLeft;
if(formWidth > w) w = formWidth;
}
errorGrayBoxSprite = drawErrorGrayBox(-2, -2, w + 4, this.height + 4, FormLayoutStyle.defaultStyles["errorBoxColor"], FormLayoutStyle.defaultStyles["errorBoxAlpha"]);␍ errorGrayBoxSpriteHolder.addChild(errorGrayBoxSprite);
}
errorGrayBoxSprite.visible = true;
}
/**␍ * @private␍ */␍ private function addListeners() : void {␍ this.addEventListener(FormDataManagerEvent.VALIDATION_PASSED, handler_validation_passed, false, 0, true);␍ this.addEventListener(FormDataManagerEvent.VALIDATION_FAILED, handler_validation_failed, false, 0, true);␍ }
/**␍ * @private␍ */␍ private function removeListeners() : void {
this.removeEventListener(FormDataManagerEvent.VALIDATION_PASSED, handler_validation_passed);␍ this.removeEventListener(FormDataManagerEvent.VALIDATION_FAILED, handler_validation_failed);␍ }
/**
* @private
*/
private function drawErrorGrayBox(x : Number, y : Number,w : Number, h : Number, clr : uint = 0xffffff, alpha : Number = 0) : Sprite {
var sprite : Sprite = new Sprite();
sprite.graphics.beginFill(clr, alpha);
sprite.graphics.drawRect(x, y, w, h);
sprite.graphics.endFill();
return sprite;
}
}
}
@@ -0,0 +1,39 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.containers.formClasses {␍ import com.yahoo.astra.containers.formClasses.FormLayoutStyle;␍ import com.yahoo.astra.containers.formClasses.IForm;␍ import com.yahoo.astra.containers.formClasses.RequiredIndicator;␍ import com.yahoo.astra.events.FormLayoutEvent;␍ import com.yahoo.astra.layout.LayoutContainer;␍ import com.yahoo.astra.layout.modes.BoxLayout;␍ ␍ import flash.display.DisplayObject;␍ import flash.text.TextField;␍ import flash.text.TextFormat;
␍ /**␍ * FormItemContainer contains, aligns form inputs(DisplayObjects) in <code>LayoutContainer</code> and handles required indicators as part of <code>FormItem</code>.␍ * @see com.yahoo.astra.containers.formClasses.FormItem␍ * @author kayoh␍ */␍ public class FormItemContainer extends LayoutContainer implements IForm {
//--------------------------------------␍ // Constructor␍ //--------------------------------------␍␍ /**␍ * Constructor.␍ */␍ public function FormItemContainer(direction : String = FormLayoutStyle.HORIZONTAL) {␍ itemContainerLayout = new BoxLayout();␍ itemContainerLayout.direction = direction;␍ super(itemContainerLayout);␍ init();␍ }␍␍␍ private var formEventObserver : IFormEventObserver = null;␍␍ ␍ //--------------------------------------␍ // Properties␍ //--------------------------------------␍ /**␍ * @private␍ */
internal var reqBox_l : RequiredIndicator = null;␍ /**␍ * @private␍ */␍ internal var reqBox_r : RequiredIndicator = null;␍ /**␍ * @private␍ */␍ internal var gotRequiredField : Boolean = false;
/**␍ * @private␍ */␍ internal var instructionTextField : TextField = null;␍ /**␍ * @private␍ */␍ internal var subItemContainer : LayoutContainer = null;
/**␍ * @private␍ */␍ private var itemContainerLayout : BoxLayout = null;␍ /**␍ * @private␍ */␍ private var itemLayoutMode : BoxLayout = null;␍ /**␍ * @private␍ */␍ private var preferredInstrunctionTextformat : TextFormat;
/**␍ * @private␍ */␍ private var itemOutterContainer : LayoutContainer = null;␍ /**␍ * @private␍ */␍ private var ItemOutterLayoutMode : BoxLayout = null;␍ /**␍ * @private␍ */
private var _isformHeadingLabel : Boolean = false;
␍ /**␍ * Setting whether this ItemContainer is assigned for FormHeading or not.␍ * @private␍ */
internal function get isFormHeadingLabel() : Boolean {␍ return _isformHeadingLabel;␍ }
␍ /**␍ * @private␍ */
internal function set isFormHeadingLabel(value : Boolean) : void {␍ if(_isformHeadingLabel == value) return;␍ _isformHeadingLabel = value;␍ }
␍ /**␍ * @private␍ */␍ private var _itemAlign : String = FormLayoutStyle.DEFAULT_ITEM_ALIGN;
␍ /**␍ * @copy com.yahoo.astra.containers.formClasses.FormItem#itemAlign␍ */␍ public function get itemAlign() : String {␍ return _itemAlign;␍ }
␍ /**␍ * @private␍ */␍ public function set itemAlign(value : String) : void {␍ if(_itemAlign == value) return;␍ itemLayoutMode.direction = _itemAlign = value;␍ }
␍ /**␍ * @private␍ */␍ private var _itemVerticalGap : Number = FormLayoutStyle.DEFAULT_FORMITEM_VERTICAL_GAP ;
␍ /**␍ * @private␍ */␍ internal function get itemVerticalGap() : Number {␍ return _itemVerticalGap;␍ }
␍ /**␍ * @private␍ */␍ internal function set itemVerticalGap(value : Number) : void {␍ if(itemVerticalGap == value) return;␍ _itemVerticalGap = itemLayoutMode.verticalGap = value;␍ }
␍ /**␍ * @private␍ */␍ private var _itemHorizontalGap : Number = FormLayoutStyle.DEFAULT_FORMITEM_HORIZONTAL_GAP;
␍ /**␍ * The number of pixels in gaps between each items in a formItems horizontaly.␍ */␍ internal function get itemHorizontalGap() : Number {␍ return _itemHorizontalGap;␍ }
␍ /**␍ * @private␍ */␍ internal function set itemHorizontalGap(value : Number) : void {␍ if(itemHorizontalGap == value) return;␍ _itemHorizontalGap = itemLayoutMode.horizontalGap = value;␍ }
␍ /**␍ * @private␍ */ ␍ internal var _labelAlign : String = FormLayoutStyle.DEFAULT_LABELALIGN;
␍ /**␍ * @private␍ */␍ internal function get labelAlign() : String {␍ return _labelAlign; ␍ }
␍ /**␍ * @private␍ */␍ internal function set labelAlign(value : String) : void {␍ if(_labelAlign == value) return;␍ ␍ _labelAlign = value;␍ }
␍ /**␍ * @private␍ */ ␍ internal var _indicatorLocation : String = FormLayoutStyle.INDICATOR_NONE;
␍ /**␍ * @private ␍ */␍ internal function get indicatorLocation() : String {␍ return _indicatorLocation; ␍ }
␍ /**␍ * @private␍ */␍ internal function set indicatorLocation(value : String) : void {␍ if(_indicatorLocation == value) return;␍ ␍ _indicatorLocation = value;␍ update_indicatiorLocation(value);␍ }
␍ /**␍ * @private␍ */ ␍ private var _required : Boolean = false;
␍ /**␍ * @private␍ */␍ internal function get required() : Boolean {␍ return _required; ␍ }
␍ /**␍ * @private␍ */␍ internal function set required(value : Boolean) : void {␍ if(_required == value) return;␍ _required = value;␍ }
␍ /**␍ * @private␍ */␍ internal function get instructionText() : String {␍ return (instructionTextField)? instructionTextField.htmlText:null;␍ }␍ /**␍ * @private␍ */␍ internal function set instructionText(value : String) : void {␍ if(!instructionTextField) {␍ instructionTextField = FormLayoutStyle.instructionTextField;␍ if(preferredInstrunctionTextformat) instructionTextField.defaultTextFormat = preferredInstrunctionTextformat;␍ itemOutterContainer.addChild(instructionTextField);␍ }␍ instructionTextField.htmlText = value;␍ }␍␍ ␍ //--------------------------------------␍ // Public Methods␍ //--------------------------------------␍ /**␍ * @private␍ * @see com.yahoo.astra.containers.formClasses.FormItem#subscribeObserver ␍ */␍ public function subscribeObserver(formEventObserver : IFormEventObserver) : IFormEventObserver {␍ this.formEventObserver = formEventObserver; ␍ ␍ reqBox_l.subscribeObserver(formEventObserver);␍ reqBox_r.subscribeObserver(formEventObserver);␍ ␍ return formEventObserver.subscribeObserver(this);␍ }␍␍ /**␍ * @private␍ */␍ internal function get requiredIndicator() : DisplayObject {␍ var curIndicator : DisplayObject = (reqBox_l.requiredIndicator) ? reqBox_l.requiredIndicator : (reqBox_r.requiredIndicator) ? reqBox_r.requiredIndicator : null;␍ return curIndicator;␍ }␍␍ /**␍ * @private␍ * @see com.yahoo.astra.containers.formClasses.FormItem#update ␍ */␍ public function update(target : String, value : Object = null) : void {␍ ␍ switch(target) {␍ ␍ case FormLayoutEvent.UPDATE_GOT_REQUIRED_ITEM:␍ gotRequiredField = true;␍ update_indicatiorLocation(indicatorLocation);␍ break;␍ ␍ case FormLayoutEvent.UPDATE_INSTRUCTION_FONT_CHANGE:␍ updateTextFields(value as TextFormat);␍ break;␍ ␍ case FormLayoutEvent.UPDATE_ERROR_MSG_TEXT:␍ if(isFormHeadingLabel) return;␍ if(!instructionTextField) instructionText = " ";␍ break;␍ ␍ case FormLayoutEvent.UPDATE_ITEM_VERTICAL_GAP:␍ ␍ if(itemVerticalGap == Number(value)) return;␍ itemVerticalGap = itemLayoutMode.verticalGap = Number(value);␍ break;␍ ␍ case FormLayoutEvent.UPDATE_ITEM_HORIZONTAL_GAP:␍ if(itemHorizontalGap == Number(value)) return;␍ itemHorizontalGap = itemLayoutMode.horizontalGap = Number(value);␍ break;␍ ␍ case FormLayoutEvent.UPDATE_REQUIRED_ITEM:␍ ␍ if(required == Boolean(value)) return;␍ required = Boolean(value);␍ break;␍ ␍ case FormLayoutEvent.UPDATE_INDICATOR_LOCATION:␍ indicatorLocation = String(value);␍ break;␍ ␍ case FormLayoutEvent.UPDATE_LABEL_ALIGN:␍ this.labelAlign = String(value);␍ update_indicatiorLocation(indicatorLocation);␍ break;␍ }␍ }␍␍ ␍ ␍ ␍ //--------------------------------------␍ // Private Methods␍ //--------------------------------------␍␍ /**␍ * @private␍ */ ␍ private function init() : void {␍ ␍ reqBox_l = new RequiredIndicator();␍ reqBox_r = new RequiredIndicator();␍ ␍ ␍ itemOutterContainer = attItemOutterContainer();␍ subItemContainer = attItemContainer();␍ ␍ this.autoMask = itemOutterContainer.autoMask = subItemContainer.autoMask = false;␍␍ this.addChild(reqBox_l);␍ itemOutterContainer.addChild(subItemContainer);␍ this.addChild(itemOutterContainer);␍ this.addChild(reqBox_r);␍ }␍␍ ␍ /**␍ * @private␍ */␍ private function attItemOutterContainer() : LayoutContainer {␍ ItemOutterLayoutMode = new BoxLayout();␍ ItemOutterLayoutMode.direction = FormLayoutStyle.VERTICAL ;␍ return new LayoutContainer(ItemOutterLayoutMode);␍ }
␍ /**␍ * @private␍ */␍ private function attItemContainer() : LayoutContainer {␍ itemLayoutMode = new BoxLayout();␍ itemLayoutMode.direction = itemAlign; ␍ itemLayoutMode.verticalGap = itemVerticalGap;␍ itemLayoutMode.horizontalGap = itemHorizontalGap;␍ return new LayoutContainer(itemLayoutMode);␍ }
␍ ␍ ␍ /**␍ * @private␍ */␍ protected function updateTextFields(value : TextFormat) : void {␍ if(!instructionTextField && value is TextFormat) { ␍ preferredInstrunctionTextformat = value;␍ return;␍ }␍ ␍ var textFieldToChg : TextField = instructionTextField;␍ var str : String = textFieldToChg.text;␍ textFieldToChg.defaultTextFormat = value;␍ textFieldToChg.htmlText = str;␍ }
␍ //--------------------------------------␍ // Internal Methods␍ //--------------------------------------␍ /**␍ * Adds DisplayObjects into the <code>ItemContainer</code>.␍ * ␍ * @param value DisplayObject.␍ */␍ public function addItem(value : DisplayObject) : void {␍ subItemContainer.addChild(value);␍ }␍␍ ␍ /**␍ * @private␍ */␍ protected function cleanRequiredIndicatorBoxs() : void {␍ reqBox_l.cleanBox();␍ reqBox_r.cleanBox();␍ }␍␍ ␍ /**␍ * @private␍ */␍ internal function update_indicatiorLocation(value : String) : void {␍ cleanRequiredIndicatorBoxs();␍ switch(value) {␍ case FormLayoutStyle.INDICATOR_RIGHT:␍ if(required) reqBox_r.showIndicator();␍ if(gotRequiredField) reqBox_r.makeEmptyGap();␍ break;␍ case FormLayoutStyle.INDICATOR_LEFT:␍ if(labelAlign == FormLayoutStyle.TOP) reqBox_l.makeEmptyGap();␍ break;␍ case FormLayoutStyle.INDICATOR_LABEL_RIGHT:␍ break;␍ case FormLayoutStyle.INDICATOR_NONE:␍ break;␍ }␍ ␍ }
}␍}␍
+247
View File
@@ -0,0 +1,247 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.containers.formClasses {
import com.yahoo.astra.containers.formClasses.FormItemContainer;
import com.yahoo.astra.containers.formClasses.FormLayoutStyle;
import com.yahoo.astra.containers.formClasses.IForm;
import com.yahoo.astra.events.FormLayoutEvent;
import com.yahoo.astra.layout.LayoutManager;
import com.yahoo.astra.layout.events.LayoutEvent;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
/**
* <code>FormItemLabel</code> contains a label and required indicator in <code>FormItem</code> .
*
* @see com.yahoo.astra.containers.formClasses.FormItem␍ * @see com.yahoo.astra.containers.formClasses.FormItemContainer
* @author kayoh
*/
public class FormItemLabel extends FormItemContainer implements IForm {
//--------------------------------------
// Constructor
//--------------------------------------
/**
* Constructor.
*/
public function FormItemLabel() {
super();
}
//--------------------------------------
// Properties
//--------------------------------------
/**
* @private
*/
private var labelTextField : TextField = null;
/**
* @private
*/
private var lableText : String = null;
/**
* @private
*/
private var lableSprite : Sprite = null;
/**
* @private
*/
private var _actualLabelTextWidth : Number = NaN;
/**
* @private
*/
internal function get actualLabelTextWidth() : Number {
return _actualLabelTextWidth;
}
/**
* @private
*/
internal function set actualLabelTextWidth(value : Number) : void {
if(_actualLabelTextWidth == value) return;
_actualLabelTextWidth = value;
}
/**
* @private
*/
private var _preferredWidth : Number;
/**
* @private
*/
internal function get preferredLabelWidth() : Number {
return _preferredWidth;
}
/**
* @private
*/
internal function set preferredLabelWidth(value : Number) : void {
if(_preferredWidth == value) return;
_preferredWidth = value;
var tempHeight : Number = (labelTextField) ? labelTextField.height : 0;
LayoutManager.resize(subItemContainer, value, tempHeight);
if(labelAlign) this.alignLabel = labelAlign;
this.dispatchEvent(new LayoutEvent(LayoutEvent.LAYOUT_CHANGE));
}
/**
* @private
*/
private var _preferredLabelTextFormat : TextFormat;
/**
* @private
*/
internal function get preferredLabelTextFormat() : TextFormat {
return _preferredLabelTextFormat;
}
/**
* @private
*/
internal function set preferredLabelTextFormat(value : TextFormat) : void {
updateTextFields(value as TextFormat);
_preferredLabelTextFormat = value;
}
//--------------------------------------
// Internal Methods
//--------------------------------------
/**
* @private
*/
override internal function update_indicatiorLocation(value : String) : void {
cleanRequiredIndicatorBoxs();
switch(value) {
case FormLayoutStyle.INDICATOR_LEFT:
if(!lableText && labelAlign == FormLayoutStyle.TOP) {
break;
return;
}
if(required) reqBox_l.showIndicator();
reqBox_l.makeEmptyGap();
break;
case FormLayoutStyle.INDICATOR_LABEL_RIGHT:
if(!lableText && labelAlign == FormLayoutStyle.TOP) {
break;
return;
}
if(required) reqBox_r.showIndicator();
reqBox_r.makeEmptyGap();
break;
}
}
//--------------------------------------
// Private Methods
//--------------------------------------
/**
* @private
*/
override public function update(target : String, value : Object = null) : void {
switch(target) {
case FormLayoutEvent.UPDATE_LABEL_FONT_CHANGE:
if(!preferredLabelTextFormat) updateTextFields(value as TextFormat);
break;
case FormLayoutEvent.UPDATE_LABEL_WIDTH:
this.preferredLabelWidth = Number(value);
break;
case FormLayoutEvent.UPDATE_REQUIRED_ITEM:
required = Boolean(value);
break;
case FormLayoutEvent.UPDATE_INDICATOR_LOCATION:
indicatorLocation = String(value);
break;
case FormLayoutEvent.UPDATE_LABEL_ALIGN:
labelAlign = String(value);
break;
}
}
/**
* @private
*/
override internal function set labelAlign(value : String) : void {
if(this.labelAlign == value) return;
this.alignLabel = _labelAlign = value;
update_indicatiorLocation(indicatorLocation);
}
/**
* @private
*/
internal function attLabel(lableTxt : String) : void {
lableSprite = new Sprite();
if(lableTxt is String && lableTxt != "" ) {
lableText = lableTxt;
if(!labelTextField) labelTextField = FormLayoutStyle.labelTextField;
labelTextField.htmlText = lableText;
actualLabelTextWidth = labelTextField.width;
labelTextField.x = 0;
lableSprite.addChild(labelTextField);
} else {
lableText = null;
actualLabelTextWidth = 0;
}
this.dispatchEvent(new FormLayoutEvent(FormLayoutEvent.LABEL_ADDED));
this.addItem(lableSprite);
}
/**
* @private
*/
override protected function updateTextFields(textformat : TextFormat) : void {
if(!labelTextField) return;
actualLabelTextWidth = NaN;
var textFieldToChg : TextField = labelTextField;
var str : String = textFieldToChg.htmlText;
textFieldToChg.htmlText = str;
// trace("updateTextFields", textformat, str)
textFieldToChg.setTextFormat(textformat);
actualLabelTextWidth = textFieldToChg.width;
this.dispatchEvent(new FormLayoutEvent(FormLayoutEvent.LABEL_ADDED));
}
/**
* @private
*/
private function set alignLabel(value : String) : void {
if(!lableText) return;
switch(value) {
case FormLayoutStyle.TOP:
labelTextField.x = 0;
break;
case FormLayoutStyle.RIGHT:
labelTextField.x = (preferredLabelWidth) ? preferredLabelWidth - actualLabelTextWidth : 0;
break;
case FormLayoutStyle.LEFT:
labelTextField.x = 0;
break;
}
}
}
}
File diff suppressed because one or more lines are too long
+5
View File
@@ -0,0 +1,5 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.containers.formClasses {␍␍ /**␍ * Methods and properties expected to be defined by Form Classes. ␍ * ␍ * @see com.yahoo.astra.containers.formClasses.FormEventObserver␍ * ␍ * @author kayoh ␍ */␍ public interface IForm {␍␍ //--------------------------------------␍ // Methods␍ //--------------------------------------␍ /**␍ * Add formItems to subscribe <code>FormEventObserver</code>. Returns <code>IFormEventObserver</code> to force IForm instance to subscribe this observer class. ␍ * ␍ * @param formEventObserver <code>FormEventObserver</code> to register.␍ * @return IFormEventObserver Return type of <code>formEventObserver.subscribeObserver(IForm)</code>.␍ */␍ function subscribeObserver(formEventObserver : IFormEventObserver) : IFormEventObserver;␍␍ /** ␍ * Update FormLayoutEvents and properties. ␍ * ␍ * @param target String <code>FormLayoutEvent</code> type.␍ * @param value Object contains value associated <code>FormLayoutEvent</code>␍ */␍ function update(target : String, value : Object = null) : void;␍ }␍}␍
@@ -0,0 +1,5 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.containers.formClasses {␍␍ /**␍ * Methods expected to be defined by FormEventObserver. ␍ * ␍ * @author kayoh␍ */␍ public interface IFormEventObserver {␍ //--------------------------------------␍ // Methods␍ //--------------------------------------␍ /**␍ * Add formItems to be subscribed.␍ * Returns <code>IFormEventObserver</code> to force IForm instance to subscribe this observer class.␍ * ␍ * @param obserItem Iform object to be subscribe events.␍ * @return IFormEventObserver␍ * ␍ * @see com.yahoo.astra.containers.formClasses.IForm#subscribeObserver␍ */␍ function subscribeObserver(obserItem : IForm) : IFormEventObserver;␍␍ /**␍ * Remove formItems from subscription.␍ * ␍ * @param obserItem Iform instance to be unsubscribed.␍ */␍ function unsubscribeObserver(obserItem : IForm) : void;␍␍ /**␍ * Update events every formItems(<code>IForm</code>) in subscription.␍ * ␍ * @param target String <code>FormLayoutEvent</code> type and its value.␍ * @param value Object contains value associated <code>FormLayoutEvent</code>␍ * ␍ * @see com.yahoo.astra.containers.formClasses.IForm#update␍ */␍ function setUpdate(target:String, val : Object) : void;␍ }␍}␍
+178
View File
@@ -0,0 +1,178 @@
/*
Copyright (c) 2009 Yahoo! Inc. All rights reserved.
The copyrights embodied in the content of this file are licensed under the BSD (revised) open source license
*/
package com.yahoo.astra.containers.formClasses {
import com.yahoo.astra.containers.formClasses.FormLayoutStyle;
import com.yahoo.astra.events.FormLayoutEvent;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.Sprite;
import flash.text.TextField;
import flash.utils.getDefinitionByName;
/**
* Attach a required field indicator object to FormItem.
*
* @author kayoh
*/
public class RequiredIndicator extends Sprite implements IForm {
//--------------------------------------
// Constructor
//--------------------------------------
/**
* Constructor.
*/
public function RequiredIndicator() {
super();
}
//--------------------------------------
// Properties
//--------------------------------------
/**
* Required field mark(red asterisk). the default is indicatorSkin movieclip in Form.
* @private
*/
private var checkBox : DisplayObjectContainer = null;
/**
* Place holder to make even gap.
* @private
*/
private var emptyBox : Sprite = null;
/**
* @private
*/
private var _requiredIndicator : DisplayObject = null;
/**
* Return requiredIndicator DisplayObject being used in <code>Form</code> or <code>FormItem</code>.
* @param value DisplayObject to be used as requiredIndicator.
*/
public function get requiredIndicator() : DisplayObject {
return _requiredIndicator;
}
/**
* @private
* @see com.yahoo.astra.fl.containers.formClasses.FormLayoutStyle#DEFAULT_INDICATORFIELD_WIDTH
*/
private var boxWidth : Number = FormLayoutStyle.INDICATORFIELD_WIDTH;
/**
* @private
* @see com.yahoo.astra.fl.containers.formClasses.FormLayoutStyle#DEFAULT_INDICATORFIELD_HEIGHT
*/
private var boxHeight : Number = FormLayoutStyle.INDICATORFIELD_HEIGHT;
/**
* @private
*/
private var formEventObserver : IFormEventObserver = null;
//--------------------------------------
// internal Methods
//--------------------------------------
/**
* @private
*/
private function upateEmptyBoxWidthHeight(w : Number, h : Number) : void {
boxWidth = w;
boxHeight = h;
if(emptyBox) {
emptyBox.width = w;
emptyBox.height = h;
}
}
/**
* @private
*/
internal function cleanBox() : void {
_requiredIndicator = null;
while(this.numChildren) this.removeChildAt(0);
}
/**
* @private
*/
internal function makeEmptyGap() : void {
if(this.getChildByName("emptyBox")) {
this.removeChild(this.getChildByName("emptyBox"));
}
var sp : Sprite = new Sprite();
sp.graphics.beginFill(0xff00ff, 0);
sp.graphics.drawRect(0, 0, boxWidth, boxHeight);
sp.graphics.endFill();
emptyBox = Sprite(this.addChild(sp));
emptyBox.name = "emptyBox";
}
/**
* @private
*
* Show the required indicator(asterisk mark or custom movieclip).
*/
internal function showIndicator() : void {
try {
/*
* When FormItem is nested in Form, attaches one from Form.
*/
var ClassReference : Class = getDefinitionByName(FormLayoutStyle.defaultStyles["indicatorSkin"]) as Class;
checkBox = new ClassReference();
}
catch(e : ReferenceError) {
if(FormLayoutStyle.defaultStyles["indicatorSkin"] is DisplayObjectContainer) {
/*
* When "indicatorSkin" was defined by set setIndicatorSkin in FormItem.
*/
checkBox = FormLayoutStyle.defaultStyles["indicatorSkin"];
} else {
checkBox = new Sprite();
var astTxtField : TextField = FormLayoutStyle.asteriskTextField;
astTxtField.y = -astTxtField.height / 2;
astTxtField.x = -astTxtField.width / 2;
checkBox.addChild(astTxtField);
}
}
if(FormLayoutStyle.INDICATORFIELD_WIDTH < checkBox.width || FormLayoutStyle.INDICATORFIELD_HEIGHT < checkBox.height) {
boxWidth = FormLayoutStyle.INDICATORFIELD_WIDTH = checkBox.width;
boxHeight = FormLayoutStyle.INDICATORFIELD_HEIGHT = checkBox.height;
if(formEventObserver) formEventObserver.setUpdate(FormLayoutEvent.INDICATOR_SIZE_CHAGE, [boxWidth, boxHeight]);
}
checkBox.x = boxWidth / 2;
checkBox.y = boxHeight / 2;
makeEmptyGap();
_requiredIndicator = this.addChild(checkBox);
}
//--------------------------------------
// Public Methods
//--------------------------------------
/**
* @private
*/
public function update(target : String, value : Object = null) : void {
switch(target) {
case FormLayoutEvent.INDICATOR_SIZE_CHAGE:
upateEmptyBoxWidthHeight(value[0], value[1]);
break;
}
}
/**
* @private
*/
public function subscribeObserver(formEventObserver : IFormEventObserver) : IFormEventObserver {
this.formEventObserver = formEventObserver;
return formEventObserver.subscribeObserver(this);
}
}
}