Free cookie consent management tool by TermsFeed Policy Generator

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

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

Sorted usings and removed unused usings in entire solution (#1094)

File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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      maxValueTextBox.Enabled = Content != null;
61      valueChangeNuTextBox.Enabled = Content != null;
62      valueChangeSigmaTextBox.Enabled = Content != null;
63    }
64
65    #region content event handlers
66    private void Content_Changed(object sender, EventArgs e) {
67      UpdateControl();
68    }
69    #endregion
70
71    #region control event handlers
72    private void minValueTextBox_TextChanged(object sender, EventArgs e) {
73      double min;
74      if (double.TryParse(minValueTextBox.Text, out min)) {
75        Content.MinValue = min;
76        errorProvider.SetError(minValueTextBox, string.Empty);
77      } else {
78        errorProvider.SetError(minValueTextBox, "Invalid value");
79      }
80    }
81    private void maxValueTextBox_TextChanged(object sender, EventArgs e) {
82      double max;
83      if (double.TryParse(maxValueTextBox.Text, out max)) {
84        Content.MaxValue = max;
85        errorProvider.SetError(maxValueTextBox, string.Empty);
86      } else {
87        errorProvider.SetError(maxValueTextBox, "Invalid value");
88      }
89    }
90
91    private void valueChangeNuTextBox_TextChanged(object sender, EventArgs e) {
92      double nu;
93      if (double.TryParse(valueChangeNuTextBox.Text, out nu)) {
94        Content.ManipulatorNu = nu;
95        errorProvider.SetError(valueChangeNuTextBox, string.Empty);
96      } else {
97        errorProvider.SetError(valueChangeNuTextBox, "Invalid value");
98      }
99    }
100
101    private void valueChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
102      double sigma;
103      if (double.TryParse(valueChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
104        Content.ManipulatorSigma = sigma;
105        errorProvider.SetError(valueChangeSigmaTextBox, string.Empty);
106      } else {
107        errorProvider.SetError(valueChangeSigmaTextBox, "Invalid value");
108      }
109    }
110    #endregion
111
112    #region helpers
113    private void UpdateControl() {
114      if (Content == null) {
115        minValueTextBox.Text = string.Empty;
116        maxValueTextBox.Text = string.Empty;
117        minValueTextBox.Text = string.Empty;
118        valueChangeSigmaTextBox.Text = string.Empty;
119      } else {
120        minValueTextBox.Text = Content.MinValue.ToString();
121        maxValueTextBox.Text = Content.MaxValue.ToString();
122        valueChangeNuTextBox.Text = Content.ManipulatorNu.ToString();
123        valueChangeSigmaTextBox.Text = Content.ManipulatorSigma.ToString();
124      }
125      SetEnabledStateOfControls();
126    }
127    #endregion
128  }
129}
Note: See TracBrowser for help on using the repository browser.