first commit
This commit is contained in:
Executable
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
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.fl.utils {␍ import fl.controls.ColorPicker;␍ import fl.controls.ComboBox;␍ import fl.controls.LabelButton;␍ import fl.controls.List;␍ import fl.controls.NumericStepper;␍ import fl.controls.RadioButtonGroup;␍ import fl.controls.TextArea;␍ import fl.controls.TextInput;␍ import fl.controls.TileList;␍ import fl.core.UIComponent;
|
||||
import com.yahoo.astra.fl.utils.FlValueParser;␍ import com.yahoo.astra.utils.IValueParser;␍ import com.yahoo.astra.utils.ValueParser;
|
||||
import flash.text.TextField;
|
||||
/**␍ * Helper class providing easy data collection from <code>UIcomponents</code>.␍ * If the <code>source</code> is <code>UIcomponent</code> or <code>TextField</code>, <code>property</code> is optional.␍ * (e.g. If you want to collect data from <code>TextField</code>, you don't have to specify <code>property</code> as "text".)␍ *␍ * <p><strong>UIcomponent type(<code>source</code>) and default <code>property</code>:</strong></p>␍ * <dl>␍ * <dt><strong><code>TextInput</code></strong> : text</dt>␍ * <dt><strong><code>ComboBox</code></strong> : selectedItem["data"]</dt>␍ * <dt><strong><code>NumericStepper</code></strong> : value</dt>␍ * <dt><strong><code>LabelButton(Button,CheckBox, RadioButton)</code></strong> : selected</dt>␍ * <dt><strong><code>List, TileList</code></strong> : selectedItem[labelField]</dt>␍ * <dt><strong><code>ColorPicker</code></strong> : hexValue</dt>␍ * </dl>␍ * ␍ * @see com.yahoo.astra.utils.ValueParser␍ * @see com.yahoo.astra.managers.FormDataManager␍ */␍ public class FlValueParser extends ValueParser implements IValueParser {␍ /**␍ * Constructor␍ */␍ public function FlValueParser() {␍ super();␍ }
|
||||
/**␍ * Return actual value set from <code>setValue</code>. ␍ * @return Object Data collected out of <code>source</code>␍ */␍ override public function getValue() : Object {␍ if(!this.source) return null;␍ if(this.source is Array) {␍ var curReturnedStr : Object = "";␍ var sourceLength : int = source.length;␍ for (var i : int = 0;i < sourceLength; i++) {␍ var curSource : Object = this.source[i];␍ if(curSource is String) {␍ curReturnedStr += curSource;␍ continue;
|
||||
}␍ var curProperty : Object = (this.property) ? ((this.property is Array) ? this.property[i] : this.property ) : null;␍ var result : Object = returnBySourceType(curSource, curProperty);␍ curReturnedStr += (result) ? result.toString() : "";␍ }␍ return curReturnedStr;␍ }␍ ␍ return returnBySourceType(this.source, this.property);␍ }
|
||||
/**␍ * @private␍ */␍ private function returnBySourceType(source : Object, property : Object = null) : Object {␍ if(source is UIComponent) {␍ return UIcomponentsValue(source as UIComponent, property);␍ } else {␍ return objectValue(source, property);␍ }␍ return this.source;␍ }
|
||||
/**␍ * @private␍ */␍ private function objectValue(source : Object = null, property : Object = null) : Object {␍ ␍ var returnedvalue : Object = source;␍ switch(source) {␍ case source as TextField:␍ var textInput : TextField = source as TextField;␍ if(!property) property = "text";␍ returnedvalue = textInput[property].toString();␍ break;␍ ␍ case source as RadioButtonGroup:␍ var rBtnBrp : RadioButtonGroup = source as RadioButtonGroup;␍ if(!property) property = "selectedData";␍ if(rBtnBrp[property]) returnedvalue = rBtnBrp[property];␍ break; ␍ ␍ default :␍ if(source && property) returnedvalue = source[property];␍ break;␍ }␍ return returnedvalue;␍ }
|
||||
/**␍ * @private␍ */␍ private function UIcomponentsValue(UiComponent : UIComponent = null, property : Object = null) : Object {␍ var returnedvalue : Object = UiComponent;␍ switch(UiComponent) {␍ ␍ /*␍ * LabelButton includes Button,CheckBox, RadioButton␍ */ ␍ case UiComponent as LabelButton:␍ var checkBox : LabelButton = UiComponent as LabelButton;␍ if(!property || property == "selected") { ␍ returnedvalue = checkBox["selected"];␍ } else {␍ if(Boolean(checkBox["selected"])) {␍ returnedvalue = property;␍ } else {␍ returnedvalue = checkBox["selected"];␍ }␍ }␍ break;␍ ␍ case UiComponent as TextInput:␍ var textInput : TextInput = UiComponent as TextInput;␍ if(!property) property = "text";␍ returnedvalue = textInput[property].toString();␍ break;␍ ␍ case UiComponent as ComboBox:␍ var comboBox : ComboBox = UiComponent as ComboBox;␍ if(!property) property = "data";␍ returnedvalue = comboBox.selectedItem[property];␍ break;␍ ␍ case UiComponent as TextArea:␍ var textArea : TextArea = UiComponent as TextArea;␍ if(!property) property = "text";␍ returnedvalue = textArea[property].toString();␍ break;␍ ␍ case UiComponent as NumericStepper:␍ var numericStepper : NumericStepper = UiComponent as NumericStepper;␍ if(!property) property = "value";␍ returnedvalue = numericStepper[property];␍ break;␍ ␍ case UiComponent as List:␍ var list : List = UiComponent as List;␍ if(!property) property = list.labelField;␍ returnedvalue = list.selectedItem[property];␍ break; ␍ ␍ case UiComponent as TileList:␍ var tilelist : TileList = UiComponent as TileList;␍ if(!property) property = tilelist.labelField;␍ returnedvalue = tilelist.selectedItem[property];␍ break; ␍ ␍ case UiComponent as ColorPicker:␍ var colorPicker : ColorPicker = UiComponent as ColorPicker;␍ if(!property) property = "hexValue";␍ returnedvalue = colorPicker[property];␍ break;␍ }␍ return returnedvalue;␍ }␍ }␍}␍
|
||||
Executable
+166
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
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.fl.utils
|
||||
{
|
||||
import com.yahoo.astra.utils.InstanceFactory;
|
||||
|
||||
import fl.core.UIComponent;
|
||||
import fl.managers.StyleManager;
|
||||
|
||||
import flash.display.DisplayObject;
|
||||
import flash.utils.getDefinitionByName;
|
||||
import flash.utils.getQualifiedClassName;
|
||||
import flash.utils.getQualifiedSuperclassName;
|
||||
|
||||
/**
|
||||
* Utility functions for use with UIComponents.
|
||||
*
|
||||
* @author Josh Tynjala
|
||||
*/
|
||||
public class UIComponentUtil
|
||||
{
|
||||
/**
|
||||
* Using an input, such as a component style, tries to convert the input
|
||||
* to a DisplayObject.
|
||||
*
|
||||
* <p>Possible inputs include Class, a String representatation of a
|
||||
* fully-qualified class name, Function, any existing instance of
|
||||
* a DisplayObject, or InstanceFactory.</p>
|
||||
*
|
||||
* @see com.yahoo.astra.utils.InstanceFactory
|
||||
*
|
||||
* @param target the parent of the new instance
|
||||
* @param input the object to convert to a DisplayObject instance
|
||||
*/
|
||||
public static function getDisplayObjectInstance(target:DisplayObject, input:Object):DisplayObject
|
||||
{
|
||||
if(input is InstanceFactory)
|
||||
{
|
||||
return InstanceFactory(input).createInstance() as DisplayObject;
|
||||
}
|
||||
//added Function as a special case because functions can be used with the new keyword
|
||||
else if(input is Class || input is Function)
|
||||
{
|
||||
return (new input()) as DisplayObject;
|
||||
}
|
||||
else if(input is DisplayObject)
|
||||
{
|
||||
(input as DisplayObject).x = 0;
|
||||
(input as DisplayObject).y = 0;
|
||||
return input as DisplayObject;
|
||||
}
|
||||
|
||||
var classDef:Object = null;
|
||||
try
|
||||
{
|
||||
classDef = getDefinitionByName(input.toString());
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
try
|
||||
{
|
||||
classDef = target.loaderInfo.applicationDomain.getDefinition(input.toString()) as Object;
|
||||
}
|
||||
catch (e:Error)
|
||||
{
|
||||
// Nothing
|
||||
}
|
||||
}
|
||||
if(classDef == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (new classDef()) as DisplayObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class of an object. If the object is a DisplayObject,
|
||||
* may retrieve the class from the containing app domain.
|
||||
*
|
||||
* @param target A Class or a fully qualified class name (String).
|
||||
*/
|
||||
public static function getClassDefinition(target:Object):Class
|
||||
{
|
||||
if(target is Class)
|
||||
{
|
||||
return target as Class;
|
||||
}
|
||||
try
|
||||
{
|
||||
return getDefinitionByName(getQualifiedClassName(target)) as Class;
|
||||
}
|
||||
catch (e:Error)
|
||||
{
|
||||
if(target is DisplayObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
return target.loaderInfo.applicationDomain.getDefinition(getQualifiedClassName(target)) as Class;
|
||||
}
|
||||
catch(e:Error)
|
||||
{
|
||||
//nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Works like getStyleValue() on UIComponent, except it makes component
|
||||
* and shared styles available globally rather than just in the component's
|
||||
* class.
|
||||
*
|
||||
* @param target the component for which to retrieve the style value
|
||||
* @param styleName the name of the style to retrieve
|
||||
*/
|
||||
public static function getStyleValue(target:UIComponent, styleName:String):Object
|
||||
{
|
||||
var value:Object = target.getStyle(styleName);
|
||||
value = value ? value : StyleManager.getComponentStyle(target, styleName);
|
||||
if(value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
var classDef:Class = UIComponentUtil.getClassDefinition(target);
|
||||
var defaultStyles:Object;
|
||||
|
||||
//borrowed from fl.managers.StyleManager
|
||||
// Walk the inheritance chain looking for a default styles object.
|
||||
while(defaultStyles == null)
|
||||
{
|
||||
// Trick the strict compiler.
|
||||
if(classDef["getStyleDefinition"] != null)
|
||||
{
|
||||
defaultStyles = classDef["getStyleDefinition"]();
|
||||
break;
|
||||
}
|
||||
try
|
||||
{
|
||||
classDef = target.loaderInfo.applicationDomain.getDefinition(getQualifiedSuperclassName(classDef)) as Class;
|
||||
}
|
||||
catch(err:Error)
|
||||
{
|
||||
try
|
||||
{
|
||||
classDef = getDefinitionByName(getQualifiedSuperclassName(classDef)) as Class;
|
||||
}
|
||||
catch (e:Error)
|
||||
{
|
||||
defaultStyles = UIComponent.getStyleDefinition();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(defaultStyles.hasOwnProperty(styleName))
|
||||
{
|
||||
return defaultStyles[styleName];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.fl.utils{
|
||||
/**
|
||||
* The XMLUtil class is an all-static class
|
||||
* with methods for working with XML within Flash.
|
||||
* Not to be confused with fl.utils.XMLUtil.
|
||||
* You do not create instances of XMLUtil;
|
||||
* instead you simply call static methods such as
|
||||
* the <code>XMLUtil.createArrayFromXML()</code> method.
|
||||
*
|
||||
* @author Alaric Cole
|
||||
* @see com.yahoo.astra.fl.data.XMLDataProvider
|
||||
*/
|
||||
public class XMLUtil
|
||||
{
|
||||
/**
|
||||
* Creates an object with properties extracted from XML attributes
|
||||
* @param node
|
||||
*/
|
||||
public static function createObjectFromXMLAttributes(node:XML):Object
|
||||
{
|
||||
//create an object and give it props from this nodes attributes
|
||||
var obj:Object = {};
|
||||
var attrs:XMLList = node.attributes();
|
||||
for each (var attr:XML in attrs)
|
||||
{
|
||||
obj[attr.localName()] = attr.toString();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
/**
|
||||
* Creates a hierarchical array from XML or an XMLList
|
||||
* @param xml An XML or XMLList object
|
||||
*/
|
||||
public static function createArrayFromXML(xml:Object):Array
|
||||
{
|
||||
var nodes:XMLList;
|
||||
var ar:Array = [];
|
||||
if (xml is XML)
|
||||
{
|
||||
nodes = XML(xml).children();
|
||||
} else if (xml is XMLList)
|
||||
{
|
||||
nodes = xml as XMLList;
|
||||
} else
|
||||
{
|
||||
throw new TypeError("Error: Type Coercion failed: cannot convert " + xml + " to XML or XMLList.");
|
||||
return null;
|
||||
}
|
||||
//loop through top level nodes
|
||||
for each (var node:XML in nodes)
|
||||
{
|
||||
var obj:Object = createObjectFromXMLAttributes(node);
|
||||
//loop through any nodes in this node
|
||||
var propNodes:XMLList = node.*;
|
||||
var data:Array = createArrayFromXML(propNodes);
|
||||
if (data.length)
|
||||
{
|
||||
obj.data = data;
|
||||
}
|
||||
ar.push(obj);
|
||||
}
|
||||
return ar;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user