Free cookie consent management tool by TermsFeed Policy Generator

source: branches/crossvalidation-2434/HeuristicLab.Analysis.Views/3.3/ScatterPlotVisualPropertiesControl.cs @ 14559

Last change on this file since 14559 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 11.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Drawing;
23using System.Windows.Forms;
24using HeuristicLab.MainForm;
25using HeuristicLab.MainForm.WindowsForms;
26
27namespace HeuristicLab.Analysis.Views {
28  [View("Scatter Plot Visual Properties")]
29  public partial class ScatterPlotVisualPropertiesControl : UserControl {
30    protected bool SuppressEvents { get; set; }
31
32    private ScatterPlotVisualProperties content;
33    public ScatterPlotVisualProperties Content {
34      get { return content; }
35      set {
36        bool changed = (value != content);
37        content = value;
38        if (changed) OnContentChanged();
39      }
40    }
41
42    public ScatterPlotVisualPropertiesControl() {
43      InitializeComponent();
44      errorProvider.SetIconAlignment(xAxisMinimumFixedTextBox, ErrorIconAlignment.MiddleLeft);
45      errorProvider.SetIconAlignment(xAxisMaximumFixedTextBox, ErrorIconAlignment.MiddleLeft);
46      errorProvider.SetIconAlignment(yAxisMinimumFixedTextBox, ErrorIconAlignment.MiddleLeft);
47      errorProvider.SetIconAlignment(yAxisMaximumFixedTextBox, ErrorIconAlignment.MiddleLeft);
48      errorProvider.SetIconPadding(xAxisMinimumFixedTextBox, 2);
49      errorProvider.SetIconPadding(xAxisMaximumFixedTextBox, 2);
50      errorProvider.SetIconPadding(yAxisMinimumFixedTextBox, 2);
51      errorProvider.SetIconPadding(yAxisMaximumFixedTextBox, 2);
52    }
53
54    protected virtual void OnContentChanged() {
55      SuppressEvents = true;
56      try {
57        if (Content == null) {
58          titleFontLabel.Text = "( none )";
59          axisFontLabel.Text = "( none )";
60          titleTextBox.Text = string.Empty;
61
62          xAxisTitleTextBox.Text = string.Empty;
63          xAxisMinimumAutoRadioButton.Checked = false;
64          xAxisMinimumFixedRadioButton.Checked = false;
65          xAxisMinimumFixedTextBox.Text = string.Empty;
66          xAxisMaximumAutoRadioButton.Checked = false;
67          xAxisMaximumFixedRadioButton.Checked = false;
68          xAxisMaximumFixedTextBox.Text = string.Empty;
69          xAxisGridCheckBox.Checked = false;
70
71          yAxisTitleTextBox.Text = string.Empty;
72          yAxisMinimumAutoRadioButton.Checked = false;
73          yAxisMinimumFixedRadioButton.Checked = false;
74          yAxisMinimumFixedTextBox.Text = string.Empty;
75          yAxisMaximumAutoRadioButton.Checked = false;
76          yAxisMaximumFixedRadioButton.Checked = false;
77          yAxisMaximumFixedTextBox.Text = string.Empty;
78          yAxisGridCheckBox.Checked = false;
79        } else {
80          titleFontLabel.Text = "( " + FormatFont(Content.TitleFont) + " )";
81          axisFontLabel.Text = "( " + FormatFont(Content.AxisTitleFont) + " )";
82          titleTextBox.Text = Content.Title;
83
84          xAxisTitleTextBox.Text = Content.XAxisTitle;
85          xAxisMinimumAutoRadioButton.Checked = Content.XAxisMinimumAuto;
86          xAxisMinimumFixedRadioButton.Checked = !Content.XAxisMinimumAuto;
87          xAxisMinimumFixedTextBox.Text = Content.XAxisMinimumFixedValue.ToString();
88          xAxisMaximumAutoRadioButton.Checked = Content.XAxisMaximumAuto;
89          xAxisMaximumFixedRadioButton.Checked = !Content.XAxisMaximumAuto;
90          xAxisMaximumFixedTextBox.Text = Content.XAxisMaximumFixedValue.ToString();
91          xAxisGridCheckBox.Checked = Content.XAxisGrid;
92
93          yAxisTitleTextBox.Text = Content.YAxisTitle;
94          yAxisMinimumAutoRadioButton.Checked = Content.YAxisMinimumAuto;
95          yAxisMinimumFixedRadioButton.Checked = !Content.YAxisMinimumAuto;
96          yAxisMinimumFixedTextBox.Text = Content.YAxisMinimumFixedValue.ToString();
97          yAxisMaximumAutoRadioButton.Checked = Content.YAxisMaximumAuto;
98          yAxisMaximumFixedRadioButton.Checked = !Content.YAxisMaximumAuto;
99          yAxisMaximumFixedTextBox.Text = Content.YAxisMaximumFixedValue.ToString();
100          yAxisGridCheckBox.Checked = Content.YAxisGrid;
101        }
102      }
103      finally { SuppressEvents = false; }
104      SetEnabledStateOfControls();
105    }
106
107    protected virtual void SetEnabledStateOfControls() {
108      axisTabControl.Enabled = Content != null;
109      xAxisMinimumFixedTextBox.Enabled = xAxisMinimumFixedRadioButton.Checked;
110      xAxisMaximumFixedTextBox.Enabled = xAxisMaximumFixedRadioButton.Checked;
111
112      yAxisMinimumFixedTextBox.Enabled = yAxisMinimumFixedRadioButton.Checked;
113      yAxisMaximumFixedTextBox.Enabled = yAxisMaximumFixedRadioButton.Checked;
114    }
115
116    #region Event Handlers
117    private void yTitleTextBox_Validated(object sender, System.EventArgs e) {
118      if (!SuppressEvents && Content != null) {
119        Content.YAxisTitle = yAxisTitleTextBox.Text;
120      }
121    }
122
123    private void xTitleTextBox_Validated(object sender, System.EventArgs e) {
124      if (!SuppressEvents && Content != null) {
125        Content.XAxisTitle = xAxisTitleTextBox.Text;
126      }
127    }
128
129    private void xAxisMinimumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
130      if (!SuppressEvents && Content != null) {
131        TextBox tb = (TextBox)sender;
132        double val;
133        if (double.TryParse(tb.Text, out val)) {
134          if (val >= Content.XAxisMaximumFixedValue) {
135            errorProvider.SetError(tb, "Number must be smaller than maximum.");
136            e.Cancel = true;
137          } else {
138            Content.XAxisMinimumFixedValue = val;
139            errorProvider.SetError(tb, string.Empty);
140          }
141        } else {
142          errorProvider.SetError(tb, "Not a valid number.");
143          e.Cancel = true;
144        }
145      }
146    }
147
148    private void xAxisMaximumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
149      if (!SuppressEvents && Content != null) {
150        TextBox tb = (TextBox)sender;
151        double val;
152        if (double.TryParse(tb.Text, out val)) {
153          if (val <= Content.XAxisMinimumFixedValue) {
154            errorProvider.SetError(tb, "Number must be greater than minimum.");
155            e.Cancel = true;
156          } else {
157            Content.XAxisMaximumFixedValue = val;
158            errorProvider.SetError(tb, string.Empty);
159          }
160        } else {
161          errorProvider.SetError(tb, "Not a valid number.");
162          e.Cancel = true;
163        }
164      }
165    }
166
167    private void yAxisMinimumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
168      if (!SuppressEvents && Content != null) {
169        TextBox tb = (TextBox)sender;
170        double val;
171        if (double.TryParse(tb.Text, out val)) {
172          if (val >= Content.YAxisMaximumFixedValue) {
173            errorProvider.SetError(tb, "Number must be smaller than maximum.");
174            e.Cancel = true;
175          } else {
176            Content.YAxisMinimumFixedValue = val;
177            errorProvider.SetError(tb, string.Empty);
178          }
179        } else {
180          errorProvider.SetError(tb, "Not a valid number.");
181          e.Cancel = true;
182        }
183      }
184    }
185
186    private void yAxisMaximumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
187      if (!SuppressEvents && Content != null) {
188        TextBox tb = (TextBox)sender;
189        double val;
190        if (double.TryParse(tb.Text, out val)) {
191          if (val <= Content.YAxisMinimumFixedValue) {
192            errorProvider.SetError(tb, "Number must be greater than minimum.");
193            e.Cancel = true;
194          } else {
195            Content.YAxisMaximumFixedValue = val;
196            errorProvider.SetError(tb, string.Empty);
197          }
198        } else {
199          errorProvider.SetError(tb, "Not a valid number.");
200          e.Cancel = true;
201        }
202      }
203    }
204
205    private void xAxisMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
206      if (!SuppressEvents && Content != null) {
207        SuppressEvents = true;
208        try {
209          Content.XAxisMinimumAuto = xAxisMinimumAutoRadioButton.Checked;
210          if (Content.XAxisMinimumAuto) xAxisMinimumFixedTextBox.Text = double.NaN.ToString();
211        }
212        finally { SuppressEvents = false; }
213        SetEnabledStateOfControls();
214      }
215    }
216
217    private void xAxisMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
218      if (!SuppressEvents && Content != null) {
219        SuppressEvents = true;
220        try {
221          Content.XAxisMaximumAuto = xAxisMaximumAutoRadioButton.Checked;
222          if (Content.XAxisMaximumAuto) xAxisMaximumFixedTextBox.Text = double.NaN.ToString();
223        }
224        finally { SuppressEvents = false; }
225        SetEnabledStateOfControls();
226      }
227    }
228
229    private void yAxisMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
230      if (!SuppressEvents && Content != null) {
231        SuppressEvents = true;
232        try {
233          Content.YAxisMinimumAuto = yAxisMinimumAutoRadioButton.Checked;
234          if (Content.YAxisMinimumAuto) yAxisMinimumFixedTextBox.Text = double.NaN.ToString();
235        }
236        finally { SuppressEvents = false; }
237        SetEnabledStateOfControls();
238      }
239    }
240
241    private void yAxisMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
242      if (!SuppressEvents && Content != null) {
243        SuppressEvents = true;
244        try {
245          Content.YAxisMaximumAuto = yAxisMaximumAutoRadioButton.Checked;
246          if (Content.YAxisMaximumAuto) yAxisMaximumFixedTextBox.Text = double.NaN.ToString();
247        }
248        finally { SuppressEvents = false; }
249        SetEnabledStateOfControls();
250      }
251    }
252
253    private void titleFontButton_Click(object sender, System.EventArgs e) {
254      titleFontDialog.Font = Content.TitleFont;
255      titleFontDialog.Color = Content.TitleColor;
256      if (titleFontDialog.ShowDialog() == DialogResult.OK) {
257        Content.TitleFont = titleFontDialog.Font;
258        Content.TitleColor = titleFontDialog.Color;
259        titleFontLabel.Text = "( " + FormatFont(Content.TitleFont) + " )";
260      }
261    }
262
263    private void axisFontButton_Click(object sender, System.EventArgs e) {
264      axisFontDialog.Font = Content.AxisTitleFont;
265      axisFontDialog.Color = Content.AxisTitleColor;
266      if (axisFontDialog.ShowDialog() == DialogResult.OK) {
267        Content.AxisTitleFont = axisFontDialog.Font;
268        Content.AxisTitleColor = axisFontDialog.Color;
269        axisFontLabel.Text = "( " + FormatFont(Content.AxisTitleFont) + " )";
270      }
271    }
272
273    private void titleTextBox_Validated(object sender, System.EventArgs e) {
274      if (!SuppressEvents && Content != null) {
275        Content.Title = titleTextBox.Text;
276      }
277    }
278
279    private void yAxisGridCheckBox_CheckedChanged(object sender, System.EventArgs e) {
280      if (!SuppressEvents && Content != null) {
281        Content.YAxisGrid = yAxisGridCheckBox.Checked;
282      }
283    }
284
285    private void xAxisGridCheckBox_CheckedChanged(object sender, System.EventArgs e) {
286      if (!SuppressEvents && Content != null) {
287        Content.XAxisGrid = xAxisGridCheckBox.Checked;
288      }
289    }
290    #endregion
291
292    private string FormatFont(Font f) {
293      if (f == null) return "default";
294      else return f.Name + ", " + f.SizeInPoints.ToString() + "pt, " + f.Style.ToString();
295    }
296  }
297}
Note: See TracBrowser for help on using the repository browser.