/** * @return a "Sample" tree with {@link TextInBox} items as nodes. */ public static ITreeForTreeLayout <TextInBox> ASTTree() { TextInBox root = new TextInBox("prog", 40, 20); TextInBox n1 = new TextInBox("classDef", 65, 20); TextInBox n1_1 = new TextInBox("class", 50, 20); TextInBox n1_2 = new TextInBox("T", 20, 20); TextInBox n1_3 = new TextInBox("{", 20, 20); TextInBox n1_4 = new TextInBox("member", 60, 20); TextInBox n1_5 = new TextInBox("member", 60, 20); TextInBox n1_5_1 = new TextInBox("<ERROR:int>", 90, 20); TextInBox n1_6 = new TextInBox("member", 60, 20); TextInBox n1_6_1 = new TextInBox("int", 30, 20); TextInBox n1_6_2 = new TextInBox("i", 20, 20); TextInBox n1_6_3 = new TextInBox(";", 20, 20); TextInBox n1_7 = new TextInBox("}", 20, 20); DefaultTreeForTreeLayout <TextInBox> tree = new DefaultTreeForTreeLayout <TextInBox>( root); tree.Add(root, n1); tree.Add(n1, n1_1); tree.Add(n1, n1_2); tree.Add(n1, n1_3); tree.Add(n1, n1_4); tree.Add(n1, n1_5); tree.Add(n1_5, n1_5_1); tree.Add(n1, n1_6); tree.Add(n1_6, n1_6_1); tree.Add(n1_6, n1_6_2); tree.Add(n1_6, n1_6_3); tree.Add(n1, n1_7); return(tree); }
private void PaintEdges(Graphics g, TextInBox parent) { if (!GetTree().IsLeaf(parent)) { RectangleF b1 = BoundsOfNode(parent); double x1 = b1.Left + b1.Width / 2; double y1 = b1.Top + b1.Height / 2; foreach (TextInBox child in ChildrenOf(parent)) { RectangleF b2 = BoundsOfNode(child); g.DrawLine(new Pen(BORDER_COLOR), (int)x1, (int)y1, (int)(b2.Left + b2.Width / 2), (int)(b2.Top + b2.Height / 2)); PaintEdges(g, child); } } }
/** * @return a "Sample" tree with {@link TextInBox} items as nodes. */ public static ITreeForTreeLayout <TextInBox> SimpleTree() { TextInBox root = new TextInBox("root", 40, 20); TextInBox n1 = new TextInBox("n1", 30, 20); TextInBox n1_1 = new TextInBox("n1.1", 80, 36); TextInBox n1_2 = new TextInBox("n1.2", 40, 20); TextInBox n1_3 = new TextInBox("n1.3", 80, 36); TextInBox n2 = new TextInBox("n2", 30, 20); TextInBox n2_1 = new TextInBox("n2.1", 30, 20); DefaultTreeForTreeLayout <TextInBox> tree = new DefaultTreeForTreeLayout <TextInBox>( root); tree.Add(root, n1); tree.Add(n1, n1_1); tree.Add(n1, n1_2); tree.Add(n1, n1_3); tree.Add(root, n2); tree.Add(n2, n2_1); return(tree); }
private void PaintBox(Graphics g, TextInBox textInBox) { // draw the box in the background // g.setColor(BOX_COLOR); RectangleF box = BoundsOfNode(textInBox); g.FillRectangle(new SolidBrush(BOX_COLOR), (int)box.Left, (int)box.Top, (int)box.Width - 1, (int)box.Height - 1); g.DrawRectangle(new Pen(BORDER_COLOR), (int)box.Left, (int)box.Top, (int)box.Width - 1, (int)box.Height - 1); // draw the text on top of the box (possibly multiple lines) // g.setColor(TEXT_COLOR); string[] lines = textInBox.Text.Split('\n'); // FontMetrics m = getFontMetrics(getFont()); // int x = (int)box.x + ARC_SIZE / 2; // int y = (int)box.y + m.getAscent() + m.getLeading() + 1; for (int i = 0; i < lines.Length; i++) { g.DrawText(new Font("Arial", ARC_SIZE), new SolidBrush(TEXT_COLOR), box.TopLeft, lines[i]); // y += m.getHeight(); } }
private RectangleF BoundsOfNode(TextInBox node) => treeLayout.NodeBounds[node];
private IEnumerable <TextInBox> ChildrenOf(TextInBox parent) => GetTree().Children(parent);