Changeset 8980 for trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs
- Timestamp:
- 11/30/12 23:15:47 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs
- Files:
-
- 2 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeConstantNodeEditDialog.Designer.cs
r8950 r8980 21 21 22 22 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 23 partial class ValueChangeDialog {23 partial class ConstantNodeEditDialog { 24 24 /// <summary> 25 25 /// Required designer variable. … … 51 51 this.newValueLabel = new System.Windows.Forms.Label(); 52 52 this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components); 53 this.variableNameLabel = new System.Windows.Forms.Label();54 this.variableNamesCombo = new System.Windows.Forms.ComboBox();55 53 this.okButton = new System.Windows.Forms.Button(); 56 54 this.cancelButton = new System.Windows.Forms.Button(); … … 61 59 // 62 60 this.originalValueLabel.AutoSize = true; 63 this.originalValueLabel.Location = new System.Drawing.Point(12, 45);61 this.originalValueLabel.Location = new System.Drawing.Point(12, 9); 64 62 this.originalValueLabel.Name = "originalValueLabel"; 65 63 this.originalValueLabel.Size = new System.Drawing.Size(72, 13); … … 69 67 // oldValueTextBox 70 68 // 71 this.oldValueTextBox.Location = new System.Drawing.Point(123, 42);69 this.oldValueTextBox.Location = new System.Drawing.Point(123, 6); 72 70 this.oldValueTextBox.Name = "oldValueTextBox"; 73 71 this.oldValueTextBox.ReadOnly = true; … … 77 75 // newValueTextBox 78 76 // 79 this.newValueTextBox.Location = new System.Drawing.Point(123, 82);77 this.newValueTextBox.Location = new System.Drawing.Point(123, 42); 80 78 this.newValueTextBox.Name = "newValueTextBox"; 81 79 this.newValueTextBox.Size = new System.Drawing.Size(131, 20); … … 88 86 // 89 87 this.newValueLabel.AutoSize = true; 90 this.newValueLabel.Location = new System.Drawing.Point(12, 85);88 this.newValueLabel.Location = new System.Drawing.Point(12, 45); 91 89 this.newValueLabel.Name = "newValueLabel"; 92 90 this.newValueLabel.Size = new System.Drawing.Size(59, 13); … … 100 98 this.errorProvider.RightToLeft = true; 101 99 // 102 // variableNameLabel103 //104 this.variableNameLabel.AutoSize = true;105 this.variableNameLabel.Location = new System.Drawing.Point(12, 7);106 this.variableNameLabel.Name = "variableNameLabel";107 this.variableNameLabel.Size = new System.Drawing.Size(76, 13);108 this.variableNameLabel.TabIndex = 6;109 this.variableNameLabel.Text = "Variable Name";110 this.variableNameLabel.Visible = false;111 //112 // variableNamesCombo113 //114 this.variableNamesCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;115 this.variableNamesCombo.FormattingEnabled = true;116 this.variableNamesCombo.Location = new System.Drawing.Point(123, 4);117 this.variableNamesCombo.Name = "variableNamesCombo";118 this.variableNamesCombo.Size = new System.Drawing.Size(131, 21);119 this.variableNamesCombo.TabIndex = 7;120 this.variableNamesCombo.Visible = false;121 this.variableNamesCombo.KeyDown += new System.Windows.Forms.KeyEventHandler(this.childControl_KeyDown);122 this.variableNamesCombo.Validating += new System.ComponentModel.CancelEventHandler(this.variableNamesCombo_Validating);123 this.variableNamesCombo.Validated += new System.EventHandler(this.variableNamesCombo_Validated);124 //125 100 // okButton 126 101 // 127 this.okButton.Location = new System.Drawing.Point(15, 119); 102 this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; 103 this.okButton.Location = new System.Drawing.Point(15, 79); 128 104 this.okButton.Name = "okButton"; 129 105 this.okButton.Size = new System.Drawing.Size(75, 23); … … 137 113 this.cancelButton.CausesValidation = false; 138 114 this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; 139 this.cancelButton.Location = new System.Drawing.Point(179, 119);115 this.cancelButton.Location = new System.Drawing.Point(179, 79); 140 116 this.cancelButton.Name = "cancelButton"; 141 117 this.cancelButton.Size = new System.Drawing.Size(75, 23); … … 145 121 this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); 146 122 // 147 // ValueChangeDialog123 // ConstantNodeEditDialog 148 124 // 149 125 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); … … 151 127 this.AutoSize = true; 152 128 this.CancelButton = this.cancelButton; 153 this.ClientSize = new System.Drawing.Size(269, 1 54);129 this.ClientSize = new System.Drawing.Size(269, 116); 154 130 this.ControlBox = false; 155 131 this.Controls.Add(this.cancelButton); 156 132 this.Controls.Add(this.okButton); 157 this.Controls.Add(this.variableNamesCombo);158 this.Controls.Add(this.variableNameLabel);159 133 this.Controls.Add(this.newValueLabel); 160 134 this.Controls.Add(this.newValueTextBox); … … 164 138 this.MaximizeBox = false; 165 139 this.MinimizeBox = false; 166 this.Name = " ValueChangeDialog";140 this.Name = "ConstantNodeEditDialog"; 167 141 this.ShowIcon = false; 168 142 this.ShowInTaskbar = false; 169 143 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 170 this.Text = " Change Value or Weight";171 this.KeyDown += new System.Windows.Forms.KeyEventHandler(this. ValueChangeDialog_KeyDown);144 this.Text = "Edit constant value"; 145 this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ConstantNodeEditDialog_KeyDown); 172 146 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 173 147 this.ResumeLayout(false); … … 182 156 private System.Windows.Forms.Label newValueLabel; 183 157 private System.Windows.Forms.ErrorProvider errorProvider; 184 private System.Windows.Forms.Label variableNameLabel;185 158 private System.Windows.Forms.Button cancelButton; 186 159 private System.Windows.Forms.Button okButton; 187 160 public System.Windows.Forms.TextBox newValueTextBox; 188 public System.Windows.Forms.ComboBox variableNamesCombo;189 161 } 190 162 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeConstantNodeEditDialog.cs
r8950 r8980 28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 30 public partial class ValueChangeDialog : Form {31 private ISymbolicExpressionTreeNode content;32 public ISymbolicExpressionTreeNode Content{33 get { return con tent; }30 public partial class ConstantNodeEditDialog : Form { 31 private ConstantTreeNode constantTreeNode; 32 public ConstantTreeNode NewNode { 33 get { return constantTreeNode; } 34 34 set { 35 35 if (InvokeRequired) 36 Invoke(new Action<SymbolicExpressionTreeNode>(x => con tent =x), value);36 Invoke(new Action<SymbolicExpressionTreeNode>(x => constantTreeNode = (ConstantTreeNode)x), value); 37 37 else 38 con tent= value;38 constantTreeNode = value; 39 39 } 40 40 } 41 41 42 public ValueChangeDialog() {42 public ConstantNodeEditDialog(ISymbolicExpressionTreeNode node) { 43 43 InitializeComponent(); 44 44 oldValueTextBox.TabStop = false; // cannot receive focus using tab key 45 NewNode = (ConstantTreeNode)node; 46 InitializeFields(); 45 47 } 46 48 47 public void SetContent(ISymbolicExpressionTreeNode content) { 48 Content = content; 49 if (Content is VariableTreeNode) { 50 this.Text = "Change variable name or weight"; 51 var variable = Content as VariableTreeNode; 52 newValueTextBox.Text = oldValueTextBox.Text = Math.Round(variable.Weight, 4).ToString(); 53 // add a dropbox containing all the available variable names 54 variableNameLabel.Visible = true; 55 variableNamesCombo.Visible = true; 56 foreach (var name in variable.Symbol.VariableNames) variableNamesCombo.Items.Add(name); 57 variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variable.VariableName); 58 } else if (Content is ConstantTreeNode) { 59 this.Text = "Change constant value"; 60 var constant = Content as ConstantTreeNode; 61 newValueTextBox.Text = oldValueTextBox.Text = Math.Round(constant.Value, 4).ToString(); 49 private void InitializeFields() { 50 if (NewNode == null) 51 throw new ArgumentException("Node is not a constant."); 52 else { 53 this.Text = "Edit constant"; 54 newValueTextBox.Text = oldValueTextBox.Text = Math.Round(constantTreeNode.Value, 4).ToString(); 62 55 } 63 56 } … … 92 85 #endregion 93 86 94 #region combo box validation and events 95 private void variableNamesCombo_Validating(object sender, CancelEventArgs e) { 96 if (!(Content is VariableTreeNode)) return; 97 if (variableNamesCombo.Items.Contains(variableNamesCombo.SelectedItem)) return; 98 e.Cancel = true; 99 errorProvider.SetError(variableNamesCombo, "Invalid variable name"); 100 variableNamesCombo.SelectAll(); 87 // proxy handler passing key strokes to the parent control 88 private void childControl_KeyDown(object sender, KeyEventArgs e) { 89 ConstantNodeEditDialog_KeyDown(sender, e); 101 90 } 102 91 103 private void variableNamesCombo_Validated(object sender, EventArgs e) { 104 errorProvider.SetError(variableNamesCombo, String.Empty); 105 } 106 #endregion 107 // proxy handler passing key strokes to the parent control 108 private void childControl_KeyDown(object sender, KeyEventArgs e) { 109 ValueChangeDialog_KeyDown(sender, e); 110 } 111 112 private void ValueChangeDialog_KeyDown(object sender, KeyEventArgs e) { 92 private void ConstantNodeEditDialog_KeyDown(object sender, KeyEventArgs e) { 113 93 if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) { 114 94 if (!ValidateChildren()) return; … … 120 100 public event EventHandler DialogValidated; 121 101 private void OnDialogValidated(object sender, EventArgs e) { 102 if (constantTreeNode == null) return; 103 var value = double.Parse(newValueTextBox.Text); 104 // we impose an extra validation condition: that the new value is different from the original value 105 if (constantTreeNode.Value.Equals(value)) return; 106 107 constantTreeNode.Value = value; 108 DialogResult = DialogResult.OK; 122 109 var dialogValidated = DialogValidated; 123 110 if (dialogValidated != null) … … 135 122 } 136 123 } 137 138 124 } 139 125 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeVariableNodeEditDialog.Designer.cs
r8950 r8980 21 21 22 22 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 23 partial class Va lueChangeDialog {23 partial class VariableNodeEditDialog { 24 24 /// <summary> 25 25 /// Required designer variable. … … 61 61 // 62 62 this.originalValueLabel.AutoSize = true; 63 this.originalValueLabel.Location = new System.Drawing.Point(12, 4 5);63 this.originalValueLabel.Location = new System.Drawing.Point(12, 48); 64 64 this.originalValueLabel.Name = "originalValueLabel"; 65 65 this.originalValueLabel.Size = new System.Drawing.Size(72, 13); … … 69 69 // oldValueTextBox 70 70 // 71 this.oldValueTextBox.Location = new System.Drawing.Point(123, 4 2);71 this.oldValueTextBox.Location = new System.Drawing.Point(123, 45); 72 72 this.oldValueTextBox.Name = "oldValueTextBox"; 73 73 this.oldValueTextBox.ReadOnly = true; … … 103 103 // 104 104 this.variableNameLabel.AutoSize = true; 105 this.variableNameLabel.Location = new System.Drawing.Point(12, 7);105 this.variableNameLabel.Location = new System.Drawing.Point(12, 12); 106 106 this.variableNameLabel.Name = "variableNameLabel"; 107 107 this.variableNameLabel.Size = new System.Drawing.Size(76, 13); … … 114 114 this.variableNamesCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 115 115 this.variableNamesCombo.FormattingEnabled = true; 116 this.variableNamesCombo.Location = new System.Drawing.Point(123, 4);116 this.variableNamesCombo.Location = new System.Drawing.Point(123, 9); 117 117 this.variableNamesCombo.Name = "variableNamesCombo"; 118 118 this.variableNamesCombo.Size = new System.Drawing.Size(131, 21); … … 125 125 // okButton 126 126 // 127 this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; 127 128 this.okButton.Location = new System.Drawing.Point(15, 119); 128 129 this.okButton.Name = "okButton"; … … 145 146 this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); 146 147 // 147 // Va lueChangeDialog148 // VariableNodeEditDialog 148 149 // 149 150 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); … … 164 165 this.MaximizeBox = false; 165 166 this.MinimizeBox = false; 166 this.Name = "Va lueChangeDialog";167 this.Name = "VariableNodeEditDialog"; 167 168 this.ShowIcon = false; 168 169 this.ShowInTaskbar = false; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeVariableNodeEditDialog.cs
r8950 r8980 28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 30 public partial class Va lueChangeDialog : Form {31 private ISymbolicExpressionTreeNode content;32 public ISymbolicExpressionTreeNode Content{33 get { return content; }30 public partial class VariableNodeEditDialog : Form { 31 private VariableTreeNode variableTreeNode; 32 public VariableTreeNode NewNode { 33 get { return variableTreeNode; } 34 34 set { 35 35 if (InvokeRequired) 36 Invoke(new Action<SymbolicExpressionTreeNode>(x => content =x), value);36 Invoke(new Action<SymbolicExpressionTreeNode>(x => variableTreeNode = (VariableTreeNode)x), value); 37 37 else 38 content= value;38 variableTreeNode = value; 39 39 } 40 40 } 41 41 42 public Va lueChangeDialog() {42 public VariableNodeEditDialog(ISymbolicExpressionTreeNode node) { 43 43 InitializeComponent(); 44 44 oldValueTextBox.TabStop = false; // cannot receive focus using tab key 45 46 NewNode = (VariableTreeNode)node; // will throw an invalid cast exception if node is not of the correct type 47 InitializeFields(); 45 48 } 46 49 47 p ublic void SetContent(ISymbolicExpressionTreeNode content) {48 Content = content;49 if (Content is VariableTreeNode) {50 this.Text = "Change variable name or weight";51 var variable = Content as VariableTreeNode;52 newValueTextBox.Text = oldValueTextBox.Text = Math.Round(variable .Weight, 4).ToString();50 private void InitializeFields() { 51 if (NewNode == null) 52 throw new ArgumentException("Node is not a constant."); 53 else { 54 this.Text = "Edit variable"; 55 newValueTextBox.Text = oldValueTextBox.Text = Math.Round(variableTreeNode.Weight, 4).ToString(); 53 56 // add a dropbox containing all the available variable names 54 57 variableNameLabel.Visible = true; 55 58 variableNamesCombo.Visible = true; 56 foreach (var name in variable.Symbol.VariableNames) variableNamesCombo.Items.Add(name); 57 variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variable.VariableName); 58 } else if (Content is ConstantTreeNode) { 59 this.Text = "Change constant value"; 60 var constant = Content as ConstantTreeNode; 61 newValueTextBox.Text = oldValueTextBox.Text = Math.Round(constant.Value, 4).ToString(); 59 foreach (var name in variableTreeNode.Symbol.VariableNames) variableNamesCombo.Items.Add(name); 60 variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variableTreeNode.VariableName); 62 61 } 63 62 } … … 94 93 #region combo box validation and events 95 94 private void variableNamesCombo_Validating(object sender, CancelEventArgs e) { 96 if (!(Content is VariableTreeNode)) return;97 95 if (variableNamesCombo.Items.Contains(variableNamesCombo.SelectedItem)) return; 98 96 e.Cancel = true; … … 120 118 public event EventHandler DialogValidated; 121 119 private void OnDialogValidated(object sender, EventArgs e) { 120 double weight = double.Parse(newValueTextBox.Text); 121 var variableName = (string)variableNamesCombo.SelectedItem; 122 // we impose an extra validation condition: that the weight/value be different than the original ones 123 if (variableTreeNode.Weight.Equals(weight) && variableTreeNode.VariableName.Equals(variableName)) return; 124 variableTreeNode.Weight = weight; 125 variableTreeNode.VariableName = variableName; 126 DialogResult = DialogResult.OK; 122 127 var dialogValidated = DialogValidated; 123 128 if (dialogValidated != null) … … 135 140 } 136 141 } 137 138 142 } 139 143 }
Note: See TracChangeset
for help on using the changeset viewer.