File: ASTFrame.cs

package info (click to toggle)
antlr 2.7.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,920 kB
  • sloc: java: 54,649; cs: 12,533; makefile: 8,963; cpp: 7,359; pascal: 5,273; sh: 4,337; python: 4,301; lisp: 1,969; xml: 220; lex: 192; ansic: 134
file content (112 lines) | stat: -rw-r--r-- 2,780 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Drawing;
//using System.Collections;
//using System.ComponentModel;
using System.Windows.Forms;

//using antlr;
using AST = antlr.collections.AST;

namespace antlr.debug.misc
{
	/// <summary>
	/// Summary description for myASTFrame.
	/// </summary>
	public class ASTFrame : System.Windows.Forms.Form
	{
		// The initial width and height of the frame
		private const int WIDTH = 200;
		private const int HEIGHT = 300;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private ASTFrame()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			this.Size = new System.Drawing.Size(WIDTH,HEIGHT);
			Application.ApplicationExit += new EventHandler(Form_OnExit);
		}

		public ASTFrame(string title, AST rootAST) : this()
		{
			this.Text = title;

			JTreeASTPanel treePanel = new JTreeASTPanel(new TreeViewEventHandler(tree_AfterSelect), rootAST);			
			this.Controls.Add(treePanel);
			treePanel.Location= new Point(5, 5);
			treePanel.Dock=DockStyle.Fill;
			treePanel.Anchor=AnchorStyles.Top|AnchorStyles.Left;
		}

		private void Form_OnExit(object sender, EventArgs e)
		{
			this.Visible = false;
			this.Dispose();
		}

		private void tree_AfterSelect(object sender, TreeViewEventArgs e)
		{
			//System.Console.Out.WriteLine("Selected: " + e.Node.Text);

			string path = e.Node.FullPath;
			path = path.Replace(e.Node.TreeView.PathSeparator, "->");
			//System.Console.Out.WriteLine(e.Node.FullPath); 
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		public static void Main(string[] args)
		{
			// Create the tree nodes
			ASTFactory factory = new ASTFactory();
			CommonAST r = (CommonAST) factory.create(0, "ROOT");
			r.addChild((CommonAST) factory.create(0, "C1"));
			r.addChild((CommonAST) factory.create(0, "C2"));
			r.addChild((CommonAST) factory.create(0, "C3"));
			
			ASTFrame frame = new ASTFrame("AST JTree Example", r);
			Application.Run(frame);
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// ASTFrame
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Name = "ASTFrame";
			this.Text = "ASTFrame";

		}
		#endregion
	}
}