Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/ConstantView.cs @ 17590

Last change on this file since 17590 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 4.8 KB
RevLine 
[3824]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3824]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;
[4068]24using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
[3824]25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
[5693]28namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
[3824]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
[3904]56    protected override void SetEnabledStateOfControls() {
57      base.SetEnabledStateOfControls();
[3824]58      minValueTextBox.Enabled = Content != null;
[4435]59      minValueTextBox.ReadOnly = ReadOnly;
[3824]60      maxValueTextBox.Enabled = Content != null;
[4435]61      maxValueTextBox.ReadOnly = ReadOnly;
[5326]62      additiveChangeSigmaTextBox.Enabled = Content != null;
63      additiveChangeSigmaTextBox.ReadOnly = ReadOnly;
64      multiplicativeChangeSigmaTextBox.Enabled = Content != null;
65      multiplicativeChangeSigmaTextBox.ReadOnly = ReadOnly;
[3824]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
[5326]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);
[3824]99      } else {
[5326]100        errorProvider.SetError(additiveChangeSigmaTextBox, "Invalid value");
[3824]101      }
102    }
103
[5326]104    private void multiplicativeChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
[3824]105      double sigma;
[5326]106      if (double.TryParse(multiplicativeChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
107        Content.MultiplicativeManipulatorSigma = sigma;
108        errorProvider.SetError(multiplicativeChangeSigmaTextBox, string.Empty);
[3824]109      } else {
[5326]110        errorProvider.SetError(multiplicativeChangeSigmaTextBox, "Invalid value");
[3824]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;
[5326]121        multiplicativeChangeSigmaTextBox.Text = string.Empty;
122        additiveChangeSigmaTextBox.Text = string.Empty;
[3824]123      } else {
124        minValueTextBox.Text = Content.MinValue.ToString();
125        maxValueTextBox.Text = Content.MaxValue.ToString();
[5326]126        additiveChangeSigmaTextBox.Text = Content.ManipulatorSigma.ToString();
127        multiplicativeChangeSigmaTextBox.Text = Content.MultiplicativeManipulatorSigma.ToString();
[3824]128      }
129      SetEnabledStateOfControls();
130    }
131    #endregion
132  }
133}
Note: See TracBrowser for help on using the repository browser.