1 | using System; |
---|
2 | //using System.Collections; |
---|
3 | //using System.ComponentModel; |
---|
4 | //using System.Drawing; |
---|
5 | //using System.Data; |
---|
6 | using System.Windows.Forms; |
---|
7 | |
---|
8 | using AST = antlr.collections.AST; |
---|
9 | |
---|
10 | namespace antlr.debug.misc |
---|
11 | { |
---|
12 | /// <summary> |
---|
13 | /// Summary description for myJTreeASTPanel. |
---|
14 | /// </summary> |
---|
15 | public class JTreeASTPanel : System.Windows.Forms.UserControl |
---|
16 | { |
---|
17 | private System.Windows.Forms.TreeView tree; |
---|
18 | /// <summary> |
---|
19 | /// Required designer variable. |
---|
20 | /// </summary> |
---|
21 | private System.ComponentModel.Container components = null; |
---|
22 | |
---|
23 | private JTreeASTPanel() |
---|
24 | { |
---|
25 | // This call is required by the Windows.Forms Form Designer. |
---|
26 | InitializeComponent(); |
---|
27 | |
---|
28 | // TODO: Add any initialization after the InitForm call |
---|
29 | |
---|
30 | } |
---|
31 | |
---|
32 | public JTreeASTPanel(TreeViewEventHandler afterSelectHandler, AST rootAST) : this() |
---|
33 | { |
---|
34 | tree.AfterSelect += afterSelectHandler; |
---|
35 | tree.BeforeExpand += new TreeViewCancelEventHandler(ASTTreeNode.tree_BeforeExpand); |
---|
36 | tree.Nodes.Add(new ASTTreeNode(rootAST)); |
---|
37 | } |
---|
38 | |
---|
39 | /// <summary> |
---|
40 | /// Clean up any resources being used. |
---|
41 | /// </summary> |
---|
42 | protected override void Dispose( bool disposing ) |
---|
43 | { |
---|
44 | if( disposing ) |
---|
45 | { |
---|
46 | if(components != null) |
---|
47 | { |
---|
48 | components.Dispose(); |
---|
49 | } |
---|
50 | } |
---|
51 | base.Dispose( disposing ); |
---|
52 | } |
---|
53 | |
---|
54 | #region Component Designer generated code |
---|
55 | /// <summary> |
---|
56 | /// Required method for Designer support - do not modify |
---|
57 | /// the contents of this method with the code editor. |
---|
58 | /// </summary> |
---|
59 | private void InitializeComponent() |
---|
60 | { |
---|
61 | this.tree = new System.Windows.Forms.TreeView(); |
---|
62 | this.SuspendLayout(); |
---|
63 | // |
---|
64 | // tree |
---|
65 | // |
---|
66 | this.tree.Dock = System.Windows.Forms.DockStyle.Fill; |
---|
67 | this.tree.ImageIndex = -1; |
---|
68 | this.tree.ImeMode = System.Windows.Forms.ImeMode.NoControl; |
---|
69 | this.tree.Location = new System.Drawing.Point(5, 5); |
---|
70 | this.tree.Name = "tree"; |
---|
71 | this.tree.SelectedImageIndex = -1; |
---|
72 | this.tree.Size = new System.Drawing.Size(140, 140); |
---|
73 | this.tree.TabIndex = 0; |
---|
74 | // |
---|
75 | // JTreeASTPanel |
---|
76 | // |
---|
77 | this.Controls.AddRange(new System.Windows.Forms.Control[] { |
---|
78 | this.tree}); |
---|
79 | this.DockPadding.All = 5; |
---|
80 | this.Name = "JTreeASTPanel"; |
---|
81 | this.ResumeLayout(false); |
---|
82 | |
---|
83 | } |
---|
84 | #endregion |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | internal class ASTTreeNode : TreeNode |
---|
89 | { |
---|
90 | private AST ASTNode_; |
---|
91 | internal bool IsAlreadyExpanded = false; |
---|
92 | |
---|
93 | public AST ASTNode |
---|
94 | { |
---|
95 | get { return ASTNode_; } |
---|
96 | set { ASTNode_ = value; } |
---|
97 | } |
---|
98 | |
---|
99 | public ASTTreeNode(AST a) |
---|
100 | { |
---|
101 | ASTNode_ = a; |
---|
102 | this.Text = a.ToString(); |
---|
103 | this.Nodes.Add("Loading....."); |
---|
104 | } |
---|
105 | |
---|
106 | internal static void tree_BeforeExpand(object sender, TreeViewCancelEventArgs e) |
---|
107 | { |
---|
108 | ASTTreeNode thisNode = (ASTTreeNode)e.Node; |
---|
109 | AST parentAST = thisNode.ASTNode; |
---|
110 | AST childAST; |
---|
111 | |
---|
112 | if (!thisNode.IsAlreadyExpanded) |
---|
113 | { |
---|
114 | thisNode.Nodes.Clear(); |
---|
115 | childAST = parentAST.getFirstChild(); |
---|
116 | while (null != childAST) |
---|
117 | { |
---|
118 | thisNode.Nodes.Add(new ASTTreeNode(childAST)); |
---|
119 | childAST = childAST.getNextSibling(); |
---|
120 | } |
---|
121 | thisNode.IsAlreadyExpanded = true; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | } |
---|
126 | } |
---|