Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MemPRAlgorithm/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/GradientChartConfigurationDialog.cs @ 16102

Last change on this file since 16102 was 14118, checked in by pfleck, 8 years ago

#2597:

  • Fixed issue with automatic movement of the cursor in some cases (missing position changed event).
  • Disable the whole GradientChartConfigurationDialog during chart recalculation after pressing apply.
File size: 4.6 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.WindowsForms;
27
28namespace HeuristicLab.Problems.DataAnalysis.Views {
29  public partial class GradientChartConfigurationDialog : Form {
30    private readonly GradientChart chart;
31
32    public GradientChartConfigurationDialog(GradientChart chart) {
33      this.chart = chart;
34      InitializeComponent();
35    }
36
37    private void GradientChartConfigurationDialog_Shown(object sender, EventArgs e) {
38      if (chart.FixedXAxisMin.HasValue && chart.FixedXAxisMax.HasValue) {
39        xAutomaticCheckBox.Checked = false;
40        minXTextBox.Text = chart.FixedXAxisMin.Value.ToString(CultureInfo.CurrentUICulture);
41        maxXTextBox.Text = chart.FixedXAxisMax.Value.ToString(CultureInfo.CurrentUICulture);
42      } else xAutomaticCheckBox.Checked = true;
43      if (chart.FixedYAxisMin.HasValue && chart.FixedYAxisMax.HasValue) {
44        yAutomaticCheckBox.Checked = false;
45        minYTextBox.Text = chart.FixedYAxisMin.Value.ToString(CultureInfo.CurrentUICulture);
46        maxYTextBox.Text = chart.FixedYAxisMax.Value.ToString(CultureInfo.CurrentUICulture);
47      } else yAutomaticCheckBox.Checked = true;
48      StepsNumericUpDown.Value = chart.DrawingSteps;
49    }
50
51    private async void okButton_Click(object sender, System.EventArgs e) {
52      try {
53        Enabled = false;
54        chart.SuspendRepaint();
55        if (xAutomaticCheckBox.Checked) {
56          chart.FixedXAxisMin = null;
57          chart.FixedXAxisMax = null;
58        } else {
59          var min = double.Parse(minXTextBox.Text, CultureInfo.CurrentUICulture);
60          var max = double.Parse(maxXTextBox.Text, CultureInfo.CurrentUICulture);
61          chart.FixedXAxisMin = min;
62          chart.FixedXAxisMax = max;
63        }
64
65        if (yAutomaticCheckBox.Checked) {
66          chart.FixedYAxisMin = null;
67          chart.FixedYAxisMax = null;
68        } else {
69          var min = double.Parse(minYTextBox.Text, CultureInfo.CurrentUICulture);
70          var max = double.Parse(maxYTextBox.Text, CultureInfo.CurrentUICulture);
71          chart.FixedYAxisMin = min;
72          chart.FixedYAxisMax = max;
73        }
74
75        chart.DrawingSteps = (int)StepsNumericUpDown.Value;
76
77        await chart.RecalculateAsync(resetYAxis: false);
78
79        Close();
80      }
81      catch (FormatException) {
82        MessageBox.Show(this, "Illegal number format", "Wrong format", MessageBoxButtons.OK, MessageBoxIcon.Error);
83      }
84      finally {
85        Enabled = true;
86        chart.ResumeRepaint(true);
87      }
88    }
89
90    private void automaticCheckBox_CheckedChanged(object sender, EventArgs e) {
91      minXTextBox.Enabled = !xAutomaticCheckBox.Checked;
92      maxXTextBox.Enabled = !xAutomaticCheckBox.Checked;
93
94      minYTextBox.Enabled = !yAutomaticCheckBox.Checked;
95      maxYTextBox.Enabled = !yAutomaticCheckBox.Checked;
96    }
97
98    private void numberTextBox_Validating(object sender, CancelEventArgs e) {
99      var textBox = sender as TextBox;
100      if (textBox != null) {
101        double number;
102        if (!double.TryParse(textBox.Text, NumberStyles.Any, CultureInfo.CurrentUICulture, out number)) {
103          e.Cancel = true;
104          applyButton.Enabled = false;
105          errorProvider.SetIconAlignment(textBox, ErrorIconAlignment.MiddleLeft);
106          errorProvider.SetIconPadding(textBox, 2);
107          errorProvider.SetError(textBox, "Illegal number format");
108          textBox.SelectAll();
109        }
110      }
111    }
112
113    private void numberTextBox_Validated(object sender, EventArgs e) {
114      var textBox = sender as TextBox;
115      if (textBox != null) {
116        errorProvider.SetError(textBox, string.Empty);
117        applyButton.Enabled = true;
118      }
119    }
120  }
121}
Note: See TracBrowser for help on using the repository browser.