private void ArrangeNodes(DependencyTreeNode <IRectangleSizeDecorator> rectNode) { // Don't handle leafs directly. Let their parent arrange them. if (rectNode.IsLeaf) { return; } if (rectNode.Item == null) { return; } float x = XSpacing; rectNode.Item.X = XSpacing; rectNode.Item.Y = YSpacing; float h = rectNode.Item.Height; foreach (DependencyTreeNode <IRectangleSizeDecorator> node in rectNode.Dependants) { node.Item.X = x; node.Item.Y = YSpacing; x += node.Item.Width + XSpacing; h = Math.Max(h, rectNode.Item.Height + YSpacing + node.Item.Height); } rectNode.Item.Height = h; rectNode.Item.Width = Math.Max(x - XSpacing, rectNode.Item.Width); }
public DependencyTreeNode <T> AddDependency(T item) { DependencyTreeNode <T> node = new DependencyTreeNode <T>(item, this); dependants.Add(node); return(node); }
public void AddDependency(T item, T dependency) { DependencyTreeNode <T> depNode = null; if (dependency == null) { depNode = root; } else { depNode = FindNode(dependency); } DependencyTreeNode <T> itemNode = FindNode(item); if (depNode == null) { depNode = root.AddDependency(dependency); } if (itemNode == null) { depNode.AddDependency(item); } else if (dependency != null) { itemNode.Reparent(depNode); } }
public static void WalkTreeChildrenFirst(DependencyTreeNode <T> root, Action <DependencyTreeNode <T> > action) { foreach (DependencyTreeNode <T> node in root.Dependants) { WalkTreeChildrenFirst(node, action); } action(root); }
private void CalcPhysicalSizeRecursive(DependencyTreeNode <IRectangleSizeDecorator> rectNode) { rectNode.Item.Size = (rectNode.Item.Rectangle.ActualWidth + XSpacing) * (rectNode.Item.Rectangle.ActualHeight + YSpacing); rectNode.Item.ChildrenSize = 0; rectNode.Item.SummedSize = rectNode.Item.Size; foreach (DependencyTreeNode <IRectangleSizeDecorator> dn in rectNode.Dependants) { rectNode.Item.ChildrenSize += dn.Item.Size; rectNode.Item.SummedSize += dn.Item.SummedSize; } }
private void MoveSubTreeByParentPosition(DependencyTreeNode <IRectangleSizeDecorator> rectNode) { if (rectNode.Item == null) { return; } foreach (DependencyTreeNode <IRectangleSizeDecorator> node in rectNode.Dependants) { MoveSubTreeBy(node, rectNode.Item.X - XSpacing, rectNode.Item.Y - YSpacing); } }
public static DependencyTreeNode <T> FindNode(DependencyTreeNode <T> root, T item) { if (item == null) { return(null); } return(FindNode(root, delegate(T nodeItem) { bool ret = (item.Equals(nodeItem)); return ret; })); }
private void MoveSubTreeBy(DependencyTreeNode <IRectangleSizeDecorator> root, float x, float y) { DependencyTree <IRectangleSizeDecorator> .WalkTreeRootFirst( root, delegate(IRectangleSizeDecorator rect) { if (rect == null) { return; } rect.Rectangle.X += x; rect.Rectangle.Y += y; }); }
public static DependencyTreeNode <T> FindNode(DependencyTreeNode <T> root, Predicate <DependencyTreeNode <T> > predicate) { if (predicate(root)) { return(root); } DependencyTreeNode <T> ret = null; foreach (DependencyTreeNode <T> node in root.Dependants) { ret = FindNode(node, predicate); if (ret != null) { break; } } return(ret); }
private void SetupPositions(DependencyTreeNode <IRectangleSizeDecorator> rectNode) { if (rectNode.Item == null) { return; } if (rectNode.Item.Rectangle == null) { return; } if (rectNode.ParentNode != null && rectNode.ParentNode.Item != null) { IRectangle parent = rectNode.ParentNode.Item.Rectangle; rectNode.Item.Rectangle.Y = parent.Y + parent.ActualHeight + YSpacing; rectNode.Item.Rectangle.X = rectNode.Item.X; } else { rectNode.Item.Rectangle.X = XSpacing; rectNode.Item.Rectangle.Y = YSpacing; } }
private int ComparePairValue( DependencyTreeNode <IRectangleSizeDecorator> a, DependencyTreeNode <IRectangleSizeDecorator> b) { return(a.Item.SummedSize.CompareTo(b.Item.SummedSize)); }
private void SortByPhysicalSize(DependencyTreeNode <IRectangleSizeDecorator> rectNode) { rectNode.Dependants.Sort(ComparePairValue); }
public void Reparent(DependencyTreeNode <T> parent) { parent.dependants.Add(this); this.parentNode.dependants.Remove(this); this.parentNode = parent; }
private DependencyTreeNode(T item, DependencyTreeNode <T> parent) { this.item = item; parentNode = parent; }
public static void WalkTreeChildrenFirst(DependencyTreeNode <T> root, Action <T> action) { WalkTreeChildrenFirst(root, delegate(DependencyTreeNode <T> item) { action(item.Item); }); }
public static DependencyTreeNode <T> FindNode(DependencyTreeNode <T> root, Predicate <T> predicate) { return(FindNode(root, delegate(DependencyTreeNode <T> item) { return predicate(item.Item); })); }