TraverseTreeEnumerator
| Kind of class: | class |
|---|---|
| Inherits from: | TreeEnumerator < Enumerator < Dispatcher |
| Version: | 20 July 2005 |
| Author: | Arthur Clemens |
| Classpath: | playground.classes.data.tree.TraverseTreeEnumerator |
| File last modified: | Friday, 14 July 2006, 00:49:05 |
Enhanced tree enumerator, with traversal options (traverse children, loop and skip root), a delegate to validate new states and dispatching of update events.
About traverse options, see TraverseTreeOptions.
To do:
When setting a new root, should the depths of the containing nodes be relative to root's depth? For instance if I set a node with depth 2 to root, should the next node of depth 3 be regarded as a node of depth 1?
Events broadcast to listeners:
TraverseTreeEnumeratorEvent with type:
UPDATE If the delegate validation method exists and only if the delegate method returns true.Summary
Constructor
Instance properties
Instance properties inherited from TreeEnumerator
Instance properties inherited from Dispatcher
Instance methods
Instance methods inherited from TreeEnumerator
Instance methods inherited from Enumerator
Constructor
TraverseTreeEnumerator
function TraverseTreeEnumerator (
inRootNode:TreeNode,
inTraverseOptions:Number)
Creates a new TraverseTreeEnumerator and initializes it for dispatching events.
Parameters:
inRootNode :
the root node of the enumerator; you may pass any node of the tree if the enumerator should start at that root - but the enumerator will traverse that branch only and will not traverse upwards to a node with a lower depth.
inTraverseOptions:
Tells the enumerator how to do traversing; see TraverseTreeOptions. Default set to TraverseTreeOptions.TRAVERSE_CHILDREN.
Instance properties
Instance methods
getNextNodeWithDepth
function getNextNodeWithDepth (
inDepth:Number,
inTraverseOptions:Number) : TreeNode
Gets the next node with the given depth and set the current node to the found node.
Parameters:
inDepth :
the hierarchical depth of the node; see TreeNode.depth
inTraverseOptions:
(optional): the traversal options (see TraverseTreeOptions); if not passed, the stored
mTraverseOptions are usedReturns:
If found, the return value of update; null if not found.
getNextObject
function getNextObject (
inTraverseOptions:Number) : TreeNode
Moves the enumerator one position forward and returns that node.
Parameters:
inTraverseOptions:
(optional): the traversal options (see TraverseTreeOptions); if not passed, the stored
mTraverseOptions are usedReturns:
The return value of update.
getPreviousObject
function getPreviousObject (
inTraverseOptions:Number) : TreeNode
Moves the enumerator one position backward and returns that node.
Parameters:
inTraverseOptions:
(optional): the traversal options (see TraverseTreeOptions); if not passed, the stored
mTraverseOptions are usedReturns:
The return value of update.
hasNextObject
function hasNextObject (
inTraverseOptions:Number) : Boolean
Checks if there is an object after the current object.
Returns:
True: there is a next object; false: the current object is the last.
hasPreviousObject
function hasPreviousObject (
inTraverseOptions:Number) : Boolean
Checks if there is an object before the current object.
Returns:
True: there is a next object; false: the current object is the last.
setDelegate
function setDelegate (
inDelegateObject:Object,
inDelegateMethod:Object) : Void
A delegate validation method is called in update when a delegate object is set. The delegate's validation method is called to evaluate the new node before it is set.
Parameters:
inDelegateObject:
the owner of the delegate method
inDelegateMethod:
Node validation method (method name or function reference). This method should accept a TreeNode as parameter and return a Boolean to indicate the node's validity.
Example:
mEnumerator.setDelegate(this, validateNewState);
// Validation method. If the red barrier blocks the button that represents the new node, this method returns false, and otherwise true.
private function validateNewState (inTreeNode:TreeNode) : Boolean {
// find corresponding button for this node:
var btn:TreeButton = getButtonForNode(inTreeNode);
// don't proceed if the barrier overlaps the button
if (btn.getBottom() > barrier_mc.getTop()) {
return false;
}
return true;
}