private void deleteNode_Click(object sender, EventArgs e) { if (parent == null) { return; } TTNode current = parent.find(focusedTextbox); if (current == parent) { clearAll_Click(sender, e); return; } /*foreach (LineShape line in panel1.Controls.OfType<LineShape>()) * { * line.Dispose(); * } * * foreach (ShapeCollection shp in panel1.Controls.OfType<ShapeCollection>()) * { * shp.Clear(); * shp.Dispose(); * } * parent.drawLines(); * drawLines(parent); * if (current != null) * current.delete(); * checkboxes.Clear(); * foreach (CheckBox chk in this.panel1.Controls.OfType<CheckBox>()) * { * checkboxes.Add(chk); * }*/ }
private void clearAll_Click(object sender, EventArgs e) { panel1.Controls.Clear(); clicked = false; parent = null; checkOffCount = 0; }
public string toTextFile(TTNode p) { string now = DateTime.Now.ToString("M-d-yy_H-mm"); string fileName = "tree_" + now + ".txt"; List <string> lines = new List <string>(); System.IO.File.WriteAllLines(@fileName, lines); return(fileName); }
private void levelButton_Click(object sender, EventArgs e) { TextBox txtDown = new TextBox(); txtDown.Name = "txtDown"; txtDown.Size = new System.Drawing.Size(80, 25); txtDown.GotFocus += textBox_Enter; txtDown.KeyPress += textBox_KeyPress; txtDown.Tag = "C"; TTNode down = new TTNode(txtDown); if (!clicked) { parent = down; down.x = 370; down.y = 10; clicked = true; txtDown.Location = new System.Drawing.Point(parent.x, parent.y); parent.level = 1; } else if (focusedTextbox != null) { TTNode p = parent.find(focusedTextbox); down.parent = p; p.addChild(down); parent.reposition(); txtDown.Location = new System.Drawing.Point(down.x, down.y); parent.drawLines(); drawLines(p); } panel1.Controls.Add(txtDown); //create corresponding checkbox CheckBox chkDown = new CheckBox(); chkDown.Location = new System.Drawing.Point(down.x + 87, down.y + 3); chkDown.Tag = down; chkDown.Size = new System.Drawing.Size(15, 15); // panel1.Controls.Add(chkDown); panel1.Controls.Add(chkDown); down.cb = chkDown; checkboxes.Add(chkDown); focusedTextbox = txtDown; down.state = "Decomp"; if (down.parent != null) { down.level = down.parent.level + 1; } }
private void drawLines(TTNode current) { ShapeContainer canvas = new ShapeContainer(); foreach (LineShape line in current.linesToChildren) { canvas.Parent = panel1; line.Parent = canvas; } foreach (TTNode child in current.children) { drawLines(child); } }
private void delete(TTNode current) { if (current != null) { foreach (LineShape line in current.linesToChildren) { line.Dispose(); } current.linesToChildren.Clear(); if (current.parent != null) { current.parent.children.Clear(); } current.delete(); } }
private void premiseButton_Click(object sender, EventArgs e) { TextBox txtPremise = new TextBox(); txtPremise.Name = "premise"; txtPremise.Size = new System.Drawing.Size(80, 25); txtPremise.GotFocus += textBox_Enter; txtPremise.KeyPress += textBox_KeyPress; txtPremise.Tag = "P"; TTNode premise = new TTNode(txtPremise); if (!clicked) { parent = premise; parent.x = 370; parent.y = 10; clicked = true; txtPremise.Location = new System.Drawing.Point(parent.x, parent.y); } else if (focusedTextbox != null) { TTNode p = parent.find(focusedTextbox); premise.parent = p; p.addChild(premise); parent.reposition(); txtPremise.Location = new System.Drawing.Point(premise.x, premise.y); parent.lineRef = 0; parent.level = 1; } panel1.Controls.Add(txtPremise); //create corresponding checkbox CheckBox chkPremise = new CheckBox(); chkPremise.Location = new System.Drawing.Point(premise.x + 87, premise.y + 3); chkPremise.Tag = premise; chkPremise.Size = new System.Drawing.Size(15, 15); panel1.Controls.Add(chkPremise); premise.cb = chkPremise; checkboxes.Add(chkPremise); focusedTextbox = txtPremise; premise.state = "Premise"; if (premise.parent != null) { premise.level = premise.parent.level + 1; } }
public TTNode find(TextBox target) { if (this.tb == target) { return(this); } foreach (TTNode child in children) { TTNode result = child.find(target); if (result != null) { return(result); } } return(null); }
private void openButton_Click(object sender, EventArgs e) { checkOffCount++; Label openBranch = new Label(); openBranch.Text = "O" + checkOffCount; openBranch.Location = new System.Drawing.Point(focusedTextbox.Location.X + 30, focusedTextbox.Location.Y + 25); openBranch.ForeColor = Color.Orange; Font font = new Font("Calibri", 10.0f, FontStyle.Bold); openBranch.Font = font; panel1.Controls.Add(openBranch); TTNode current = parent.find(focusedTextbox); current.state = "Open"; openBranch.Size = new System.Drawing.Size(30, 25); }
public TTNode(TextBox _tb, TTNode _parent = null) { parent = _parent; tb = _tb; children = new List <TTNode>(); x = _tb.Location.X; y = _tb.Location.Y; linesToChildren = new List <LineShape>(); if (_parent == null) { level = 1; } else { level += parent.level + 1; } siblingDeleted = false; lineRef = 0; }
public void addChild(TTNode child) { children.Add(child); }
private void verifyButton_Click(object sender, EventArgs e) { List <string> toVerify = new List <string>(); List <CheckBox> checkedboxes = new List <CheckBox>(); int ghettoCount = 0; string ruleType = ""; foreach (CheckBox chk in checkboxes) { if (chk.Checked) { TTNode t = chk.Tag as TTNode; if (t != null) { toVerify.Add(t.ToString()); if (ghettoCount == 1) { string type = t.tb.Tag.ToString(); if (type == "C" || type == "P") { ruleType = "D"; } else { ruleType = "B"; } } ghettoCount++; } checkedboxes.Add(chk); } } if (checkedboxes.Count == 5) { ruleType = "BI"; toVerify = rearrange(toVerify); } toVerify.Add(ruleType); for (int i = 0; i < toVerify.Count; i++) { toVerify[i] = replaceSymbols(toVerify[i]); } if (verifySentences(toVerify)) { foreach (Label label in panel1.Controls.OfType <Label>()) { if (label.Text == "failed") { label.Dispose(); } } checkOffCount++; Label verifyBranch = new Label(); verifyBranch.Text = "✓" + checkOffCount; verifyBranch.Location = new System.Drawing.Point(checkedboxes[0].Location.X + 15, checkedboxes[0].Location.Y - 3); verifyBranch.ForeColor = Color.Green; Font font = new Font("Calibri", 10.0f, FontStyle.Bold); verifyBranch.Font = font; panel1.Controls.Add(verifyBranch); } else { Label incorrect = new Label(); incorrect.Text = "failed"; incorrect.Location = new System.Drawing.Point(checkedboxes[0].Location.X + 15, checkedboxes[0].Location.Y - 3); incorrect.ForeColor = Color.Red; Font font = new Font("Calibri", 10.0f, FontStyle.Bold); incorrect.Font = font; panel1.Controls.Add(incorrect); } foreach (CheckBox chk in panel1.Controls.OfType <CheckBox>()) { chk.Checked = false; } }
private void branchButton_Click(object sender, EventArgs e) { if (focusedTextbox == null) { return; } TextBox txtRight = new TextBox(); TextBox txtLeft = new TextBox(); txtLeft.Name = "txtLeft"; txtRight.Name = "txtRight"; txtRight.Size = new System.Drawing.Size(80, 25); txtLeft.Size = new System.Drawing.Size(80, 25); txtRight.GotFocus += textBox_Enter; txtRight.KeyPress += textBox_KeyPress; txtLeft.GotFocus += textBox_Enter; txtLeft.KeyPress += textBox_KeyPress; txtRight.Tag = "R"; txtLeft.Tag = "L"; panel1.Controls.Add(txtRight); panel1.Controls.Add(txtLeft); TTNode left = new TTNode(txtLeft); TTNode right = new TTNode(txtRight); left.sibling = right; right.sibling = left; if (focusedTextbox != null) { TTNode p = parent.find(focusedTextbox); left.parent = p; right.parent = p; p.addChild(left); p.addChild(right); p.reposition(); txtRight.Location = new System.Drawing.Point(right.x, right.y); txtLeft.Location = new System.Drawing.Point(left.x, left.y); parent.drawLines(); drawLines(p); } //create corresponding checkboxes CheckBox chkRight = new CheckBox(); CheckBox chkLeft = new CheckBox(); chkRight.Location = new System.Drawing.Point(right.x + 87, right.y + 3); chkLeft.Location = new System.Drawing.Point(left.x + 87, left.y + 3); chkLeft.Size = new System.Drawing.Size(10, 10); chkRight.Tag = right; chkLeft.Tag = left; chkRight.Size = new System.Drawing.Size(15, 15); chkLeft.Size = new System.Drawing.Size(15, 15); panel1.Controls.Add(chkRight); panel1.Controls.Add(chkLeft); right.cb = chkRight; left.cb = chkLeft; checkboxes.Add(chkRight); checkboxes.Add(chkLeft); focusedTextbox = txtRight; right.state = "Branch"; left.state = "Branch"; right.level = right.parent.level + 1; left.level = left.parent.level + 1; }