Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChartConfigurationDialog.cs @ 14095

Last change on this file since 14095 was 14095, checked in by mkommend, 8 years ago

#2597: Merged all changesets from HeuristiLab.RegressionSolutionGradientView into the trunk.

File size: 4.5 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        chart.SuspendRepaint();
54        if (xAutomaticCheckBox.Checked) {
55          chart.FixedXAxisMin = null;
56          chart.FixedXAxisMax = null;
57        } else {
58          var min = double.Parse(minXTextBox.Text, CultureInfo.CurrentUICulture);
59          var max = double.Parse(maxXTextBox.Text, CultureInfo.CurrentUICulture);
60          chart.FixedXAxisMin = min;
61          chart.FixedXAxisMax = max;
62        }
63
64        if (yAutomaticCheckBox.Checked) {
65          chart.FixedYAxisMin = null;
66          chart.FixedYAxisMax = null;
67        } else {
68          var min = double.Parse(minYTextBox.Text, CultureInfo.CurrentUICulture);
69          var max = double.Parse(maxYTextBox.Text, CultureInfo.CurrentUICulture);
70          chart.FixedYAxisMin = min;
71          chart.FixedYAxisMax = max;
72        }
73
74        chart.DrawingSteps = (int)StepsNumericUpDown.Value;
75
76        await chart.RecalculateAsync(resetYAxis: false);
77
78        Close();
79      }
80      catch (FormatException) {
81        MessageBox.Show(this, "Illegal number format", "Wrong format", MessageBoxButtons.OK, MessageBoxIcon.Error);
82      }
83      finally {
84        chart.ResumeRepaint(true);
85      }
86    }
87
88    private void automaticCheckBox_CheckedChanged(object sender, EventArgs e) {
89      minXTextBox.Enabled = !xAutomaticCheckBox.Checked;
90      maxXTextBox.Enabled = !xAutomaticCheckBox.Checked;
91
92      minYTextBox.Enabled = !yAutomaticCheckBox.Checked;
93      maxYTextBox.Enabled = !yAutomaticCheckBox.Checked;
94    }
95
96    private void numberTextBox_Validating(object sender, CancelEventArgs e) {
97      var textBox = sender as TextBox;
98      if (textBox != null) {
99        double number;
100        if (!double.TryParse(textBox.Text, NumberStyles.Any, CultureInfo.CurrentUICulture, out number)) {
101          e.Cancel = true;
102          applyButton.Enabled = false;
103          errorProvider.SetIconAlignment(textBox, ErrorIconAlignment.MiddleLeft);
104          errorProvider.SetIconPadding(textBox, 2);
105          errorProvider.SetError(textBox, "Illegal number format");
106          textBox.SelectAll();
107        }
108      }
109    }
110
111    private void numberTextBox_Validated(object sender, EventArgs e) {
112      var textBox = sender as TextBox;
113      if (textBox != null) {
114        errorProvider.SetError(textBox, string.Empty);
115        applyButton.Enabled = true;
116      }
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.