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

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 {

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;
/**

View File

@ -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;

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

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 {

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 {

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);
}
}
}