source: trunk/yao/share/antlr-2.7.7/lib/csharp/antlr.astframe/antlr.debug.misc/ASTFrame.cs @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 2.7 KB
Line 
1using System;
2using System.Drawing;
3//using System.Collections;
4//using System.ComponentModel;
5using System.Windows.Forms;
6
7//using antlr;
8using AST = antlr.collections.AST;
9
10namespace antlr.debug.misc
11{
12        /// <summary>
13        /// Summary description for myASTFrame.
14        /// </summary>
15        public class ASTFrame : System.Windows.Forms.Form
16        {
17                // The initial width and height of the frame
18                private const int WIDTH = 200;
19                private const int HEIGHT = 300;
20
21                /// <summary>
22                /// Required designer variable.
23                /// </summary>
24                private System.ComponentModel.Container components = null;
25
26                private ASTFrame()
27                {
28                        //
29                        // Required for Windows Form Designer support
30                        //
31                        InitializeComponent();
32
33                        //
34                        // TODO: Add any constructor code after InitializeComponent call
35                        //
36                        this.Size = new System.Drawing.Size(WIDTH,HEIGHT);
37                        Application.ApplicationExit += new EventHandler(Form_OnExit);
38                }
39
40                public ASTFrame(string title, AST rootAST) : this()
41                {
42                        this.Text = title;
43
44                        JTreeASTPanel treePanel = new JTreeASTPanel(new TreeViewEventHandler(tree_AfterSelect), rootAST);                       
45                        this.Controls.Add(treePanel);
46                        treePanel.Location= new Point(5, 5);
47                        treePanel.Dock=DockStyle.Fill;
48                        treePanel.Anchor=AnchorStyles.Top|AnchorStyles.Left;
49                }
50
51                private void Form_OnExit(object sender, EventArgs e)
52                {
53                        this.Visible = false;
54                        this.Dispose();
55                }
56
57                private void tree_AfterSelect(object sender, TreeViewEventArgs e)
58                {
59                        //System.Console.Out.WriteLine("Selected: " + e.Node.Text);
60
61                        string path = e.Node.FullPath;
62                        path = path.Replace(e.Node.TreeView.PathSeparator, "->");
63                        //System.Console.Out.WriteLine(e.Node.FullPath);
64                }
65
66                /// <summary>
67                /// Clean up any resources being used.
68                /// </summary>
69                protected override void Dispose( bool disposing )
70                {
71                        if( disposing )
72                        {
73                                if(components != null)
74                                {
75                                        components.Dispose();
76                                }
77                        }
78                        base.Dispose( disposing );
79                }
80
81                public static void Main(string[] args)
82                {
83                        // Create the tree nodes
84                        ASTFactory factory = new ASTFactory();
85                        CommonAST r = (CommonAST) factory.create(0, "ROOT");
86                        r.addChild((CommonAST) factory.create(0, "C1"));
87                        r.addChild((CommonAST) factory.create(0, "C2"));
88                        r.addChild((CommonAST) factory.create(0, "C3"));
89                       
90                        ASTFrame frame = new ASTFrame("AST JTree Example", r);
91                        Application.Run(frame);
92                }
93
94                #region Windows Form Designer generated code
95                /// <summary>
96                /// Required method for Designer support - do not modify
97                /// the contents of this method with the code editor.
98                /// </summary>
99                private void InitializeComponent()
100                {
101                        //
102                        // ASTFrame
103                        //
104                        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
105                        this.ClientSize = new System.Drawing.Size(292, 273);
106                        this.Name = "ASTFrame";
107                        this.Text = "ASTFrame";
108
109                }
110                #endregion
111        }
112}
Note: See TracBrowser for help on using the repository browser.