source: branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/ConstantView.cs @ 17207

Last change on this file since 17207 was 17207, checked in by gkronber, 6 weeks ago

#2971: merged r17180:17184 from trunk to branch

File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.Windows.Forms;
24using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
29  [View("Constant View")]
30  [Content(typeof(Constant), true)]
31  public partial class ConstantView : SymbolView {
32    public new Constant Content {
33      get { return (Constant)base.Content; }
34      set { base.Content = value; }
35    }
36
37    public ConstantView() {
38      InitializeComponent();
39    }
40
41    protected override void RegisterContentEvents() {
42      base.RegisterContentEvents();
43      Content.Changed += new EventHandler(Content_Changed);
44    }
45
46    protected override void DeregisterContentEvents() {
47      base.DeregisterContentEvents();
48      Content.Changed -= new EventHandler(Content_Changed);
49    }
50
51    protected override void OnContentChanged() {
52      base.OnContentChanged();
53      UpdateControl();
54    }
55
56    protected override void SetEnabledStateOfControls() {
57      base.SetEnabledStateOfControls();
58      minValueTextBox.Enabled = Content != null;
59      minValueTextBox.ReadOnly = ReadOnly;
60      maxValueTextBox.Enabled = Content != null;
61      maxValueTextBox.ReadOnly = ReadOnly;
62      additiveChangeSigmaTextBox.Enabled = Content != null;
63      additiveChangeSigmaTextBox.ReadOnly = ReadOnly;
64      multiplicativeChangeSigmaTextBox.Enabled = Content != null;
65      multiplicativeChangeSigmaTextBox.ReadOnly = ReadOnly;
66    }
67
68    #region content event handlers
69    private void Content_Changed(object sender, EventArgs e) {
70      UpdateControl();
71    }
72    #endregion
73
74    #region control event handlers
75    private void minValueTextBox_TextChanged(object sender, EventArgs e) {
76      double min;
77      if (double.TryParse(minValueTextBox.Text, out min)) {
78        Content.MinValue = min;
79        errorProvider.SetError(minValueTextBox, string.Empty);
80      } else {
81        errorProvider.SetError(minValueTextBox, "Invalid value");
82      }
83    }
84    private void maxValueTextBox_TextChanged(object sender, EventArgs e) {
85      double max;
86      if (double.TryParse(maxValueTextBox.Text, out max)) {
87        Content.MaxValue = max;
88        errorProvider.SetError(maxValueTextBox, string.Empty);
89      } else {
90        errorProvider.SetError(maxValueTextBox, "Invalid value");
91      }
92    }
93
94    private void additiveChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
95      double sigma;
96      if (double.TryParse(additiveChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
97        Content.ManipulatorSigma = sigma;
98        errorProvider.SetError(additiveChangeSigmaTextBox, string.Empty);
99      } else {
100        errorProvider.SetError(additiveChangeSigmaTextBox, "Invalid value");
101      }
102    }
103
104    private void multiplicativeChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
105      double sigma;
106      if (double.TryParse(multiplicativeChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
107        Content.MultiplicativeManipulatorSigma = sigma;
108        errorProvider.SetError(multiplicativeChangeSigmaTextBox, string.Empty);
109      } else {
110        errorProvider.SetError(multiplicativeChangeSigmaTextBox, "Invalid value");
111      }
112    }
113    #endregion
114
115    #region helpers
116    private void UpdateControl() {
117      if (Content == null) {
118        minValueTextBox.Text = string.Empty;
119        maxValueTextBox.Text = string.Empty;
120        minValueTextBox.Text = string.Empty;
121        multiplicativeChangeSigmaTextBox.Text = string.Empty;
122        additiveChangeSigmaTextBox.Text = string.Empty;
123      } else {
124        minValueTextBox.Text = Content.MinValue.ToString();
125        maxValueTextBox.Text = Content.MaxValue.ToString();
126        additiveChangeSigmaTextBox.Text = Content.ManipulatorSigma.ToString();
127        multiplicativeChangeSigmaTextBox.Text = Content.MultiplicativeManipulatorSigma.ToString();
128      }
129      SetEnabledStateOfControls();
130    }
131    #endregion
132  }
133}
Note: See TracBrowser for help on using the repository browser.