Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        public DependencyTreeNode <T> AddDependency(T item)
        {
            DependencyTreeNode <T> node = new DependencyTreeNode <T>(item, this);

            dependants.Add(node);
            return(node);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public static void WalkTreeChildrenFirst(DependencyTreeNode <T> root, Action <DependencyTreeNode <T> > action)
 {
     foreach (DependencyTreeNode <T> node in root.Dependants)
     {
         WalkTreeChildrenFirst(node, action);
     }
     action(root);
 }
Ejemplo n.º 5
0
 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;
     }
 }
Ejemplo n.º 6
0
 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);
     }
 }
Ejemplo n.º 7
0
 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;
     }));
 }
Ejemplo n.º 8
0
 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;
     });
 }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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;
            }
        }
Ejemplo n.º 11
0
 public void Reparent(DependencyTreeNode <T> parent)
 {
     parent.dependants.Add(this);
     this.parentNode.dependants.Remove(this);
     this.parentNode = parent;
 }
Ejemplo n.º 12
0
 private DependencyTreeNode(T item, DependencyTreeNode <T> parent)
 {
     this.item  = item;
     parentNode = parent;
 }
Ejemplo n.º 13
0
 private int ComparePairValue(
     DependencyTreeNode <IRectangleSizeDecorator> a,
     DependencyTreeNode <IRectangleSizeDecorator> b)
 {
     return(a.Item.SummedSize.CompareTo(b.Item.SummedSize));
 }
Ejemplo n.º 14
0
 private void SortByPhysicalSize(DependencyTreeNode <IRectangleSizeDecorator> rectNode)
 {
     rectNode.Dependants.Sort(ComparePairValue);
 }
Ejemplo n.º 15
0
 public static void WalkTreeChildrenFirst(DependencyTreeNode <T> root, Action <T> action)
 {
     WalkTreeChildrenFirst(root, delegate(DependencyTreeNode <T> item) { action(item.Item); });
 }
Ejemplo n.º 16
0
 public static DependencyTreeNode <T> FindNode(DependencyTreeNode <T> root, Predicate <T> predicate)
 {
     return(FindNode(root, delegate(DependencyTreeNode <T> item) { return predicate(item.Item); }));
 }