Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.0/HeuristicLab.Problems.DataAnalysis.Views/3.3/Symbolic/Symbols/VariableView.cs @ 13398

Last change on this file since 13398 was 3824, checked in by gkronber, 14 years ago

Implemented view for symbolic expression grammars and symbols. #1014

File size: 4.8 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.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.MainForm;
31using HeuristicLab.MainForm.WindowsForms;
32using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
33using HeuristicLab.Core.Views;
34using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
35
36namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
37  [View("Variable View")]
38  [Content(typeof(Variable), true)]
39  public partial class VariableView : SymbolView {
40    public new Variable Content {
41      get { return (Variable)base.Content; }
42      set { base.Content = value; }
43    }
44
45    public VariableView() {
46      InitializeComponent();
47    }
48
49    protected override void RegisterContentEvents() {
50      base.RegisterContentEvents();
51      Content.Changed += new EventHandler(Content_Changed);
52    }
53
54    protected override void DeregisterContentEvents() {
55      base.DeregisterContentEvents();
56      Content.Changed -= new EventHandler(Content_Changed);
57    }
58
59    protected override void OnContentChanged() {
60      base.OnContentChanged();
61      UpdateControl();
62    }
63
64    protected override void OnReadOnlyChanged() {
65      base.OnReadOnlyChanged();
66      SetEnabledStateOfControls();
67    }
68
69    private void SetEnabledStateOfControls() {
70      weightNuTextBox.Enabled = Content != null;
71      weightSigmaTextBox.Enabled = Content != null;
72      weightChangeNuTextBox.Enabled = Content != null;
73      weightChangeSigmaTextBox.Enabled = Content != null;
74    }
75
76    #region content event handlers
77    private void Content_Changed(object sender, EventArgs e) {
78      UpdateControl();
79    }
80    #endregion
81
82    #region control event handlers
83    private void weightNuTextBox_TextChanged(object sender, EventArgs e) {
84      double nu;
85      if (double.TryParse(weightNuTextBox.Text, out nu)) {
86        Content.WeightNu = nu;
87        errorProvider.SetError(weightNuTextBox, string.Empty);
88      } else {
89        errorProvider.SetError(weightNuTextBox, "Invalid value");
90      }
91    }
92    private void weightSigmaTextBox_TextChanged(object sender, EventArgs e) {
93      double sigma;
94      if (double.TryParse(weightSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
95        Content.WeightSigma = sigma;
96        errorProvider.SetError(weightSigmaTextBox, string.Empty);
97      } else {
98        errorProvider.SetError(weightSigmaTextBox, "Invalid value");
99      }
100    }
101
102    private void weightChangeNuTextBox_TextChanged(object sender, EventArgs e) {
103      double nu;
104      if (double.TryParse(weightChangeNuTextBox.Text, out nu)) {
105        Content.WeightManipulatorNu = nu;
106        errorProvider.SetError(weightChangeNuTextBox, string.Empty);
107      } else {
108        errorProvider.SetError(weightChangeNuTextBox, "Invalid value");
109      }
110    }
111
112    private void weightChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
113      double sigma;
114      if (double.TryParse(weightChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
115        Content.WeightManipulatorSigma = sigma;
116        errorProvider.SetError(weightChangeSigmaTextBox, string.Empty);
117      } else {
118        errorProvider.SetError(weightChangeSigmaTextBox, "Invalid value");
119      }
120    }
121    #endregion
122
123    #region helpers
124    private void UpdateControl() {
125      if (Content == null) {
126        weightNuTextBox.Text = string.Empty;
127        weightSigmaTextBox.Text = string.Empty;
128        weightNuTextBox.Text = string.Empty;
129        weightChangeSigmaTextBox.Text = string.Empty;
130      } else {
131        weightNuTextBox.Text = Content.WeightNu.ToString();
132        weightSigmaTextBox.Text = Content.WeightSigma.ToString();
133        weightChangeNuTextBox.Text = Content.WeightManipulatorNu.ToString();
134        weightChangeSigmaTextBox.Text = Content.WeightManipulatorSigma.ToString();
135      }
136      SetEnabledStateOfControls();
137    }
138    #endregion
139  }
140}
Note: See TracBrowser for help on using the repository browser.