[14333] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.ComponentModel;
|
---|
| 24 | using System.Globalization;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.GoalSeeking.Views {
|
---|
| 30 | [View("GoalSeekingParameter View", "")]
|
---|
| 31 | [Content(typeof(InputParameter), true)]
|
---|
| 32 | public partial class GoalSeekingParameterView : AsynchronousContentView {
|
---|
| 33 | public new InputParameter Content {
|
---|
| 34 | get { return (InputParameter)base.Content; }
|
---|
| 35 | set { base.Content = value; }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public GoalSeekingParameterView() {
|
---|
| 39 | InitializeComponent();
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | protected override void OnContentChanged() {
|
---|
| 43 | base.OnContentChanged();
|
---|
| 44 | if (Content != null) {
|
---|
| 45 | groupBox.Text = Content.Name;
|
---|
| 46 | minTextBox.Text = Content.Min.ToString(CultureInfo.CurrentCulture);
|
---|
| 47 | maxTextBox.Text = Content.Max.ToString(CultureInfo.CurrentCulture);
|
---|
| 48 | stepTextBox.Text = Content.Step.ToString(CultureInfo.CurrentCulture);
|
---|
| 49 | valueTextBox.Text = Content.Value.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 | minTextBox.Text = Content.Min.ToString(CultureInfo.CurrentCulture);
|
---|
| 58 | maxTextBox.Text = Content.Max.ToString(CultureInfo.CurrentCulture);
|
---|
| 59 | stepTextBox.Text = Content.Step.ToString(CultureInfo.CurrentCulture);
|
---|
| 60 | valueTextBox.Text = Content.Value.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 | #endregion
|
---|
| 85 |
|
---|
| 86 | private void minTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 87 | double min;
|
---|
| 88 | if (double.TryParse(minTextBox.Text, out min))
|
---|
| 89 | Content.Min = min;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | private void maxTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 93 | double max;
|
---|
[14336] | 94 | if (double.TryParse(maxTextBox.Text, out max))
|
---|
[14333] | 95 | Content.Max = max;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | private void stepTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 99 | double step;
|
---|
[14336] | 100 | if (double.TryParse(stepTextBox.Text, out step))
|
---|
[14333] | 101 | Content.Step = step;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | private void valueTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 105 | double value;
|
---|
[14336] | 106 | if (double.TryParse(valueTextBox.Text, out value))
|
---|
[14333] | 107 | Content.Value = value;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | private void activeCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 111 | Content.Active = activeCheckBox.Checked;
|
---|
| 112 | minTextBox.Enabled = maxTextBox.Enabled = stepTextBox.Enabled = Content.Active;
|
---|
| 113 | valueTextBox.Enabled = !Content.Active;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | }
|
---|