Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/ConstantView.cs @ 6833

Last change on this file since 6833 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

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