using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Globalization;
using Common;
namespace TreeTest
{
public class Form1 : System.Windows.Forms.Form
{
private ITree tree = null;
private ITree treeClipboard = null;
private object oSetObject = null;
private System.Windows.Forms.TreeView TreeView;
private System.Windows.Forms.ToolBar ToolBar;
private System.Windows.Forms.ImageList ImageList;
private System.Windows.Forms.ToolBarButton ToolBarButtonViewRefresh;
private System.Windows.Forms.ToolBarButton ToolBarButtonFileNew;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox TextBoxCount;
private System.Windows.Forms.TextBox TextBoxTotal;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button ButtonDirectChildrenEnumerator;
private System.Windows.Forms.Button ButtonINodeEnumerator;
private System.Windows.Forms.Button ButtonITreeEnumerator;
private System.Windows.Forms.Button ButtonInReverseEnumerator;
private System.Windows.Forms.Button ButtonAllChildrenEnumerator;
private System.Windows.Forms.Button ButtonInsertInteger;
private System.Windows.Forms.Button ButtonInsertNode;
private System.Windows.Forms.TreeView TreeViewClipboard;
private System.Windows.Forms.Button ButtonCut;
private System.Windows.Forms.Button ButtonCopy;
private System.Windows.Forms.Button ButtonDeepCopy;
private System.Windows.Forms.Button ButtonDelete;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button ButtonCopyObject;
private System.Windows.Forms.Button ButtonDeepCopyObject;
private System.Windows.Forms.Button ButtonCutObject;
private System.Windows.Forms.Button ButtonRemoveObject;
private System.Windows.Forms.Button ButtonContainsObject;
private System.Windows.Forms.Button ButtonSetObject;
private System.Windows.Forms.Button ButtonMoveToPrevious;
private System.Windows.Forms.Button ButtonMoveToNext;
private System.Windows.Forms.Button ButtonMoveToParent;
private System.Windows.Forms.Button ButtonMoveToChild;
private System.Windows.Forms.Button ButtonMoveToFirst;
private System.Windows.Forms.Button ButtonMoveToLast;
private System.Windows.Forms.Button ButtonInsertChildTree;
private System.Windows.Forms.Button ButtonInsertNextTree;
private System.Windows.Forms.Button ButtonInsertPreviousTree;
private System.Windows.Forms.Button ButtonAddTree;
private System.Windows.Forms.Button ButtonAddChildTree;
private System.Windows.Forms.Button ButtonAddObject;
private System.Windows.Forms.Button ButtonAddChildObject;
private System.Windows.Forms.Button ButtonInsertChildObject;
private System.Windows.Forms.Button ButtonInsertNextObject;
private System.Windows.Forms.Button ButtonInsertPreviousObject;
private System.Windows.Forms.Button ButtonCopyToArray;
private System.Windows.Forms.TextBox TextBoxHandlers;
private System.Windows.Forms.Button ButtonSetData;
private System.Windows.Forms.Button ButtonClear;
private System.ComponentModel.IContainer components;
public Form1()
{
InitializeComponent();
// tree = NodeTree.NewTree();
tree = NodeTree.NewTree( typeof( Element ) );
tree.Validate += new NodeTreeDataEventHandler ( Tree_Validate );
tree.Clearing += new EventHandler ( Tree_Clearing );
tree.Cleared += new EventHandler ( Tree_Cleared );
tree.Setting += new NodeTreeDataEventHandler ( Tree_Setting );
tree.SetDone += new NodeTreeDataEventHandler ( Tree_SetDone );
tree.Inserting += new NodeTreeInsertEventHandler ( Tree_Inserting );
tree.Inserted += new NodeTreeInsertEventHandler ( Tree_Inserted );
tree.Cutting += new EventHandler ( Tree_Cutting );
tree.CutDone += new EventHandler ( Tree_CutDone );
tree.Copying += new NodeTreeNodeEventHandler ( Tree_Copying );
tree.Copied += new NodeTreeNodeEventHandler ( Tree_Copied );
tree.DeepCopying += new NodeTreeNodeEventHandler ( Tree_DeepCopying );
tree.DeepCopied += new NodeTreeNodeEventHandler ( Tree_DeepCopied );
OnFileNew();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#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()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.TreeView = new System.Windows.Forms.TreeView();
this.ToolBar = new System.Windows.Forms.ToolBar();
this.ToolBarButtonFileNew = new System.Windows.Forms.ToolBarButton();
this.ToolBarButtonViewRefresh = new System.Windows.Forms.ToolBarButton();
this.ImageList = new System.Windows.Forms.ImageList(this.components);
this.label1 = new System.Windows.Forms.Label();
this.TextBoxCount = new System.Windows.Forms.TextBox();
this.TextBoxTotal = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.ButtonDirectChildrenEnumerator = new System.Windows.Forms.Button();
this.ButtonINodeEnumerator = new System.Windows.Forms.Button();
this.ButtonITreeEnumerator = new System.Windows.Forms.Button();
this.ButtonInReverseEnumerator = new System.Windows.Forms.Button();
this.ButtonAllChildrenEnumerator = new System.Windows.Forms.Button();
this.ButtonInsertChildTree = new System.Windows.Forms.Button();
this.ButtonInsertNextTree = new System.Windows.Forms.Button();
this.ButtonInsertPreviousTree = new System.Windows.Forms.Button();
this.ButtonInsertInteger = new System.Windows.Forms.Button();
this.ButtonInsertNode = new System.Windows.Forms.Button();
this.TreeViewClipboard = new System.Windows.Forms.TreeView();
this.ButtonCut = new System.Windows.Forms.Button();
this.ButtonCopy = new System.Windows.Forms.Button();
this.ButtonDeepCopy = new System.Windows.Forms.Button();
this.ButtonDelete = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.ButtonCopyObject = new System.Windows.Forms.Button();
this.ButtonDeepCopyObject = new System.Windows.Forms.Button();
this.ButtonCutObject = new System.Windows.Forms.Button();
this.ButtonRemoveObject = new System.Windows.Forms.Button();
this.ButtonContainsObject = new System.Windows.Forms.Button();
this.ButtonSetObject = new System.Windows.Forms.Button();
this.ButtonMoveToPrevious = new System.Windows.Forms.Button();
this.ButtonMoveToChild = new System.Windows.Forms.Button();
this.ButtonMoveToNext = new System.Windows.Forms.Button();
this.ButtonMoveToParent = new System.Windows.Forms.Button();
this.ButtonMoveToFirst = new System.Windows.Forms.Button();
this.ButtonMoveToLast = new System.Windows.Forms.Button();
this.ButtonAddTree = new System.Windows.Forms.Button();
this.ButtonAddChildTree = new System.Windows.Forms.Button();
this.ButtonAddObject = new System.Windows.Forms.Button();
this.ButtonAddChildObject = new System.Windows.Forms.Button();
this.ButtonInsertChildObject = new System.Windows.Forms.Button();
this.ButtonInsertNextObject = new System.Windows.Forms.Button();
this.ButtonInsertPreviousObject = new System.Windows.Forms.Button();
this.ButtonCopyToArray = new System.Windows.Forms.Button();
this.TextBoxHandlers = new System.Windows.Forms.TextBox();
this.ButtonSetData = new System.Windows.Forms.Button();
this.ButtonClear = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// TreeView
//
this.TreeView.FullRowSelect = true;
this.TreeView.HideSelection = false;
this.TreeView.ImageIndex = -1;
this.TreeView.Location = new System.Drawing.Point(8, 56);
this.TreeView.Name = "TreeView";
this.TreeView.SelectedImageIndex = -1;
this.TreeView.ShowRootLines = false;
this.TreeView.Size = new System.Drawing.Size(160, 344);
this.TreeView.TabIndex = 5;
this.TreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TreeView_AfterSelect);
//
// ToolBar
//
this.ToolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.ToolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.ToolBarButtonFileNew,
this.ToolBarButtonViewRefresh});
this.ToolBar.DropDownArrows = true;
this.ToolBar.ImageList = this.ImageList;
this.ToolBar.Location = new System.Drawing.Point(0, 0);
this.ToolBar.Name = "ToolBar";
this.ToolBar.ShowToolTips = true;
this.ToolBar.Size = new System.Drawing.Size(848, 28);
this.ToolBar.TabIndex = 0;
this.ToolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.ToolBar_ButtonClick);
//
// ToolBarButtonFileNew
//
this.ToolBarButtonFileNew.ImageIndex = 0;
this.ToolBarButtonFileNew.ToolTipText = "New";
//
// ToolBarButtonViewRefresh
//
this.ToolBarButtonViewRefresh.ImageIndex = 1;
this.ToolBarButtonViewRefresh.ToolTipText = "Refresh";
//
// ImageList
//
this.ImageList.ImageSize = new System.Drawing.Size(16, 16);
this.ImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ImageList.ImageStream")));
this.ImageList.TransparentColor = System.Drawing.Color.Transparent;
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 20);
this.label1.TabIndex = 1;
this.label1.Text = "Count";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// TextBoxCount
//
this.TextBoxCount.Location = new System.Drawing.Point(72, 32);
this.TextBoxCount.Name = "TextBoxCount";
this.TextBoxCount.ReadOnly = true;
this.TextBoxCount.Size = new System.Drawing.Size(40, 20);
this.TextBoxCount.TabIndex = 2;
this.TextBoxCount.Text = "";
this.TextBoxCount.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// TextBoxTotal
//
this.TextBoxTotal.Location = new System.Drawing.Point(128, 32);
this.TextBoxTotal.Name = "TextBoxTotal";
this.TextBoxTotal.ReadOnly = true;
this.TextBoxTotal.Size = new System.Drawing.Size(40, 20);
this.TextBoxTotal.TabIndex = 4;
this.TextBoxTotal.Text = "";
this.TextBoxTotal.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label2
//
this.label2.Location = new System.Drawing.Point(112, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(16, 20);
this.label2.TabIndex = 3;
this.label2.Text = "/";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// ButtonDirectChildrenEnumerator
//
this.ButtonDirectChildrenEnumerator.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonDirectChildrenEnumerator.Location = new System.Drawing.Point(680, 504);
this.ButtonDirectChildrenEnumerator.Name = "ButtonDirectChildrenEnumerator";
this.ButtonDirectChildrenEnumerator.Size = new System.Drawing.Size(160, 23);
this.ButtonDirectChildrenEnumerator.TabIndex = 42;
this.ButtonDirectChildrenEnumerator.Text = "DirectChildren Enumerator";
this.ButtonDirectChildrenEnumerator.Click += new System.EventHandler(this.ButtonDirectChildrenEnumerator_Click);
//
// ButtonINodeEnumerator
//
this.ButtonINodeEnumerator.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonINodeEnumerator.Location = new System.Drawing.Point(680, 408);
this.ButtonINodeEnumerator.Name = "ButtonINodeEnumerator";
this.ButtonINodeEnumerator.Size = new System.Drawing.Size(160, 23);
this.ButtonINodeEnumerator.TabIndex = 39;
this.ButtonINodeEnumerator.Text = "INode Enumerator";
this.ButtonINodeEnumerator.Click += new System.EventHandler(this.ButtonINodeEnumerator_Click);
//
// ButtonITreeEnumerator
//
this.ButtonITreeEnumerator.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonITreeEnumerator.Location = new System.Drawing.Point(680, 440);
this.ButtonITreeEnumerator.Name = "ButtonITreeEnumerator";
this.ButtonITreeEnumerator.Size = new System.Drawing.Size(160, 23);
this.ButtonITreeEnumerator.TabIndex = 40;
this.ButtonITreeEnumerator.Text = "ITree Enumerator";
this.ButtonITreeEnumerator.Click += new System.EventHandler(this.ButtonITreeEnumerator_Click);
//
// ButtonInReverseEnumerator
//
this.ButtonInReverseEnumerator.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonInReverseEnumerator.Location = new System.Drawing.Point(680, 536);
this.ButtonInReverseEnumerator.Name = "ButtonInReverseEnumerator";
this.ButtonInReverseEnumerator.Size = new System.Drawing.Size(160, 23);
this.ButtonInReverseEnumerator.TabIndex = 43;
this.ButtonInReverseEnumerator.Text = "InReverse Enumerator";
this.ButtonInReverseEnumerator.Click += new System.EventHandler(this.ButtonInReverseEnumerator_Click);
//
// ButtonAllChildrenEnumerator
//
this.ButtonAllChildrenEnumerator.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonAllChildrenEnumerator.Location = new System.Drawing.Point(680, 472);
this.ButtonAllChildrenEnumerator.Name = "ButtonAllChildrenEnumerator";
this.ButtonAllChildrenEnumerator.Size = new System.Drawing.Size(160, 23);
this.ButtonAllChildrenEnumerator.TabIndex = 41;
this.ButtonAllChildrenEnumerator.Text = "AllChildren Enumerator";
this.ButtonAllChildrenEnumerator.Click += new System.EventHandler(this.ButtonAllChildrenEnumerator_Click);
//
// ButtonInsertChildTree
//
this.ButtonInsertChildTree.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonInsertChildTree.Location = new System.Drawing.Point(176, 312);
this.ButtonInsertChildTree.Name = "ButtonInsertChildTree";
this.ButtonInsertChildTree.Size = new System.Drawing.Size(160, 23);
this.ButtonInsertChildTree.TabIndex = 14;
this.ButtonInsertChildTree.Text = "Insert Child Tree";
this.ButtonInsertChildTree.Click += new System.EventHandler(this.ButtonInsertChildTree_Click);
//
// ButtonInsertNextTree
//
this.ButtonInsertNextTree.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonInsertNextTree.Location = new System.Drawing.Point(176, 280);
this.ButtonInsertNextTree.Name = "ButtonInsertNextTree";
this.ButtonInsertNextTree.Size = new System.Drawing.Size(160, 23);
this.ButtonInsertNextTree.TabIndex = 13;
this.ButtonInsertNextTree.Text = "Insert Next Tree";
this.ButtonInsertNextTree.Click += new System.EventHandler(this.ButtonInsertNextTree_Click);
//
// ButtonInsertPreviousTree
//
this.ButtonInsertPreviousTree.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonInsertPreviousTree.Location = new System.Drawing.Point(176, 248);
this.ButtonInsertPreviousTree.Name = "ButtonInsertPreviousTree";
this.ButtonInsertPreviousTree.Size = new System.Drawing.Size(160, 23);
this.ButtonInsertPreviousTree.TabIndex = 12;
this.ButtonInsertPreviousTree.Text = "Insert Previous Tree";
this.ButtonInsertPreviousTree.Click += new System.EventHandler(this.ButtonInsertPreviousTree_Click);
//
// ButtonInsertInteger
//
this.ButtonInsertInteger.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonInsertInteger.Location = new System.Drawing.Point(344, 56);
this.ButtonInsertInteger.Name = "ButtonInsertInteger";
this.ButtonInsertInteger.Size = new System.Drawing.Size(160, 23);
this.ButtonInsertInteger.TabIndex = 17;
this.ButtonInsertInteger.Text = "Insert Child Integer";
this.ButtonInsertInteger.Click += new System.EventHandler(this.ButtonInsertInteger_Click);
//
// ButtonInsertNode
//
this.ButtonInsertNode.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonInsertNode.Location = new System.Drawing.Point(344, 88);
this.ButtonInsertNode.Name = "ButtonInsertNode";
this.ButtonInsertNode.Size = new System.Drawing.Size(160, 23);
this.ButtonInsertNode.TabIndex = 18;
this.ButtonInsertNode.Text = "Insert Child Node";
this.ButtonInsertNode.Click += new System.EventHandler(this.ButtonInsertNode_Click);
//
// TreeViewClipboard
//
this.TreeViewClipboard.FullRowSelect = true;
this.TreeViewClipboard.HideSelection = false;
this.TreeViewClipboard.ImageIndex = -1;
this.TreeViewClipboard.Location = new System.Drawing.Point(680, 56);
this.TreeViewClipboard.Name = "TreeViewClipboard";
this.TreeViewClipboard.SelectedImageIndex = -1;
this.TreeViewClipboard.ShowRootLines = false;
this.TreeViewClipboard.Size = new System.Drawing.Size(160, 344);
this.TreeViewClipboard.TabIndex = 38;
//
// ButtonCut
//
this.ButtonCut.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonCut.Location = new System.Drawing.Point(512, 56);
this.ButtonCut.Name = "ButtonCut";
this.ButtonCut.Size = new System.Drawing.Size(160, 23);
this.ButtonCut.TabIndex = 21;
this.ButtonCut.Text = "Cut";
this.ButtonCut.Click += new System.EventHandler(this.ButtonCut_Click);
//
// ButtonCopy
//
this.ButtonCopy.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonCopy.Location = new System.Drawing.Point(512, 88);
this.ButtonCopy.Name = "ButtonCopy";
this.ButtonCopy.Size = new System.Drawing.Size(160, 23);
this.ButtonCopy.TabIndex = 22;
this.ButtonCopy.Text = "Copy";
this.ButtonCopy.Click += new System.EventHandler(this.ButtonCopy_Click);
//
// ButtonDeepCopy
//
this.ButtonDeepCopy.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonDeepCopy.Location = new System.Drawing.Point(512, 120);
this.ButtonDeepCopy.Name = "ButtonDeepCopy";
this.ButtonDeepCopy.Size = new System.Drawing.Size(160, 23);
this.ButtonDeepCopy.TabIndex = 23;
this.ButtonDeepCopy.Text = "Deep Copy";
this.ButtonDeepCopy.Click += new System.EventHandler(this.ButtonDeepCopy_Click);
//
// ButtonDelete
//
this.ButtonDelete.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonDelete.Location = new System.Drawing.Point(512, 152);
this.ButtonDelete.Name = "ButtonDelete";
this.ButtonDelete.Size = new System.Drawing.Size(160, 23);
this.ButtonDelete.TabIndex = 24;
this.ButtonDelete.Text = "Remove";
this.ButtonDelete.Click += new System.EventHandler(this.ButtonDelete_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(696, 32);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 20);
this.label3.TabIndex = 37;
this.label3.Text = "Clipboard";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// ButtonCopyObject
//
this.ButtonCopyObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonCopyObject.Location = new System.Drawing.Point(512, 312);
this.ButtonCopyObject.Name = "ButtonCopyObject";
this.ButtonCopyObject.Size = new System.Drawing.Size(160, 23);
this.ButtonCopyObject.TabIndex = 28;
this.ButtonCopyObject.Text = "Copy Object";
this.ButtonCopyObject.Click += new System.EventHandler(this.ButtonCopyObject_Click);
//
// ButtonDeepCopyObject
//
this.ButtonDeepCopyObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonDeepCopyObject.Location = new System.Drawing.Point(512, 344);
this.ButtonDeepCopyObject.Name = "ButtonDeepCopyObject";
this.ButtonDeepCopyObject.Size = new System.Drawing.Size(160, 23);
this.ButtonDeepCopyObject.TabIndex = 29;
this.ButtonDeepCopyObject.Text = "Deep Copy Object";
this.ButtonDeepCopyObject.Click += new System.EventHandler(this.ButtonDeepCopyObject_Click);
//
// ButtonCutObject
//
this.ButtonCutObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonCutObject.Location = new System.Drawing.Point(512, 280);
this.ButtonCutObject.Name = "ButtonCutObject";
this.ButtonCutObject.Size = new System.Drawing.Size(160, 23);
this.ButtonCutObject.TabIndex = 27;
this.ButtonCutObject.Text = "Cut Object";
this.ButtonCutObject.Click += new System.EventHandler(this.ButtonCutObject_Click);
//
// ButtonRemoveObject
//
this.ButtonRemoveObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonRemoveObject.Location = new System.Drawing.Point(512, 376);
this.ButtonRemoveObject.Name = "ButtonRemoveObject";
this.ButtonRemoveObject.Size = new System.Drawing.Size(160, 23);
this.ButtonRemoveObject.TabIndex = 30;
this.ButtonRemoveObject.Text = "Remove Object";
this.ButtonRemoveObject.Click += new System.EventHandler(this.ButtonRemoveObject_Click);
//
// ButtonContainsObject
//
this.ButtonContainsObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonContainsObject.Location = new System.Drawing.Point(512, 248);
this.ButtonContainsObject.Name = "ButtonContainsObject";
this.ButtonContainsObject.Size = new System.Drawing.Size(160, 23);
this.ButtonContainsObject.TabIndex = 26;
this.ButtonContainsObject.Text = "Contains Object";
this.ButtonContainsObject.Click += new System.EventHandler(this.ButtonContainsObject_Click);
//
// ButtonSetObject
//
this.ButtonSetObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonSetObject.Location = new System.Drawing.Point(512, 216);
this.ButtonSetObject.Name = "ButtonSetObject";
this.ButtonSetObject.Size = new System.Drawing.Size(160, 23);
this.ButtonSetObject.TabIndex = 25;
this.ButtonSetObject.Text = "Set Object";
this.ButtonSetObject.Click += new System.EventHandler(this.ButtonSetObject_Click);
//
// ButtonMoveToPrevious
//
this.ButtonMoveToPrevious.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonMoveToPrevious.Location = new System.Drawing.Point(512, 472);
this.ButtonMoveToPrevious.Name = "ButtonMoveToPrevious";
this.ButtonMoveToPrevious.Size = new System.Drawing.Size(160, 23);
this.ButtonMoveToPrevious.TabIndex = 32;
this.ButtonMoveToPrevious.Text = "Move To Previous";
this.ButtonMoveToPrevious.Click += new System.EventHandler(this.ButtonMoveToPrevious_Click);
//
// ButtonMoveToChild
//
this.ButtonMoveToChild.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonMoveToChild.Location = new System.Drawing.Point(512, 536);
this.ButtonMoveToChild.Name = "ButtonMoveToChild";
this.ButtonMoveToChild.Size = new System.Drawing.Size(160, 23);
this.ButtonMoveToChild.TabIndex = 34;
this.ButtonMoveToChild.Text = "Move To Child";
this.ButtonMoveToChild.Click += new System.EventHandler(this.ButtonMoveToChild_Click);
//
// ButtonMoveToNext
//
this.ButtonMoveToNext.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonMoveToNext.Location = new System.Drawing.Point(512, 504);
this.ButtonMoveToNext.Name = "ButtonMoveToNext";
this.ButtonMoveToNext.Size = new System.Drawing.Size(160, 23);
this.ButtonMoveToNext.TabIndex = 33;
this.ButtonMoveToNext.Text = "Move To Next";
this.ButtonMoveToNext.Click += new System.EventHandler(this.ButtonMoveToNext_Click);
//
// ButtonMoveToParent
//
this.ButtonMoveToParent.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonMoveToParent.Location = new System.Drawing.Point(512, 440);
this.ButtonMoveToParent.Name = "ButtonMoveToParent";
this.ButtonMoveToParent.Size = new System.Drawing.Size(160, 23);
this.ButtonMoveToParent.TabIndex = 31;
this.ButtonMoveToParent.Text = "Move To Parent";
this.ButtonMoveToParent.Click += new System.EventHandler(this.ButtonMoveToParent_Click);
//
// ButtonMoveToFirst
//
this.ButtonMoveToFirst.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonMoveToFirst.Location = new System.Drawing.Point(512, 568);
this.ButtonMoveToFirst.Name = "ButtonMoveToFirst";
this.ButtonMoveToFirst.Size = new System.Drawing.Size(160, 23);
this.ButtonMoveToFirst.TabIndex = 35;
this.ButtonMoveToFirst.Text = "Move To First";
this.ButtonMoveToFirst.Click += new System.EventHandler(this.ButtonMoveToFirst_Click);
//
// ButtonMoveToLast
//
this.ButtonMoveToLast.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonMoveToLast.Location = new System.Drawing.Point(512, 600);
this.ButtonMoveToLast.Name = "ButtonMoveToLast";
this.ButtonMoveToLast.Size = new System.Drawing.Size(160, 23);
this.ButtonMoveToLast.TabIndex = 36;
this.ButtonMoveToLast.Text = "Move To Last";
this.ButtonMoveToLast.Click += new System.EventHandler(this.ButtonMoveToLast_Click);
//
// ButtonAddTree
//
this.ButtonAddTree.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonAddTree.Location = new System.Drawing.Point(176, 344);
this.ButtonAddTree.Name = "ButtonAddTree";
this.ButtonAddTree.Size = new System.Drawing.Size(160, 23);
this.ButtonAddTree.TabIndex = 15;
this.ButtonAddTree.Text = "Add Tree";
this.ButtonAddTree.Click += new System.EventHandler(this.ButtonAddTree_Click);
//
// ButtonAddChildTree
//
this.ButtonAddChildTree.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonAddChildTree.Location = new System.Drawing.Point(176, 376);
this.ButtonAddChildTree.Name = "ButtonAddChildTree";
this.ButtonAddChildTree.Size = new System.Drawing.Size(160, 23);
this.ButtonAddChildTree.TabIndex = 16;
this.ButtonAddChildTree.Text = "Add Child Tree";
this.ButtonAddChildTree.Click += new System.EventHandler(this.ButtonAddChildTree_Click);
//
// ButtonAddObject
//
this.ButtonAddObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonAddObject.Location = new System.Drawing.Point(176, 152);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(160, 23);
this.ButtonAddObject.TabIndex = 10;
this.ButtonAddObject.Text = "Add Object";
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
//
// ButtonAddChildObject
//
this.ButtonAddChildObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonAddChildObject.Location = new System.Drawing.Point(176, 184);
this.ButtonAddChildObject.Name = "ButtonAddChildObject";
this.ButtonAddChildObject.Size = new System.Drawing.Size(160, 23);
this.ButtonAddChildObject.TabIndex = 11;
this.ButtonAddChildObject.Text = "Add Child Object";
this.ButtonAddChildObject.Click += new System.EventHandler(this.ButtonAddChildObject_Click);
//
// ButtonInsertChildObject
//
this.ButtonInsertChildObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonInsertChildObject.Location = new System.Drawing.Point(176, 120);
this.ButtonInsertChildObject.Name = "ButtonInsertChildObject";
this.ButtonInsertChildObject.Size = new System.Drawing.Size(160, 23);
this.ButtonInsertChildObject.TabIndex = 9;
this.ButtonInsertChildObject.Text = "Insert Child Object";
this.ButtonInsertChildObject.Click += new System.EventHandler(this.ButtonInsertChildObject_Click);
//
// ButtonInsertNextObject
//
this.ButtonInsertNextObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonInsertNextObject.Location = new System.Drawing.Point(176, 88);
this.ButtonInsertNextObject.Name = "ButtonInsertNextObject";
this.ButtonInsertNextObject.Size = new System.Drawing.Size(160, 23);
this.ButtonInsertNextObject.TabIndex = 8;
this.ButtonInsertNextObject.Text = "Insert Next Object";
this.ButtonInsertNextObject.Click += new System.EventHandler(this.ButtonInsertNextObject_Click);
//
// ButtonInsertPreviousObject
//
this.ButtonInsertPreviousObject.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonInsertPreviousObject.Location = new System.Drawing.Point(176, 56);
this.ButtonInsertPreviousObject.Name = "ButtonInsertPreviousObject";
this.ButtonInsertPreviousObject.Size = new System.Drawing.Size(160, 23);
this.ButtonInsertPreviousObject.TabIndex = 7;
this.ButtonInsertPreviousObject.Text = "Insert Previous Object";
this.ButtonInsertPreviousObject.Click += new System.EventHandler(this.ButtonInsertPreviousObject_Click);
//
// ButtonCopyToArray
//
this.ButtonCopyToArray.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonCopyToArray.Location = new System.Drawing.Point(680, 600);
this.ButtonCopyToArray.Name = "ButtonCopyToArray";
this.ButtonCopyToArray.Size = new System.Drawing.Size(160, 23);
this.ButtonCopyToArray.TabIndex = 44;
this.ButtonCopyToArray.Text = "Copy To Array";
this.ButtonCopyToArray.Click += new System.EventHandler(this.ButtonCopyToArray_Click);
//
// TextBoxHandlers
//
this.TextBoxHandlers.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.TextBoxHandlers.Location = new System.Drawing.Point(8, 408);
this.TextBoxHandlers.Multiline = true;
this.TextBoxHandlers.Name = "TextBoxHandlers";
this.TextBoxHandlers.ReadOnly = true;
this.TextBoxHandlers.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.TextBoxHandlers.Size = new System.Drawing.Size(496, 216);
this.TextBoxHandlers.TabIndex = 6;
this.TextBoxHandlers.Text = "";
this.TextBoxHandlers.WordWrap = false;
this.TextBoxHandlers.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TextBoxHandlers_KeyDown);
this.TextBoxHandlers.DoubleClick += new System.EventHandler(this.TextBoxHandlers_DoubleClick);
//
// ButtonSetData
//
this.ButtonSetData.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonSetData.Location = new System.Drawing.Point(344, 152);
this.ButtonSetData.Name = "ButtonSetData";
this.ButtonSetData.Size = new System.Drawing.Size(160, 23);
this.ButtonSetData.TabIndex = 19;
this.ButtonSetData.Text = "Set Data";
this.ButtonSetData.Click += new System.EventHandler(this.ButtonSetData_Click);
//
// ButtonClear
//
this.ButtonClear.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.ButtonClear.Location = new System.Drawing.Point(344, 216);
this.ButtonClear.Name = "ButtonClear";
this.ButtonClear.Size = new System.Drawing.Size(160, 23);
this.ButtonClear.TabIndex = 20;
this.ButtonClear.Text = "Clear";
this.ButtonClear.Click += new System.EventHandler(this.ButtonClear_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(848, 636);
this.Controls.Add(this.TextBoxHandlers);
this.Controls.Add(this.ButtonDirectChildrenEnumerator);
this.Controls.Add(this.TextBoxCount);
this.Controls.Add(this.label1);
this.Controls.Add(this.TreeView);
this.Controls.Add(this.ToolBar);
this.Controls.Add(this.TextBoxTotal);
this.Controls.Add(this.label2);
this.Controls.Add(this.ButtonINodeEnumerator);
this.Controls.Add(this.ButtonITreeEnumerator);
this.Controls.Add(this.ButtonInReverseEnumerator);
this.Controls.Add(this.ButtonAllChildrenEnumerator);
this.Controls.Add(this.ButtonInsertChildTree);
this.Controls.Add(this.ButtonInsertNextTree);
this.Controls.Add(this.ButtonInsertPreviousTree);
this.Controls.Add(this.ButtonInsertInteger);
this.Controls.Add(this.ButtonInsertNode);
this.Controls.Add(this.TreeViewClipboard);
this.Controls.Add(this.ButtonCut);
this.Controls.Add(this.ButtonCopy);
this.Controls.Add(this.ButtonDeepCopy);
this.Controls.Add(this.ButtonDelete);
this.Controls.Add(this.label3);
this.Controls.Add(this.ButtonCopyObject);
this.Controls.Add(this.ButtonDeepCopyObject);
this.Controls.Add(this.ButtonCutObject);
this.Controls.Add(this.ButtonRemoveObject);
this.Controls.Add(this.ButtonContainsObject);
this.Controls.Add(this.ButtonSetObject);
this.Controls.Add(this.ButtonMoveToPrevious);
this.Controls.Add(this.ButtonMoveToChild);
this.Controls.Add(this.ButtonMoveToNext);
this.Controls.Add(this.ButtonMoveToParent);
this.Controls.Add(this.ButtonMoveToFirst);
this.Controls.Add(this.ButtonMoveToLast);
this.Controls.Add(this.ButtonAddTree);
this.Controls.Add(this.ButtonAddChildTree);
this.Controls.Add(this.ButtonAddObject);
this.Controls.Add(this.ButtonAddChildObject);
this.Controls.Add(this.ButtonInsertChildObject);
this.Controls.Add(this.ButtonInsertNextObject);
this.Controls.Add(this.ButtonInsertPreviousObject);
this.Controls.Add(this.ButtonCopyToArray);
this.Controls.Add(this.ButtonSetData);
this.Controls.Add(this.ButtonClear);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Tree Test";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.DoEvents();
Application.Run( new Form1() );
}
//-----------------------------------------------------------------------------
private void ToolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if ( e.Button == ToolBarButtonFileNew ) OnFileNew ();
if ( e.Button == ToolBarButtonViewRefresh ) OnViewRefresh ();
}
//-----------------------------------------------------------------------------
private void OnFileNew()
{
tree.Clear();
while ( tree.Count < 10 )
{
tree.Clear();
TextBoxHandlers.Clear();
AddNodes( tree.Root, "", 0 );
}
OnViewRefresh();
}
private static Random Random = new Random();
private void AddNodes( INode parent, string sParent, int iDepth )
{
if ( iDepth > 3 ) return;
for ( int i = 0 ; Random.Next( 10 ) < 5 ; i++ )
{
string s = sParent + i;
INode child = parent.AddChild( new Element( s ) );
child.Validate += new NodeTreeDataEventHandler ( Node_Validate );
// child.Validate += new NodeTreeDataEventHandler ( Node_Validate );
// child.Clearing += new EventHandler ( Node_Clearing );
// child.Cleared += new EventHandler ( Node_Cleared );
child.Setting += new NodeTreeDataEventHandler ( Node_Setting );
child.SetDone += new NodeTreeDataEventHandler ( Node_SetDone );
child.Inserting += new NodeTreeInsertEventHandler ( Node_Inserting );
child.Inserted += new NodeTreeInsertEventHandler ( Node_Inserted );
child.Cutting += new EventHandler ( Node_Cutting );
child.CutDone += new EventHandler ( Node_CutDone );
child.Copying += new NodeTreeNodeEventHandler ( Node_Copying );
child.Copied += new NodeTreeNodeEventHandler ( Node_Copied );
child.DeepCopying += new NodeTreeNodeEventHandler ( Node_DeepCopying );
child.DeepCopied += new NodeTreeNodeEventHandler ( Node_DeepCopied );
AddNodes( child, s, iDepth + 1 );
}
}
private void OnViewRefresh()
{
TextBoxTotal.Text = tree.Count.ToString( CultureInfo.CurrentUICulture );
FillTreeView( TreeView, tree );
FillTreeView( TreeViewClipboard, treeClipboard );
}
private class TreeViewUpdate : IDisposable
{
private TreeView TreeView = null;
public TreeViewUpdate( TreeView TreeView )
{
this.TreeView = TreeView;
TreeView.BeginUpdate();
}
public void Dispose()
{
TreeView.EndUpdate();
}
}
private void FillTreeView( TreeView TreeView, ITree tree )
{
object oSelected = null;
if ( TreeView.SelectedNode != null ) oSelected = TreeView.SelectedNode.Tag;
using ( new TreeViewUpdate( TreeView ) )
{
TreeView.Nodes.Clear();
if ( tree == null ) return;
TreeNode Root = TreeView.Nodes.Add( tree.Root.ToString() );
Root.Tag = tree.Root;
TreeNode nSelected = AddNodes( Root.Nodes, tree.Root, oSelected );
TreeView.ExpandAll();
if ( nSelected != null )
TreeView.SelectedNode = nSelected;
else
if ( TreeView.Nodes.Count > 0 )
TreeView.SelectedNode = TreeView.Nodes[ 0 ];
}
}
private TreeNode AddNodes( TreeNodeCollection nodes, INode parent, object oSelected )
{
TreeNode nSelected = null;
foreach ( INode child in parent.DirectChildren )
// for ( INode child = parent.child ; child != null ; child = child.next )
{
TreeNode node = nodes.Add( child.ToString() );
node.Tag = child;
if ( child == oSelected ) nSelected = node;
TreeNode n = AddNodes( node.Nodes, child, oSelected );
if ( n != null ) nSelected = n;
}
return nSelected;
}
private void TreeView_AfterSelect( object sender, System.Windows.Forms.TreeViewEventArgs e )
{
INode n = e.Node.Tag as INode;
TextBoxCount.Text = ( n == null ) ? "NULL" : n.Count.ToString( CultureInfo.CurrentUICulture );
}
//-----------------------------------------------------------------------------
private void TextBoxHandlers_KeyDown( object sender, System.Windows.Forms.KeyEventArgs e )
{
if ( e.KeyCode == Keys.Delete ) TextBoxHandlers.Clear();
if ( e.KeyCode == Keys.Back ) TextBoxHandlers.Clear();
}
private void TextBoxHandlers_DoubleClick( object sender, System.EventArgs e )
{
TextBoxHandlers.Clear();
}
//-----------------------------------------------------------------------------
private void Tree_Validate( object sender, NodeTreeDataEventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : Validate : " + e.Data + "\r\n";
}
private void Tree_Clearing( object sender, EventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : Clearing\r\n";
}
private void Tree_Cleared( object sender, EventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : Cleared\r\n";
}
private void Tree_Setting( object sender, NodeTreeDataEventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : Setting : " + e.Data + "\r\n";
}
private void Tree_SetDone( object sender, NodeTreeDataEventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : SetDone : " + e.Data + "\r\n";
}
private void Tree_Inserting( object sender, NodeTreeInsertEventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : Inserting " + e.Operation + " : " + e.Node + "\r\n";
}
private void Tree_Inserted( object sender, NodeTreeInsertEventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : Inserted " + e.Operation + " : " + e.Node + "\r\n";
}
private void Tree_Cutting( object sender, EventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : Cutting\r\n";
}
private void Tree_CutDone( object sender, EventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : CutDone\r\n";
}
private void Tree_Copying( object sender, NodeTreeNodeEventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : Copying : " + e.Node + "\r\n";
}
private void Tree_Copied( object sender, NodeTreeNodeEventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : Copied : " + e.Node + "\r\n";
}
private void Tree_DeepCopying( object sender, NodeTreeNodeEventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : DeepCopying : " + e.Node + "\r\n";
}
private void Tree_DeepCopied( object sender, NodeTreeNodeEventArgs e )
{
TextBoxHandlers.Text += "Tree: " + sender + " : DeepCopied : " + e.Node + "\r\n";
}
//-----------------------------------------------------------------------------
private void Node_Validate( object sender, NodeTreeDataEventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : Validate : " + e.Data + "\r\n";
}
/*
private void Node_Clearing( object sender, EventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : Clearing\r\n";
}
private void Node_Cleared( object sender, EventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : Cleared\r\n";
}
*/
private void Node_Setting( object sender, NodeTreeDataEventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : Setting : " + e.Data + "\r\n";
}
private void Node_SetDone( object sender, NodeTreeDataEventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : SetDone : " + e.Data + "\r\n";
}
private void Node_Inserting( object sender, NodeTreeInsertEventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : Inserting " + e.Operation + " : " + e.Node + "\r\n";
}
private void Node_Inserted( object sender, NodeTreeInsertEventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : Inserted " + e.Operation + " : " + e.Node + "\r\n";
}
private void Node_Cutting( object sender, EventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : Cutting\r\n";
}
private void Node_CutDone( object sender, EventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : CutDone\r\n";
}
private void Node_Copying( object sender, NodeTreeNodeEventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : Copying : " + e.Node + "\r\n";
}
private void Node_Copied( object sender, NodeTreeNodeEventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : Copied : " + e.Node + "\r\n";
}
private void Node_DeepCopying( object sender, NodeTreeNodeEventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : DeepCopying : " + e.Node + "\r\n";
}
private void Node_DeepCopied( object sender, NodeTreeNodeEventArgs e )
{
TextBoxHandlers.Text += "Node: " + sender + " : DeepCopied : " + e.Node + "\r\n";
}
//-----------------------------------------------------------------------------
private object CreateLittleObject()
{
return new Element( "New Element" );
}
private void ButtonInsertPreviousObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.InsertPrevious( CreateLittleObject() );
OnViewRefresh();
}
private void ButtonInsertNextObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.InsertNext( CreateLittleObject() );
OnViewRefresh();
}
private void ButtonInsertChildObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.InsertChild( CreateLittleObject() );
OnViewRefresh();
}
private void ButtonAddObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.Add( CreateLittleObject() );
OnViewRefresh();
}
private void ButtonAddChildObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.AddChild( CreateLittleObject() );
OnViewRefresh();
}
//-----------------------------------------------------------------------------
private ITree CreateLittleTree()
{
ITree t = NodeTree.NewTree();
t.AddChild( new Element( "New node 1" ) );
t.AddChild( new Element( "New node 2" ) )
.AddChild( new Element( "New node 21" ) )
.InsertNext( new Element( "New node 22" ) )
.AddChild( new Element( "New node 221" ) );
return t;
}
private void ButtonInsertPreviousTree_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.InsertPrevious( CreateLittleTree() );
OnViewRefresh();
}
private void ButtonInsertNextTree_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.InsertNext( CreateLittleTree() );
OnViewRefresh();
}
private void ButtonInsertChildTree_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.InsertChild( CreateLittleTree() );
OnViewRefresh();
}
private void ButtonAddTree_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.Add( CreateLittleTree() );
OnViewRefresh();
}
private void ButtonAddChildTree_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.AddChild( CreateLittleTree() );
OnViewRefresh();
}
//-----------------------------------------------------------------------------
private void ButtonInsertInteger_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
ITree t = NodeTree.NewTree();
t.AddChild( 42 );
n.InsertChild( t );
OnViewRefresh();
}
private void ButtonInsertNode_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
ITree t = NodeTree.NewTree();
INode NewNode = t.AddChild( "NewNode" );
n.InsertChild( NewNode );
OnViewRefresh();
}
//-----------------------------------------------------------------------------
private void ButtonINodeEnumerator_Click(object sender, System.EventArgs e)
{
INode parent = TreeView.SelectedNode.Tag as INode;
if ( parent == null ) return;
string s = parent + " :\n\n";
foreach ( INode child in parent )
s += child + "\n";
MessageBox.Show( s, "Tree Test" );
}
private void ButtonITreeEnumerator_Click(object sender, System.EventArgs e)
{
INode parent = TreeView.SelectedNode.Tag as INode;
if ( parent == null ) return;
ITree tree = parent.Tree;
string s = tree + " :\n\n";
foreach ( INode child in tree )
s += child + "\n";
MessageBox.Show( s, "Tree Test" );
}
private void ButtonAllChildrenEnumerator_Click(object sender, System.EventArgs e)
{
INode parent = TreeView.SelectedNode.Tag as INode;
if ( parent == null ) return;
string s = parent + " :\n\n";
foreach ( INode child in parent.AllChildren )
s += child + "\n";
MessageBox.Show( s, "Tree Test" );
}
private void ButtonDirectChildrenEnumerator_Click( object sender, System.EventArgs e )
{
INode parent = TreeView.SelectedNode.Tag as INode;
if ( parent == null ) return;
string s = parent + " :\n\n";
foreach ( INode child in parent.DirectChildren )
s += child + "\n";
MessageBox.Show( s, "Tree Test" );
}
private void ButtonInReverseEnumerator_Click(object sender, System.EventArgs e)
{
INode parent = TreeView.SelectedNode.Tag as INode;
if ( parent == null ) return;
string s = parent + " :\n\n";
foreach ( INode child in parent.DirectChildrenInReverse )
s += child + "\n";
MessageBox.Show( s, "Tree Test" );
}
//-----------------------------------------------------------------------------
private void ButtonCopyToArray_Click( object sender, System.EventArgs e )
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
Element[] a = new Element[ n.Count ];
n.CopyTo( a, 0 );
string s = n + " :\n\n";
foreach ( Element o in a )
s += o + "\n";
MessageBox.Show( s );
}
//-----------------------------------------------------------------------------
private void ButtonCut_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
treeClipboard = n.Cut();
OnViewRefresh();
}
private void ButtonCopy_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
treeClipboard = n.Copy();
OnViewRefresh();
}
private void ButtonDeepCopy_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
treeClipboard = n.DeepCopy();
OnViewRefresh();
}
private void ButtonDelete_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.Remove();
OnViewRefresh();
}
//-----------------------------------------------------------------------------
private void ButtonSetObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
oSetObject = n.Data;
}
private void ButtonContainsObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
if ( n.Contains( oSetObject ) )
MessageBox.Show( "Node contains object", "Tree Test" );
else
MessageBox.Show( "Node does not contain object", "Tree Test" );
}
private void ButtonCutObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
treeClipboard = n.Cut( oSetObject );
OnViewRefresh();
}
private void ButtonCopyObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
treeClipboard = n.Copy( oSetObject );
OnViewRefresh();
}
private void ButtonDeepCopyObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
treeClipboard = n.DeepCopy( oSetObject );
OnViewRefresh();
}
private void ButtonRemoveObject_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.Remove( oSetObject );
OnViewRefresh();
}
//-----------------------------------------------------------------------------
private void ButtonMoveToParent_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.MoveToParent();
OnViewRefresh();
}
private void ButtonMoveToPrevious_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.MoveToPrevious();
OnViewRefresh();
}
private void ButtonMoveToNext_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.MoveToNext();
OnViewRefresh();
}
private void ButtonMoveToChild_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.MoveToChild();
OnViewRefresh();
}
private void ButtonMoveToFirst_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.MoveToFirst();
OnViewRefresh();
}
private void ButtonMoveToLast_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.MoveToLast();
OnViewRefresh();
}
private void ButtonSetData_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
n.Data = new Element( "Element" );
OnViewRefresh();
}
private void ButtonClear_Click(object sender, System.EventArgs e)
{
INode n = TreeView.SelectedNode.Tag as INode;
if ( n == null ) return;
( (NodeTree) n ).Clear();
OnViewRefresh();
}
//-----------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------
internal class Element //: IDeepCopy
{
private string _data = null;
public Element( string s )
{
_data = s;
}
#if true
public Element( Element o )
{
_data = o._data + " *COPYCTOR*";
}
#endif
public override string ToString()
{
return _data;
}
public object CreateDeepCopy()
{
return new Element( _data + " *DEEPCOPY*" );
}
}
//-----------------------------------------------------------------------------
}