first commit
This commit is contained in:
5
com/yahoo/astra/fl/controls/treeClasses/BranchNode.as
Executable file
5
com/yahoo/astra/fl/controls/treeClasses/BranchNode.as
Executable file
File diff suppressed because one or more lines are too long
123
com/yahoo/astra/fl/controls/treeClasses/LeafNode.as
Executable file
123
com/yahoo/astra/fl/controls/treeClasses/LeafNode.as
Executable file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
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.controls.treeClasses {
|
||||
//--------------------------------------
|
||||
// Class description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* The LeafNode class is the base class for leaf nodes in the Tree.
|
||||
* Leaf nodes are nodes that do not have any children.
|
||||
* The class inherits from the base TNode class and provides logic
|
||||
* for linking nodes hierarchically and retrieving relevant information
|
||||
* about them.
|
||||
*
|
||||
* @author Allen Rabinovich
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.TreeDataProvider
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.TNode
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.LeafNode
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.RootNode
|
||||
*/
|
||||
public dynamic class LeafNode extends TNode {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* The type of the node
|
||||
*/
|
||||
protected var _nodeType:String;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pDP The data provider that will contain this node.
|
||||
*/
|
||||
public function LeafNode (pDP:TreeDataProvider) {
|
||||
super(pDP);
|
||||
_nodeType = TreeDataProvider.LEAF_NODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* The node type marker. For the LeafNode,
|
||||
* the value is constant and set to <code>TreeDataProvider.LEAF_NODE</code>
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.TreeDataProvider
|
||||
*/
|
||||
public function get nodeType () : String {
|
||||
return _nodeType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Checks whether a particular field <code>fieldName</code> in the node
|
||||
* object holds a particular <code>value</code>
|
||||
*
|
||||
* @return true if the field contains the specified value; false if not.
|
||||
*/
|
||||
public function checkForValue (fieldName:String, value:String) : TNode {
|
||||
if (this[fieldName] == value) {
|
||||
return (this as TNode);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Gets the number of visible nodes for this node.
|
||||
* For LeafNode, the value is always 1.
|
||||
*
|
||||
* @return 1
|
||||
*/
|
||||
public function getVisibleSize () : int {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the node by adding it to the Tree's dataProvider.
|
||||
* Will only draw the node if all of its parents are open
|
||||
* and if the node hasn't already been drawn.
|
||||
*
|
||||
*/
|
||||
override public function drawNode () : void {
|
||||
// Only draw the node if it's not already drawn and if it's open
|
||||
if (_parentDataProvider.getItemIndex(this) == -1 && isVisible()) {
|
||||
var myIndex:int = _parentNode.children.indexOf(this);
|
||||
var actualIndex:int = 0;
|
||||
for (var i:int = 0; i < myIndex; i++) {
|
||||
actualIndex += _parentNode.children[i].getVisibleSize();
|
||||
}
|
||||
// If the node is at the top level, add it directly to the DataProvider at the right location
|
||||
if (_parentNode is RootNode) {
|
||||
if (_parentDataProvider.length > 0) {
|
||||
_parentDataProvider.addItemAt(this, actualIndex);
|
||||
}
|
||||
else {
|
||||
_parentDataProvider.addItem(this);
|
||||
}
|
||||
}
|
||||
// If the node is nested, add it below the parent node with the correct offset
|
||||
else {
|
||||
var parentIndex:int = _parentDataProvider.getItemIndex(_parentNode);
|
||||
_parentDataProvider.addItemAt(this, parentIndex + actualIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides the node by removing it from the dataProvider.
|
||||
* Only hides the node if one of its parents is closed.
|
||||
*
|
||||
*/
|
||||
override public function hideNode () : void {
|
||||
// Only hide the node if it's not already hidden and is closed
|
||||
if (_parentDataProvider.getItemIndex(this) != -1 && !isVisible()) {
|
||||
_parentDataProvider.removeItem(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
77
com/yahoo/astra/fl/controls/treeClasses/RootNode.as
Executable file
77
com/yahoo/astra/fl/controls/treeClasses/RootNode.as
Executable file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
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.controls.treeClasses {
|
||||
//--------------------------------------
|
||||
// Class description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* The RootNode is a special case of a BranchNode that's used
|
||||
* to contain the top-level nodes. The RootNode itself is never drawn.
|
||||
*
|
||||
* @author Allen Rabinovich
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.TreeDataProvider
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.TNode
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.LeafNode
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.BranchNode
|
||||
*/
|
||||
public dynamic class RootNode extends BranchNode {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pDP The data provider that will contain this node.
|
||||
*/
|
||||
public function RootNode (pDP:TreeDataProvider) {
|
||||
_nodeLevel = -1;
|
||||
_nodeType = TreeDataProvider.ROOT_NODE;
|
||||
_nodeState = TreeDataProvider.OPEN_NODE;
|
||||
super(pDP);
|
||||
|
||||
}
|
||||
/**
|
||||
* @private (setter);
|
||||
*/
|
||||
override public function set nodeLevel (value:int) : void {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Since the root node itself is not visible, this function
|
||||
* draws all of the top-level nodes.
|
||||
*
|
||||
*/
|
||||
override public function drawNode () : void {
|
||||
for each (var child:TNode in _children) {
|
||||
child.drawNode();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
*/
|
||||
override public function hideNode () : void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a child node at a particular index in the array
|
||||
* of children of the current node. If the current node is
|
||||
* open, the new child node is also made visible.
|
||||
*
|
||||
* @param childNode The node to be added as a child
|
||||
* @param index The position in the <code>children</code> array where
|
||||
* the child node is inserted.
|
||||
*
|
||||
*/
|
||||
override public function addChildNodeAt (childNode:TNode, index:int) : void {
|
||||
_children.splice(index, 0, childNode);
|
||||
childNode.parentNode = this as BranchNode;
|
||||
childNode.nodeLevel = this.nodeLevel + 1;
|
||||
childNode.drawNode();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
143
com/yahoo/astra/fl/controls/treeClasses/TNode.as
Executable file
143
com/yahoo/astra/fl/controls/treeClasses/TNode.as
Executable file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
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.controls.treeClasses {
|
||||
|
||||
//--------------------------------------
|
||||
// Class description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* The TNode class is the base class for three different types of node objects
|
||||
* that may appear in a Tree component data provider. The TNode class provides
|
||||
* the necessary logic for linking the nodes hierarchically, recording the information
|
||||
* about the nesting level of a node, and checking whether a node is currently
|
||||
* visible.
|
||||
*
|
||||
* @author Allen Rabinovich
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.TreeDataProvider
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.BranchNode
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.LeafNode
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.RootNode
|
||||
*/
|
||||
public dynamic class TNode extends Object {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* The parent node of this node.
|
||||
*/
|
||||
protected var _parentNode:BranchNode;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* The nesting level of this node.
|
||||
*/
|
||||
protected var _nodeLevel:int;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* The data provider that contains this node.
|
||||
*/
|
||||
protected var _parentDataProvider:TreeDataProvider;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pDP The data provider that will contain this node.
|
||||
*/
|
||||
public function TNode (pDP:TreeDataProvider) {
|
||||
_parentDataProvider = pDP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether all of the nodes parents are currently open in the Tree
|
||||
* (thus making the node visible).
|
||||
*
|
||||
* @return <code>true</code> if all of the nodes parents are open; <code>false</code> otherwise.
|
||||
*/
|
||||
|
||||
public function isVisible () : Boolean {
|
||||
var nodePointer:BranchNode = _parentNode as BranchNode;
|
||||
|
||||
while (!(nodePointer is RootNode)) {
|
||||
if (!(nodePointer.isOpen())) {
|
||||
return false;
|
||||
}
|
||||
nodePointer = nodePointer.parentNode;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* Placeholder for a function that draws the node by placing it into the dataProvider;
|
||||
* overridden in BranchNode and LeafNode.
|
||||
*/
|
||||
public function drawNode () : void {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* Placeholder for a function that hides the node by removing it from the dataProvider;
|
||||
* overridden in BranchNode and LeafNode.
|
||||
*/
|
||||
public function hideNode () : void {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Completely removes the node from the tree.
|
||||
*
|
||||
* @return The node that has been removed.
|
||||
*
|
||||
*/
|
||||
public function removeNode () : TNode {
|
||||
this.parentNode.removeChild(this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set nodeLevel (value:int) : void {
|
||||
if (value == _parentNode.nodeLevel + 1) {
|
||||
_nodeLevel = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or sets the node level for this node.
|
||||
* The level will only set if it's one greater
|
||||
* that the nodeLevel of the parent node.
|
||||
*/
|
||||
public function get nodeLevel () : int {
|
||||
return _nodeLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*/
|
||||
public function set parentNode (value:BranchNode) : void {
|
||||
if (value.children.indexOf(this) >= 0) {
|
||||
_parentNode = value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets or sets the parent node for this node.
|
||||
* The parent node will only be set if this node
|
||||
* is in the <code>children</code> array of the parent node.
|
||||
*/
|
||||
public function get parentNode () : BranchNode {
|
||||
return _parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
455
com/yahoo/astra/fl/controls/treeClasses/TreeCellRenderer.as
Executable file
455
com/yahoo/astra/fl/controls/treeClasses/TreeCellRenderer.as
Executable file
@ -0,0 +1,455 @@
|
||||
/*
|
||||
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.controls.treeClasses {
|
||||
|
||||
import com.yahoo.astra.fl.controls.Tree;
|
||||
import fl.controls.ButtonLabelPlacement;
|
||||
import fl.controls.listClasses.ListData;
|
||||
import fl.controls.listClasses.ICellRenderer;
|
||||
import fl.controls.LabelButton;
|
||||
import fl.core.UIComponent;
|
||||
import flash.events.Event;
|
||||
import flash.events.MouseEvent;
|
||||
import flash.text.TextFormat;
|
||||
import fl.core.InvalidationType;
|
||||
import flash.display.Sprite;
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// Styles
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* Name of the class to use as the skin for the icon associated
|
||||
* with a closed branch of the tree.
|
||||
*
|
||||
* @default TreeCellRenderer_closedBranchIcon
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="closedBranchIcon", type="Class")]
|
||||
|
||||
/**
|
||||
* Name of the class to use as the skin for the icon associated
|
||||
* with an open branch of the tree.
|
||||
*
|
||||
* @default TreeCellRenderer_openBranchIcon
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="openBranchIcon", type="Class")]
|
||||
|
||||
/**
|
||||
* Name of the class to use as the skin for the icon associated
|
||||
* with a leaf node of the tree.
|
||||
*
|
||||
* @default TreeCellRenderer_leafIcon
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="leafIcon", type="Class")]
|
||||
|
||||
/**
|
||||
* @copy fl.controls.LabelButton#style:upSkin
|
||||
*
|
||||
* @default CellRenderer_upSkin
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="upSkin", type="Class")]
|
||||
|
||||
/**
|
||||
* @copy fl.controls.LabelButton#style:downSkin
|
||||
*
|
||||
* @default CellRenderer_downSkin
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="downSkin", type="Class")]
|
||||
|
||||
/**
|
||||
* @copy fl.controls.LabelButton#style:overSkin
|
||||
*
|
||||
* @default CellRenderer_overSkin
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="overSkin", type="Class")]
|
||||
|
||||
/**
|
||||
* @copy fl.controls.LabelButton#style:disabledSkin
|
||||
*
|
||||
* @default CellRenderer_disabledSkin
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="disabledSkin", type="Class")]
|
||||
|
||||
/**
|
||||
* @copy fl.controls.LabelButton#style:selectedDisabledSkin
|
||||
*
|
||||
* @default CellRenderer_selectedDisabledSkin
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="selectedDisabledSkin", type="Class")]
|
||||
|
||||
/**
|
||||
* @copy fl.controls.LabelButton#style:selectedUpSkin
|
||||
*
|
||||
* @default CellRenderer_selectedUpSkin
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="selectedUpSkin", type="Class")]
|
||||
|
||||
/**
|
||||
* @copy fl.controls.LabelButton#style:selectedDownSkin
|
||||
*
|
||||
* @default CellRenderer_selectedDownSkin
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="selectedDownSkin", type="Class")]
|
||||
|
||||
/**
|
||||
* @copy fl.controls.LabelButton#style:selectedOverSkin
|
||||
*
|
||||
* @default CellRenderer_selectedOverSkin
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="selectedOverSkin", type="Class")]
|
||||
|
||||
|
||||
/**
|
||||
* @copy fl.core.UIComponent#style:textFormat
|
||||
*
|
||||
* @default null
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="textFormat", type="flash.text.TextFormat")]
|
||||
|
||||
|
||||
/**
|
||||
* @copy fl.core.UIComponent#style:disabledTextFormat
|
||||
*
|
||||
* @default null
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="disabledTextFormat", type="flash.text.TextFormat")]
|
||||
|
||||
|
||||
/**
|
||||
* @copy fl.controls.LabelButton#style:textPadding
|
||||
*
|
||||
* @default 5
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="textPadding", type="Number", format="Length")]
|
||||
|
||||
|
||||
/**
|
||||
* Number of pixels to use as offset when rendering nested tree nodes.
|
||||
*
|
||||
* @default 5
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="nodeIndent", type="Number", format="Length")]
|
||||
|
||||
/**
|
||||
* Left margin width in pixels
|
||||
*
|
||||
* @default 5
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
[Style(name="leftMargin", type="Number", format="Length")]
|
||||
|
||||
//--------------------------------------
|
||||
// Class description
|
||||
//--------------------------------------
|
||||
/**
|
||||
* The TreeCellRenderer class defines methods and properties for
|
||||
* Tree component to manipulate and display custom
|
||||
* cell content in each of its rows. TreeCellRenderer relies on
|
||||
* properties contained in the TreeDataProvider objects to set
|
||||
* appropriate icons and offsets for individual cells.
|
||||
* The TreeCellRenderer implements ICellRenderer and extends
|
||||
* the LabelButton.
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.TreeDataProvider
|
||||
* @see ICellRenderer
|
||||
* @see fl.controls.LabelButton
|
||||
*
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public class TreeCellRenderer extends LabelButton implements ICellRenderer {
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected var _listData:ListData;
|
||||
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
protected var _data:Object;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new TreeCellRenderer instance.
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function TreeCellRenderer():void {
|
||||
super();
|
||||
toggle = true;
|
||||
focusEnabled = false;
|
||||
|
||||
this.addEventListener(MouseEvent.CLICK, handleClickEvent, false, 0, true);
|
||||
}
|
||||
|
||||
|
||||
private function handleClickEvent(evt:MouseEvent) : void {
|
||||
var currentNode:TNode = data as TNode;
|
||||
if (this.icon != null && currentNode is BranchNode &&
|
||||
this.icon.x <= this.mouseX &&
|
||||
this.mouseX <= (this.icon.x + this.icon.width) &&
|
||||
this.icon.y <= this.mouseY &&
|
||||
this.mouseY <= (this.icon.y + this.icon.height)) {
|
||||
evt.stopImmediatePropagation();
|
||||
if (currentNode.isOpen()) {
|
||||
currentNode.closeNode();
|
||||
}
|
||||
else {
|
||||
currentNode.openNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
private static var defaultStyles:Object = {upSkin:"TreeCellRenderer_upSkin",downSkin:"TreeCellRenderer_downSkin",overSkin:"TreeCellRenderer_overSkin",
|
||||
disabledSkin:"TreeCellRenderer_disabledSkin",
|
||||
selectedDisabledSkin:"TreeCellRenderer_selectedDisabledSkin",
|
||||
selectedUpSkin:"TreeCellRenderer_selectedUpSkin",selectedDownSkin:"TreeCellRenderer_selectedDownSkin",selectedOverSkin:"TreeCellRenderer_selectedOverSkin",
|
||||
closedBranchIcon:"TreeCellRenderer_closedBranchIcon",
|
||||
openBranchIcon:"TreeCellRenderer_openBranchIcon",
|
||||
leafIcon:"TreeCellRenderer_leafIcon",
|
||||
textFormat:null,
|
||||
disabledTextFormat:null,
|
||||
embedFonts:null,
|
||||
textPadding:5,
|
||||
nodeIndent:5,
|
||||
leftMargin:5};
|
||||
/**
|
||||
* @copy fl.core.UIComponent#getStyleDefinition()
|
||||
*
|
||||
* @includeExample ../../core/examples/UIComponent.getStyleDefinition.1.as -noswf
|
||||
*
|
||||
* @see fl.core.UIComponent#getStyle()
|
||||
* @see fl.core.UIComponent#setStyle()
|
||||
* @see fl.managers.StyleManager
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public static function getStyleDefinition():Object {
|
||||
return mergeStyles(defaultStyles, LabelButton.getStyleDefinition());
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the dimensions at which the data should be rendered.
|
||||
* These dimensions affect both the data and the cell that contains it;
|
||||
* the cell renderer uses them to ensure that the data fits the cell and
|
||||
* does not bleed into adjacent cells.
|
||||
*
|
||||
* @param width The width of the object, in pixels.
|
||||
*
|
||||
* @param height The height of the object, in pixels.
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override public function setSize(width:Number,height:Number):void {
|
||||
super.setSize(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* @copy fl.controls.listClasses.ICellRenderer#listData
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function get listData():ListData {
|
||||
return _listData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
* When listData is set, we determine the appropriate icon to use
|
||||
* with the particular type of Tree node (open branch, closed branch,
|
||||
* or leaf).
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function set listData(value:ListData):void {
|
||||
_listData = value;
|
||||
label = _listData.label;
|
||||
var parentTree:Tree = _listData.owner as Tree;
|
||||
if (data.nodeType == TreeDataProvider.BRANCH_NODE) {
|
||||
if (data.nodeState == TreeDataProvider.OPEN_NODE) {
|
||||
if (parentTree.iconFunction != null) {
|
||||
setStyle("icon", parentTree.iconFunction(data));
|
||||
} else if (parentTree.openBranchIconField != null && data[parentTree.openBranchIconField] != null) {
|
||||
setStyle("icon", data[parentTree.openBranchIconField]);
|
||||
} else {
|
||||
setStyle("icon", getStyleValue("openBranchIcon"));
|
||||
}
|
||||
} else {
|
||||
if (parentTree.iconFunction != null) {
|
||||
setStyle("icon", parentTree.iconFunction(data));
|
||||
} else if (parentTree.closedBranchIconField != null && data[parentTree.closedBranchIconField] != null) {
|
||||
setStyle("icon", data[parentTree.closedBranchIconField]);
|
||||
} else {
|
||||
setStyle("icon", getStyleValue("closedBranchIcon"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (parentTree.iconFunction != null) {
|
||||
setStyle("icon", parentTree.iconFunction(data));
|
||||
} else if (parentTree.openBranchIconField != null && data[parentTree.leafIconField] != null) {
|
||||
setStyle("icon", data[parentTree.leafIconField]);
|
||||
} else {
|
||||
setStyle("icon", getStyleValue("leafIcon"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @copy fl.controls.listClasses.ICellRenderer#data
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function get data():Object {
|
||||
return _data;
|
||||
}
|
||||
/**
|
||||
* @private (setter)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
public function set data(value:Object):void {
|
||||
_data = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @copy fl.controls.listClasses.ICellRenderer#selected
|
||||
*
|
||||
* @default false
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override public function get selected():Boolean {
|
||||
return super.selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (setter)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override public function set selected(value:Boolean):void {
|
||||
super.selected = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override protected function toggleSelected(event:MouseEvent):void {
|
||||
// don't set selected or dispatch change event.
|
||||
}
|
||||
/**
|
||||
* @private (protected)
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
override protected function drawLayout():void {
|
||||
var textPadding:Number = Number(getStyleValue("textPadding"));
|
||||
var nodeIndent:Number = Number(getStyleValue("nodeIndent"));
|
||||
var leftMargin:Number = Number(getStyleValue("leftMargin"));
|
||||
var textFieldX:Number = 0;
|
||||
|
||||
// Align icon and add the indent derived from node's level
|
||||
if (icon != null) {
|
||||
icon.x = leftMargin + data.nodeLevel * nodeIndent;
|
||||
icon.y = Math.round((height-icon.height)>>1);
|
||||
textFieldX = icon.x + icon.width + textPadding;
|
||||
}
|
||||
|
||||
|
||||
// Align text and add the indent derived from node's level
|
||||
if (label.length > 0) {
|
||||
textField.visible = true;
|
||||
var textWidth:Number = Math.max(0, width - textFieldX - textPadding*2);
|
||||
textField.width = textWidth;
|
||||
textField.height = textField.textHeight + 4;
|
||||
textField.x = textFieldX;
|
||||
textField.y = Math.round((height-textField.height)>>1);
|
||||
} else {
|
||||
textField.visible = false;
|
||||
}
|
||||
|
||||
// Size background
|
||||
background.width = width;
|
||||
background.height = height;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
225
com/yahoo/astra/fl/controls/treeClasses/TreeDataProvider.as
Executable file
225
com/yahoo/astra/fl/controls/treeClasses/TreeDataProvider.as
Executable file
@ -0,0 +1,225 @@
|
||||
/*
|
||||
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.controls.treeClasses {
|
||||
|
||||
import flash.events.EventDispatcher;
|
||||
import fl.events.DataChangeEvent;
|
||||
import fl.events.DataChangeType;
|
||||
import RangeError;
|
||||
|
||||
import fl.data.DataProvider;
|
||||
|
||||
//--------------------------------------
|
||||
// Class description
|
||||
//--------------------------------------
|
||||
|
||||
/**
|
||||
* The TreeDataProvider class provides methods and properties that allow you to query and modify
|
||||
* the data in a Tree Component.
|
||||
*
|
||||
* <p>A <em>TreeDataProvider</em> is the current linear representation of the state of the Tree component.
|
||||
* However, even if some nodes are not visible, the TreeDataProvider holds information about them in member
|
||||
* fields of the visible nodes. For example, consider the following tree:
|
||||
* <p>
|
||||
* <node label=\"Folder 1\">
|
||||
* <br /> <node label=\"File 1\"/>
|
||||
* <br /> <node label=\"File 2\"/>
|
||||
* <br /></node>
|
||||
* <br /><node label=\"Folder 2\">
|
||||
* <br /> <node label=\"File 3\"/>
|
||||
* <br /> <node label=\"File 4\"/>
|
||||
* <br /></node>
|
||||
* </p>
|
||||
* <p>When the TreeDataProvider is initialized with the XML shown above, it will contain two items: one with label
|
||||
* "Folder 1", and one with label "Folder 2". However, each of these items will have a number of fields that tie
|
||||
* them to the Tree structure. These fields are: <em>nodeType</em> (either branch or leaf), <em>nodeState</em>
|
||||
* (either open or closed), <em>nodeLevel</em> (the depth within the tree), and <em>nodeChildren</em> (a set of
|
||||
* references to all of the node's children, if applicable. In the example, the node with label "Folder 1" will
|
||||
* have <em>nodeType</em> set to "branch node", <em>nodeState</em> set to "closed node", <em>nodeLevel</em> to 0,
|
||||
* and <em>nodeChildren</em> would contain references to nodes with labels "File 1" and "File 2".
|
||||
* </p><p>
|
||||
* When the node "Folder 1" is expanded, the <em>TreeDataProvider</em> will contain 4 items: "Folder 1", "File 1",
|
||||
* "File 2", "Folder 2".
|
||||
* </p>
|
||||
*
|
||||
* @author Allen Rabinovich
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*
|
||||
* <p>
|
||||
* <strong>Example usage:</strong><br/>
|
||||
* <em>
|
||||
* var mytree:Tree = new Tree();<br/>
|
||||
* var myxml:XML = <node label=\"Folder 1\"><node label=\"File 2\"/></node>;<br/>
|
||||
* mytree.dp = new TreeDataProvider(myxml);<br/>
|
||||
* addChild(mytree);<br/>
|
||||
* </em>
|
||||
* </p>
|
||||
*/
|
||||
|
||||
public class TreeDataProvider extends DataProvider {
|
||||
|
||||
/**
|
||||
* A constant used for populating the <em>nodeState</em> field.
|
||||
*/
|
||||
public static const OPEN_NODE : String = "openNode";
|
||||
/**
|
||||
* A constant used for populating the <em>nodeState</em> field.
|
||||
*/
|
||||
public static const CLOSED_NODE : String = "closedNode";
|
||||
|
||||
/**
|
||||
* A constant used for populating the <em>nodeType</em> field.
|
||||
*/
|
||||
public static const BRANCH_NODE : String = "branchNode";
|
||||
|
||||
/**
|
||||
* A constant used for populating the <em>nodeType</em> field.
|
||||
*/
|
||||
public static const LEAF_NODE : String = "leafNode";
|
||||
|
||||
/**
|
||||
* A constant used for populating the <em>nodeType</em> field.
|
||||
*/
|
||||
public static const ROOT_NODE : String = "rootNode";
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Used for traversing the tree
|
||||
*/
|
||||
private var nodeCounter:int;
|
||||
|
||||
public var rootNode:TNode;
|
||||
|
||||
/**
|
||||
* Creates a new TreeDataProvider object using an instance of XML object as data source.
|
||||
* The hierarchical structure of the XML object is reproduced in the Tree as parent-child
|
||||
* relationships between Objects. Each XML node is converted into an Object, and its attributes
|
||||
* are converted to fields within the Object. In addition, the following values are populated
|
||||
* for each node:
|
||||
* <p><em>nodeType</em> - Can be either <em>BRANCH_NODE</em> or <em>LEAF_NODE</em>. Represents
|
||||
* whether a Node has any children.</p>
|
||||
* <p><em>nodeState</em> - If the node is a <em>BRANCH_NODE</em>, represents whether it's currently
|
||||
* open or closed. The value can be either <em>OPEN_NODE</em> or <em>CLOSED_NODE</em></p>
|
||||
* <p><em>nodeLevel</em> - The depth of the Node within the Tree. Can be used for indenting the node
|
||||
* by the cell renderer.</p>
|
||||
* <p><em>nodeChildren</em> - An Array of pointers to the objects representing children of the current node.</p>
|
||||
*
|
||||
* @param data The XML data that is used to create the DataProvider.
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
|
||||
public function TreeDataProvider(value:Object=null) {
|
||||
data = [];
|
||||
super(value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Toggles the node state of a branch node. If the node is currently open, it becomes closed; and vice versa.
|
||||
* The effect on the dataProvider is as follows: if the node is being opened, all of its children are added
|
||||
* to the dataProvider below the node; if the node is being closed, all of its children are removed from the
|
||||
* dataProvider.
|
||||
* <p>The state of the child nodes of the current node is preserved; that is, if a child node of the current node
|
||||
* is a branch node and was open when its parent node was closed, it will be open when the parent node is
|
||||
* reopened.</p>
|
||||
* <p>This method is deprecated. Use <code>BranchNode.openNode()</code> and <code>BranchNode.closeNode()</code> instead.</p>
|
||||
*
|
||||
* @param nodeIndex The dataProvider index of the node to be toggled.
|
||||
*
|
||||
* @see com.yahoo.astra.fl.controls.treeClasses.BranchNode
|
||||
*/
|
||||
public function toggleNode (nodeIndex:int) : void {
|
||||
var currentNode:TNode = this.getItemAt(nodeIndex) as TNode;
|
||||
if (currentNode is BranchNode && !(currentNode is RootNode)) {
|
||||
if (currentNode.isOpen()) {
|
||||
currentNode.closeNode();
|
||||
}
|
||||
else {
|
||||
currentNode.openNode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Placeholder for next release.
|
||||
*/
|
||||
private function moveNode (oldNodeIndex:int, newNodeIndex:int) : void {
|
||||
}
|
||||
|
||||
/**
|
||||
* @private (protected)
|
||||
* Overrides the DataProvider's main method for parsing objects
|
||||
* to allow for hierarchical XML
|
||||
*
|
||||
* @langversion 3.0
|
||||
* @playerversion Flash 9.0.28.0
|
||||
*/
|
||||
private function createTreeFromXML(xml:XML) : void {
|
||||
|
||||
rootNode = new RootNode(this);
|
||||
|
||||
rootNode.drawNode();
|
||||
for each (var child:XML in xml.children()) {
|
||||
parseXMLNode(child, rootNode as BranchNode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Parses a specific XML node and gives it Tree-specific properties.
|
||||
*/
|
||||
private function parseXMLNode(xml:XML, parentNode:BranchNode) : void {
|
||||
var newNode:TNode;
|
||||
|
||||
if (xml.children().length() > 0) {
|
||||
newNode = new BranchNode(this);
|
||||
}
|
||||
else {
|
||||
newNode = new LeafNode(this);
|
||||
}
|
||||
|
||||
var attrs:XMLList = xml.attributes();
|
||||
for each (var attr:XML in attrs) {
|
||||
newNode[attr.localName()] = attr.toString();
|
||||
}
|
||||
|
||||
parentNode.addChildNode(newNode);
|
||||
|
||||
|
||||
for each (var child:XML in xml.children()) {
|
||||
parseXMLNode(child, newNode as BranchNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Checks whether something is a tree node.
|
||||
*/
|
||||
private function isTreeNode (obj:Object) : Boolean {
|
||||
return (obj is TNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Initialized retrieval from a data object that's passed in. Currently only works with XML files.
|
||||
*/
|
||||
|
||||
override protected function getDataFromObject(obj:Object):Array {
|
||||
if (obj is XML) {
|
||||
var xml:XML = obj as XML;
|
||||
createTreeFromXML(xml);
|
||||
return this.toArray();
|
||||
} else {
|
||||
throw new TypeError("Error: Type Coercion failed: cannot convert " + obj + " to TreeDataProvider.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user