Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2679_HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem.Views/3.4/GoalParameterView.cs @ 18063

Last change on this file since 18063 was 14333, checked in by bburlacu, 8 years ago

#2679: Refactor problems and extract common functionality in static util class.

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.ComponentModel;
24using System.Globalization;
25using System.Windows.Forms;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28
29namespace HeuristicLab.GoalSeeking.Views {
30  [View("GoalSeekingTarget View", "")]
31  [Content(typeof(GoalParameter), true)]
32  public partial class GoalSeekingTargetView : AsynchronousContentView {
33    public new GoalParameter Content {
34      get { return (GoalParameter)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public GoalSeekingTargetView() {
39      InitializeComponent();
40    }
41
42    protected override void OnContentChanged() {
43      base.OnContentChanged();
44      if (Content != null) {
45        groupBox.Text = Content.Name;
46        goalTextBox.Text = Content.Goal.ToString(CultureInfo.CurrentCulture);
47        weightTextBox.Text = Content.Weight.ToString(CultureInfo.CurrentCulture);
48        varianceTextBox.Text = Content.Variance.ToString(CultureInfo.CurrentCulture);
49        stepTextBox.Text = Content.Step.ToString(CultureInfo.CurrentCulture);
50        activeCheckBox.Checked = Content.Active;
51        Content.Changed += Content_Changed;
52      }
53    }
54
55    private void Content_Changed(object sender, EventArgs args) {
56      groupBox.Text = Content.Name;
57      goalTextBox.Text = Content.Goal.ToString(CultureInfo.CurrentCulture);
58      weightTextBox.Text = Content.Weight.ToString(CultureInfo.CurrentCulture);
59      varianceTextBox.Text = Content.Variance.ToString(CultureInfo.CurrentCulture);
60      stepTextBox.Text = Content.Step.ToString(CultureInfo.CurrentCulture);
61      activeCheckBox.Checked = Content.Active;
62    }
63
64    #region event handlers
65    private void TextBoxValidating(object sender, CancelEventArgs e) {
66      double v;
67      string errorMsg = "Could not parse the entered value. Please input a real number.";
68      var tb = (TextBox)sender;
69      if (!double.TryParse(tb.Text, out v)) {
70        e.Cancel = true;
71        tb.Select(0, tb.Text.Length);
72
73        // Set the ErrorProvider error with the text to display.
74        this.errorProvider.SetError(tb, errorMsg);
75        errorProvider.BlinkStyle = ErrorBlinkStyle.NeverBlink;
76        errorProvider.SetIconPadding(tb, -20);
77      }
78    }
79
80    private void TextBoxValidated(object sender, EventArgs e) {
81      var tb = (TextBox)sender;
82      errorProvider.SetError(tb, string.Empty);
83    }
84
85    private void activeCheckBox_CheckedChanged(object sender, System.EventArgs e) {
86      Content.Active = activeCheckBox.Checked;
87      goalTextBox.Enabled = weightTextBox.Enabled = stepTextBox.Enabled = varianceTextBox.Enabled = Content.Active;
88    }
89
90    private void goalTextBox_TextChanged(object sender, EventArgs e) {
91      double goal;
92      if (double.TryParse(goalTextBox.Text, out goal))
93        Content.Goal = goal;
94    }
95
96    private void weightTextBox_TextChanged(object sender, EventArgs e) {
97      double weight;
98      if (double.TryParse(weightTextBox.Text, out weight))
99        Content.Weight = weight;
100    }
101
102    private void varianceTextBox_TextChanged(object sender, EventArgs e) {
103      double variance;
104      if (double.TryParse(varianceTextBox.Text, out variance))
105        Content.Variance = variance;
106    }
107
108    private void stepTextBox_TextChanged(object sender, System.EventArgs e) {
109      double step;
110      if (double.TryParse(stepTextBox.Text, out step))
111        Content.Step = step;
112    }
113    #endregion
114  }
115}
Note: See TracBrowser for help on using the repository browser.