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 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
using System;
//using System.Collections;
//using System.ComponentModel;
//using System.Drawing;
//using System.Data;
using System.Windows.Forms;
using AST = antlr.collections.AST;
namespace antlr.debug.misc
{
/// <summary>
/// Summary description for myJTreeASTPanel.
/// </summary>
public class JTreeASTPanel : System.Windows.Forms.UserControl
{
private System.Windows.Forms.TreeView tree;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private JTreeASTPanel()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
public JTreeASTPanel(TreeViewEventHandler afterSelectHandler, AST rootAST) : this()
{
tree.AfterSelect += afterSelectHandler;
tree.BeforeExpand += new TreeViewCancelEventHandler(ASTTreeNode.tree_BeforeExpand);
tree.Nodes.Add(new ASTTreeNode(rootAST));
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component 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()
{
this.tree = new System.Windows.Forms.TreeView();
this.SuspendLayout();
//
// tree
//
this.tree.Dock = System.Windows.Forms.DockStyle.Fill;
this.tree.ImageIndex = -1;
this.tree.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.tree.Location = new System.Drawing.Point(5, 5);
this.tree.Name = "tree";
this.tree.SelectedImageIndex = -1;
this.tree.Size = new System.Drawing.Size(140, 140);
this.tree.TabIndex = 0;
//
// JTreeASTPanel
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tree});
this.DockPadding.All = 5;
this.Name = "JTreeASTPanel";
this.ResumeLayout(false);
}
#endregion
}
internal class ASTTreeNode : TreeNode
{
private AST ASTNode_;
internal bool IsAlreadyExpanded = false;
public AST ASTNode
{
get { return ASTNode_; }
set { ASTNode_ = value; }
}
public ASTTreeNode(AST a)
{
ASTNode_ = a;
this.Text = a.ToString();
this.Nodes.Add("Loading.....");
}
internal static void tree_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
ASTTreeNode thisNode = (ASTTreeNode)e.Node;
AST parentAST = thisNode.ASTNode;
AST childAST;
if (!thisNode.IsAlreadyExpanded)
{
thisNode.Nodes.Clear();
childAST = parentAST.getFirstChild();
while (null != childAST)
{
thisNode.Nodes.Add(new ASTTreeNode(childAST));
childAST = childAST.getNextSibling();
}
thisNode.IsAlreadyExpanded = true;
}
}
}
}
|