Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicExpressionTreeNodeChangeValueDialog.cs @ 7388

Last change on this file since 7388 was 7388, checked in by bburlacu, 12 years ago

#1763: Added a new context option for leaf nodes (ConstantTreeNode or VariableTreeNode) to change the value or variable weight respectively.

  • Added new dialog: SymbolicExpressionTreeNodeChangeValueDialog
  • Added new SymbolicExpressionTreeNodeChanged event and handler
  • Changed the double click behavior to account for node value/weight changes

Overall the behavior has been slightly changed: if a node was folded(replaced by a ConstantTreeNode), then it is possible to change its value via the context menu. For all changed nodes the original value is kept in a dictionary, so the first double click will restore it. After that, a second double click will unfold the node.

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.ComponentModel;
24using System.Text;
25using System.Windows.Forms;
26using HeuristicLab.Common;
27using HeuristicLab.Data;
28
29namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
30  public partial class ValueChangeDialog : Form {
31    public string Caption {
32      get { return this.Text; }
33      set {
34        if (InvokeRequired)
35          Invoke(new Action<string>(x => this.Caption = x), value);
36        else
37          this.Text = value;
38      }
39    }
40    public string OldValue {
41      get { return oldValueTextBox.Text; }
42      set {
43        if (InvokeRequired)
44          Invoke(new Action<string>(x => this.NewValue = x), value);
45        else
46          oldValueTextBox.Text = value;
47      }
48    }
49    public string NewValue {
50      get { return newValueTextBox.Text; }
51      set {
52        if (InvokeRequired)
53          Invoke(new Action<string>(x => this.NewValue = x), value);
54        else
55          newValueTextBox.Text = value;
56      }
57    }
58
59    public ValueChangeDialog() {
60      InitializeComponent();
61    }
62    public ValueChangeDialog(string caption, string oldValue)
63      : this() {
64      Caption = caption;
65      OldValue = oldValue;
66      NewValue = string.Empty;
67    }
68
69    protected virtual void okButton_Click(object sender, EventArgs e) {
70      Close();
71    }
72
73    private void newValueTextBox_KeyDown(object sender, KeyEventArgs e) {
74      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
75        newValueLabel.Select();  // select label to validate data
76
77      if (e.KeyCode == Keys.Escape) {
78        newValueTextBox.Text = String.Empty;
79        newValueLabel.Select();  // select label to validate data
80      }
81    }
82    private void newValueTextBox_Validating(object sender, CancelEventArgs e) {
83      string errorMessage;
84      if (!Validate(newValueTextBox.Text, out errorMessage)) {
85        e.Cancel = true;
86        okButton.Enabled = false;
87        errorProvider.SetError(newValueTextBox, errorMessage);
88        newValueTextBox.SelectAll();
89      }
90    }
91    private void newValueTextBox_Validated(object sender, EventArgs e) {
92      errorProvider.SetError(newValueTextBox, string.Empty);
93      okButton.Enabled = true;
94    }
95
96    private static bool Validate(string value, out string errorMessage) {
97      double val;
98      bool valid = double.TryParse(value, out val);
99      errorMessage = string.Empty;
100      if (!valid) {
101        var sb = new StringBuilder();
102        sb.Append("Invalid Value (Valid Value Format: \"");
103        sb.Append(FormatPatterns.GetDoubleFormatPattern());
104        sb.Append("\")");
105        errorMessage = sb.ToString();
106      }
107      return valid;
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.