Esempio n. 1
0
        static VisualNode BreadthFirstEnumaration(ITextTree tree)
        {
            var nodeQueue = new Queue <VisualNode>();

            var root = new VisualNode {
                X = 0, Y = 0, TreeNode = tree.Root
            };

            nodeQueue.Enqueue(root);

            var curDepth = 0;
            var x        = 0;

            while (nodeQueue.Count > 0)
            {
                var node = nodeQueue.Dequeue();

                if (curDepth != node.Y)
                {
                    x        = node.X;
                    curDepth = node.Y;
                }

                if (node.TreeNode.Children == null)
                {
                    continue;
                }

                node.Children = new List <VisualNode>();

                foreach (var tn in node.TreeNode.Children)
                {
                    var vn = new VisualNode {
                        X = x++, Y = node.Y + 1, TreeNode = tn
                    };
                    node.Children.Add(vn);
                    nodeQueue.Enqueue(vn);
                }
            }

            return(root);
        }
        private void BuildIndent(VisualNode vn)
        {
            if (indent.ContainsKey(vn.Y))
            {
                if (indent[vn.Y] < vn.X + 1)
                {
                    indent[vn.Y] = vn.X + 1;
                }
            }
            else
            {
                indent.Add(vn.Y, vn.X + 1);
            }

            if (vn.Children == null)
            {
                return;
            }

            foreach (var cvn in vn.Children)
            {
                BuildIndent(cvn);
            }
        }
 private Pen GetEdgePen(VisualNode parent, VisualNode child)
 {
     return(NeedHighLight(parent.TreeNode.Tree.TreeId, parent.TreeNode.PreorderIndex, child.TreeNode.PreorderIndex)
         ? highLightEdgePen : normalEdgePen);
 }
 private Pen GetNodePen(VisualNode vn)
 {
     return(NeedHighLight(vn.TreeNode.Tree.TreeId, vn.TreeNode.PreorderIndex)
        ? highLightNodePen : normalNodePen);
 }
 private SolidBrush GetIndexBrush(VisualNode vn)
 {
     return(NeedHighLight(vn.TreeNode.Tree.TreeId, vn.TreeNode.PreorderIndex)
         ? highLightIndexBrush : normalIndexBrush);
 }