Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.cs @ 5821

Last change on this file since 5821 was 5809, checked in by mkommend, 14 years ago

#1418: Reintegrated branch into trunk.

File size: 2.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.Core.Views;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
29  [View("Symbol View")]
30  [Content(typeof(ISymbol), false)]
31  public partial class SymbolView : NamedItemView {
32    public new ISymbol Content {
33      get { return (ISymbol)base.Content; }
34      set { base.Content = value; }
35    }
36
37    public SymbolView() {
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      initialFrequencyTextBox.Enabled = Content != null;
59      initialFrequencyTextBox.ReadOnly = ReadOnly;
60    }
61
62    #region content event handlers
63    private void Content_Changed(object sender, EventArgs e) {
64      UpdateControl();
65    }
66    #endregion
67
68    #region control event handlers
69    private void initialFrequencyTextBox_TextChanged(object sender, EventArgs e) {
70      double freq;
71      if (double.TryParse(initialFrequencyTextBox.Text, out freq) && freq >= 0.0) {
72        Content.InitialFrequency = freq;
73        errorProvider.SetError(initialFrequencyTextBox, string.Empty);
74      } else {
75        errorProvider.SetError(initialFrequencyTextBox, "Invalid value");
76      }
77    }
78    #endregion
79
80    #region helpers
81    private void UpdateControl() {
82      if (Content == null) {
83        initialFrequencyTextBox.Text = string.Empty;
84      } else {
85        initialFrequencyTextBox.Text = Content.InitialFrequency.ToString();
86      }
87      SetEnabledStateOfControls();
88    }
89    #endregion
90  }
91}
Note: See TracBrowser for help on using the repository browser.