Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveHiveEngine/HeuristicLab.Analysis.Views/3.3/DataTableVisualPropertiesControl.cs @ 12771

Last change on this file since 12771 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 20.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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("DataRow Visual Properties")]
29  public partial class DataTableVisualPropertiesControl : UserControl {
30    protected bool SuppressEvents { get; set; }
31
32    private DataTableVisualProperties content;
33    public DataTableVisualProperties Content {
34      get { return content; }
35      set {
36        bool changed = (value != content);
37        content = value;
38        if (changed) OnContentChanged();
39      }
40    }
41
42    public DataTableVisualPropertiesControl() {
43      InitializeComponent();
44      errorProvider.SetIconAlignment(xAxisPrimaryMinimumFixedTextBox, ErrorIconAlignment.MiddleLeft);
45      errorProvider.SetIconAlignment(xAxisPrimaryMaximumFixedTextBox, ErrorIconAlignment.MiddleLeft);
46      errorProvider.SetIconAlignment(xAxisSecondaryMinimumFixedTextBox, ErrorIconAlignment.MiddleLeft);
47      errorProvider.SetIconAlignment(xAxisSecondaryMaximumFixedTextBox, ErrorIconAlignment.MiddleLeft);
48      errorProvider.SetIconAlignment(yAxisPrimaryMinimumFixedTextBox, ErrorIconAlignment.MiddleLeft);
49      errorProvider.SetIconAlignment(yAxisPrimaryMaximumFixedTextBox, ErrorIconAlignment.MiddleLeft);
50      errorProvider.SetIconAlignment(yAxisSecondaryMinimumFixedTextBox, ErrorIconAlignment.MiddleLeft);
51      errorProvider.SetIconAlignment(yAxisSecondaryMaximumFixedTextBox, ErrorIconAlignment.MiddleLeft);
52      errorProvider.SetIconPadding(xAxisPrimaryMinimumFixedTextBox, 2);
53      errorProvider.SetIconPadding(xAxisPrimaryMaximumFixedTextBox, 2);
54      errorProvider.SetIconPadding(xAxisSecondaryMinimumFixedTextBox, 2);
55      errorProvider.SetIconPadding(xAxisSecondaryMaximumFixedTextBox, 2);
56      errorProvider.SetIconPadding(yAxisPrimaryMinimumFixedTextBox, 2);
57      errorProvider.SetIconPadding(yAxisPrimaryMaximumFixedTextBox, 2);
58      errorProvider.SetIconPadding(yAxisSecondaryMinimumFixedTextBox, 2);
59      errorProvider.SetIconPadding(yAxisSecondaryMaximumFixedTextBox, 2);
60    }
61
62    protected virtual void OnContentChanged() {
63      SuppressEvents = true;
64      try {
65        if (Content == null) {
66          titleFontLabel.Text = "( none )";
67          axisFontLabel.Text = "( none )";
68          titleTextBox.Text = string.Empty;
69
70          xAxisPrimaryTitleTextBox.Text = string.Empty;
71          xAxisPrimaryMinimumAutoRadioButton.Checked = false;
72          xAxisPrimaryMinimumFixedRadioButton.Checked = false;
73          xAxisPrimaryMinimumFixedTextBox.Text = string.Empty;
74          xAxisPrimaryMaximumAutoRadioButton.Checked = false;
75          xAxisPrimaryMaximumFixedRadioButton.Checked = false;
76          xAxisPrimaryMaximumFixedTextBox.Text = string.Empty;
77          xAxisSecondaryTitleTextBox.Text = string.Empty;
78          xAxisSecondaryMinimumAutoRadioButton.Checked = false;
79          xAxisSecondaryMinimumFixedRadioButton.Checked = false;
80          xAxisSecondaryMinimumFixedTextBox.Text = string.Empty;
81          xAxisSecondaryMaximumAutoRadioButton.Checked = false;
82          xAxisSecondaryMaximumFixedRadioButton.Checked = false;
83          xAxisSecondaryMaximumFixedTextBox.Text = string.Empty;
84
85          yAxisPrimaryTitleTextBox.Text = string.Empty;
86          yAxisPrimaryMinimumAutoRadioButton.Checked = false;
87          yAxisPrimaryMinimumFixedRadioButton.Checked = false;
88          yAxisPrimaryMinimumFixedTextBox.Text = string.Empty;
89          yAxisPrimaryMaximumAutoRadioButton.Checked = false;
90          yAxisPrimaryMaximumFixedRadioButton.Checked = false;
91          yAxisPrimaryMaximumFixedTextBox.Text = string.Empty;
92          yAxisSecondaryTitleTextBox.Text = string.Empty;
93          yAxisSecondaryMinimumAutoRadioButton.Checked = false;
94          yAxisSecondaryMinimumFixedRadioButton.Checked = false;
95          yAxisSecondaryMinimumFixedTextBox.Text = string.Empty;
96          yAxisSecondaryMaximumAutoRadioButton.Checked = false;
97          yAxisSecondaryMaximumFixedRadioButton.Checked = false;
98          yAxisSecondaryMaximumFixedTextBox.Text = string.Empty;
99        } else {
100          titleFontLabel.Text = "( " + FormatFont(Content.TitleFont) + " )";
101          axisFontLabel.Text = "( " + FormatFont(Content.AxisTitleFont) + " )";
102          titleTextBox.Text = Content.Title;
103
104          xAxisPrimaryTitleTextBox.Text = Content.XAxisTitle;
105          xAxisPrimaryMinimumAutoRadioButton.Checked = Content.XAxisMinimumAuto;
106          xAxisPrimaryMinimumFixedRadioButton.Checked = !Content.XAxisMinimumAuto;
107          xAxisPrimaryMinimumFixedTextBox.Text = Content.XAxisMinimumFixedValue.ToString();
108          xAxisPrimaryMaximumAutoRadioButton.Checked = Content.XAxisMaximumAuto;
109          xAxisPrimaryMaximumFixedRadioButton.Checked = !Content.XAxisMaximumAuto;
110          xAxisPrimaryMaximumFixedTextBox.Text = Content.XAxisMaximumFixedValue.ToString();
111          xAxisSecondaryTitleTextBox.Text = Content.SecondXAxisTitle;
112          xAxisSecondaryMinimumAutoRadioButton.Checked = Content.SecondXAxisMinimumAuto;
113          xAxisSecondaryMinimumFixedRadioButton.Checked = !Content.SecondXAxisMinimumAuto;
114          xAxisSecondaryMinimumFixedTextBox.Text = Content.SecondXAxisMinimumFixedValue.ToString();
115          xAxisSecondaryMaximumAutoRadioButton.Checked = Content.SecondXAxisMaximumAuto;
116          xAxisSecondaryMaximumFixedRadioButton.Checked = !Content.SecondXAxisMaximumAuto;
117          xAxisSecondaryMaximumFixedTextBox.Text = Content.SecondXAxisMaximumFixedValue.ToString();
118
119          yAxisPrimaryTitleTextBox.Text = Content.YAxisTitle;
120          yAxisPrimaryMinimumAutoRadioButton.Checked = Content.YAxisMinimumAuto;
121          yAxisPrimaryMinimumFixedRadioButton.Checked = !Content.YAxisMinimumAuto;
122          yAxisPrimaryMinimumFixedTextBox.Text = Content.YAxisMinimumFixedValue.ToString();
123          yAxisPrimaryMaximumAutoRadioButton.Checked = Content.YAxisMaximumAuto;
124          yAxisPrimaryMaximumFixedRadioButton.Checked = !Content.YAxisMaximumAuto;
125          yAxisPrimaryMaximumFixedTextBox.Text = Content.YAxisMaximumFixedValue.ToString();
126          yAxisSecondaryTitleTextBox.Text = Content.SecondYAxisTitle;
127          yAxisSecondaryMinimumAutoRadioButton.Checked = Content.SecondYAxisMinimumAuto;
128          yAxisSecondaryMinimumFixedRadioButton.Checked = !Content.SecondYAxisMinimumAuto;
129          yAxisSecondaryMinimumFixedTextBox.Text = Content.SecondYAxisMinimumFixedValue.ToString();
130          yAxisSecondaryMaximumAutoRadioButton.Checked = Content.SecondYAxisMaximumAuto;
131          yAxisSecondaryMaximumFixedRadioButton.Checked = !Content.SecondYAxisMaximumAuto;
132          yAxisSecondaryMaximumFixedTextBox.Text = Content.SecondYAxisMaximumFixedValue.ToString();
133        }
134      }
135      finally { SuppressEvents = false; }
136      SetEnabledStateOfControls();
137    }
138
139    protected virtual void SetEnabledStateOfControls() {
140      axisTabControl.Enabled = Content != null;
141      xAxisPrimaryMinimumFixedTextBox.Enabled = xAxisPrimaryMinimumFixedRadioButton.Checked;
142      xAxisPrimaryMaximumFixedTextBox.Enabled = xAxisPrimaryMaximumFixedRadioButton.Checked;
143      xAxisSecondaryMinimumFixedTextBox.Enabled = xAxisSecondaryMinimumFixedRadioButton.Checked;
144      xAxisSecondaryMaximumFixedTextBox.Enabled = xAxisSecondaryMaximumFixedRadioButton.Checked;
145
146      yAxisPrimaryMinimumFixedTextBox.Enabled = yAxisPrimaryMinimumFixedRadioButton.Checked;
147      yAxisPrimaryMaximumFixedTextBox.Enabled = yAxisPrimaryMaximumFixedRadioButton.Checked;
148      yAxisSecondaryMinimumFixedTextBox.Enabled = yAxisSecondaryMinimumFixedRadioButton.Checked;
149      yAxisSecondaryMaximumFixedTextBox.Enabled = yAxisSecondaryMaximumFixedRadioButton.Checked;
150    }
151
152    #region Event Handlers
153    private void yPrimaryTitleTextBox_Validated(object sender, System.EventArgs e) {
154      if (!SuppressEvents && Content != null) {
155        Content.YAxisTitle = yAxisPrimaryTitleTextBox.Text;
156      }
157    }
158
159    private void ySecondaryTitleTextBox_Validated(object sender, System.EventArgs e) {
160      if (!SuppressEvents && Content != null) {
161        Content.SecondYAxisTitle = yAxisSecondaryTitleTextBox.Text;
162      }
163    }
164
165    private void xPrimaryTitleTextBox_Validated(object sender, System.EventArgs e) {
166      if (!SuppressEvents && Content != null) {
167        Content.XAxisTitle = xAxisPrimaryTitleTextBox.Text;
168      }
169    }
170
171    private void xSecondaryTitleTextBox_Validated(object sender, System.EventArgs e) {
172      if (!SuppressEvents && Content != null) {
173        Content.SecondXAxisTitle = xAxisSecondaryTitleTextBox.Text;
174      }
175    }
176
177    private void xAxisPrimaryMinimumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
178      if (!SuppressEvents && Content != null) {
179        TextBox tb = (TextBox)sender;
180        double val;
181        if (double.TryParse(tb.Text, out val)) {
182          if (val >= Content.XAxisMaximumFixedValue) {
183            errorProvider.SetError(tb, "Number must be smaller than maximum.");
184            e.Cancel = true;
185          } else {
186            Content.XAxisMinimumFixedValue = val;
187            errorProvider.SetError(tb, string.Empty);
188          }
189        } else {
190          errorProvider.SetError(tb, "Not a valid number.");
191          e.Cancel = true;
192        }
193      }
194    }
195
196    private void xAxisPrimaryMaximumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
197      if (!SuppressEvents && Content != null) {
198        TextBox tb = (TextBox)sender;
199        double val;
200        if (double.TryParse(tb.Text, out val)) {
201          if (val <= Content.XAxisMinimumFixedValue) {
202            errorProvider.SetError(tb, "Number must be greater than minimum.");
203            e.Cancel = true;
204          } else {
205            Content.XAxisMaximumFixedValue = val;
206            errorProvider.SetError(tb, string.Empty);
207          }
208        } else {
209          errorProvider.SetError(tb, "Not a valid number.");
210          e.Cancel = true;
211        }
212      }
213    }
214
215    private void xAxisSecondaryMinimumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
216      if (!SuppressEvents && Content != null) {
217        TextBox tb = (TextBox)sender;
218        double val;
219        if (double.TryParse(tb.Text, out val)) {
220          if (val >= Content.SecondXAxisMaximumFixedValue) {
221            errorProvider.SetError(tb, "Number must be smaller than maximum.");
222            e.Cancel = true;
223          } else {
224            Content.SecondXAxisMinimumFixedValue = val;
225            errorProvider.SetError(tb, string.Empty);
226          }
227        } else {
228          errorProvider.SetError(tb, "Not a valid number.");
229          e.Cancel = true;
230        }
231      }
232    }
233
234    private void xAxisSecondaryMaximumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
235      if (!SuppressEvents && Content != null) {
236        TextBox tb = (TextBox)sender;
237        double val;
238        if (double.TryParse(tb.Text, out val)) {
239          if (val <= Content.SecondXAxisMinimumFixedValue) {
240            errorProvider.SetError(tb, "Number must be greater than minimum.");
241            e.Cancel = true;
242          } else {
243            Content.SecondXAxisMaximumFixedValue = val;
244            errorProvider.SetError(tb, string.Empty);
245          }
246        } else {
247          errorProvider.SetError(tb, "Not a valid number.");
248          e.Cancel = true;
249        }
250      }
251    }
252
253    private void yAxisPrimaryMinimumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
254      if (!SuppressEvents && Content != null) {
255        TextBox tb = (TextBox)sender;
256        double val;
257        if (double.TryParse(tb.Text, out val)) {
258          if (val >= Content.YAxisMaximumFixedValue) {
259            errorProvider.SetError(tb, "Number must be smaller than maximum.");
260            e.Cancel = true;
261          } else {
262            Content.YAxisMinimumFixedValue = val;
263            errorProvider.SetError(tb, string.Empty);
264          }
265        } else {
266          errorProvider.SetError(tb, "Not a valid number.");
267          e.Cancel = true;
268        }
269      }
270    }
271
272    private void yAxisPrimaryMaximumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
273      if (!SuppressEvents && Content != null) {
274        TextBox tb = (TextBox)sender;
275        double val;
276        if (double.TryParse(tb.Text, out val)) {
277          if (val <= Content.YAxisMinimumFixedValue) {
278            errorProvider.SetError(tb, "Number must be greater than minimum.");
279            e.Cancel = true;
280          } else {
281            Content.YAxisMaximumFixedValue = val;
282            errorProvider.SetError(tb, string.Empty);
283          }
284        } else {
285          errorProvider.SetError(tb, "Not a valid number.");
286          e.Cancel = true;
287        }
288      }
289    }
290
291    private void yAxisSecondaryMinimumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
292      if (!SuppressEvents && Content != null) {
293        TextBox tb = (TextBox)sender;
294        double val;
295        if (double.TryParse(tb.Text, out val)) {
296          if (val >= Content.SecondYAxisMaximumFixedValue) {
297            errorProvider.SetError(tb, "Number must be smaller than maximum.");
298            e.Cancel = true;
299          } else {
300            Content.SecondYAxisMinimumFixedValue = val;
301            errorProvider.SetError(tb, string.Empty);
302          }
303        } else {
304          errorProvider.SetError(tb, "Not a valid number.");
305          e.Cancel = true;
306        }
307      }
308    }
309
310    private void yAxisSecondaryMaximumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
311      if (!SuppressEvents && Content != null) {
312        TextBox tb = (TextBox)sender;
313        double val;
314        if (double.TryParse(tb.Text, out val)) {
315          if (val <= Content.SecondYAxisMinimumFixedValue) {
316            errorProvider.SetError(tb, "Number must be greater than minimum.");
317            e.Cancel = true;
318          } else {
319            Content.SecondYAxisMaximumFixedValue = val;
320            errorProvider.SetError(tb, string.Empty);
321          }
322        } else {
323          errorProvider.SetError(tb, "Not a valid number.");
324          e.Cancel = true;
325        }
326      }
327    }
328
329    private void xAxisPrimaryMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
330      if (!SuppressEvents && Content != null) {
331        SuppressEvents = true;
332        try {
333          Content.XAxisMinimumAuto = xAxisPrimaryMinimumAutoRadioButton.Checked;
334          if (Content.XAxisMinimumAuto) xAxisPrimaryMinimumFixedTextBox.Text = double.NaN.ToString();
335        }
336        finally { SuppressEvents = false; }
337        SetEnabledStateOfControls();
338      }
339    }
340
341    private void xAxisPrimaryMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
342      if (!SuppressEvents && Content != null) {
343        SuppressEvents = true;
344        try {
345          Content.XAxisMaximumAuto = xAxisPrimaryMaximumAutoRadioButton.Checked;
346          if (Content.XAxisMaximumAuto) xAxisPrimaryMaximumFixedTextBox.Text = double.NaN.ToString();
347        }
348        finally { SuppressEvents = false; }
349        SetEnabledStateOfControls();
350      }
351    }
352
353    private void xAxisSecondaryMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
354      if (!SuppressEvents && Content != null) {
355        SuppressEvents = true;
356        try {
357          Content.SecondXAxisMinimumAuto = xAxisSecondaryMinimumAutoRadioButton.Checked;
358          if (Content.SecondXAxisMinimumAuto) xAxisSecondaryMinimumFixedTextBox.Text = double.NaN.ToString();
359        }
360        finally { SuppressEvents = false; }
361        SetEnabledStateOfControls();
362      }
363    }
364
365    private void xAxisSecondaryMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
366      if (!SuppressEvents && Content != null) {
367        SuppressEvents = true;
368        try {
369          Content.SecondXAxisMaximumAuto = xAxisSecondaryMaximumAutoRadioButton.Checked;
370          if (Content.SecondXAxisMaximumAuto) xAxisSecondaryMaximumFixedTextBox.Text = double.NaN.ToString();
371        }
372        finally { SuppressEvents = false; }
373        SetEnabledStateOfControls();
374      }
375    }
376
377    private void yAxisPrimaryMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
378      if (!SuppressEvents && Content != null) {
379        SuppressEvents = true;
380        try {
381          Content.YAxisMinimumAuto = yAxisPrimaryMinimumAutoRadioButton.Checked;
382          if (Content.YAxisMinimumAuto) yAxisPrimaryMinimumFixedTextBox.Text = double.NaN.ToString();
383        }
384        finally { SuppressEvents = false; }
385        SetEnabledStateOfControls();
386      }
387    }
388
389    private void yAxisPrimaryMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
390      if (!SuppressEvents && Content != null) {
391        SuppressEvents = true;
392        try {
393          Content.YAxisMaximumAuto = yAxisPrimaryMaximumAutoRadioButton.Checked;
394          if (Content.YAxisMaximumAuto) yAxisPrimaryMaximumFixedTextBox.Text = double.NaN.ToString();
395        }
396        finally { SuppressEvents = false; }
397        SetEnabledStateOfControls();
398      }
399    }
400
401    private void yAxisSecondaryMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
402      if (!SuppressEvents && Content != null) {
403        SuppressEvents = true;
404        try {
405          Content.SecondYAxisMinimumAuto = yAxisSecondaryMinimumAutoRadioButton.Checked;
406          if (Content.SecondYAxisMinimumAuto) yAxisSecondaryMinimumFixedTextBox.Text = double.NaN.ToString();
407        }
408        finally { SuppressEvents = false; }
409        SetEnabledStateOfControls();
410      }
411    }
412
413    private void yAxisSecondaryMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
414      if (!SuppressEvents && Content != null) {
415        SuppressEvents = true;
416        try {
417          Content.SecondYAxisMaximumAuto = yAxisSecondaryMaximumAutoRadioButton.Checked;
418          if (Content.SecondYAxisMaximumAuto) yAxisSecondaryMaximumFixedTextBox.Text = double.NaN.ToString();
419        }
420        finally { SuppressEvents = false; }
421        SetEnabledStateOfControls();
422      }
423    }
424
425    private void titleFontButton_Click(object sender, System.EventArgs e) {
426      titleFontDialog.Font = Content.TitleFont;
427      titleFontDialog.Color = Content.TitleColor;
428      if (titleFontDialog.ShowDialog() == DialogResult.OK) {
429        Content.TitleFont = titleFontDialog.Font;
430        Content.TitleColor = titleFontDialog.Color;
431        titleFontLabel.Text = "( " + FormatFont(Content.TitleFont) + " )";
432      }
433    }
434
435    private void axisFontButton_Click(object sender, System.EventArgs e) {
436      axisFontDialog.Font = Content.AxisTitleFont;
437      axisFontDialog.Color = Content.AxisTitleColor;
438      if (axisFontDialog.ShowDialog() == DialogResult.OK) {
439        Content.AxisTitleFont = axisFontDialog.Font;
440        Content.AxisTitleColor = axisFontDialog.Color;
441        axisFontLabel.Text = "( " + FormatFont(Content.AxisTitleFont) + " )";
442      }
443    }
444
445    private void titleTextBox_Validated(object sender, System.EventArgs e) {
446      if (!SuppressEvents && Content != null) {
447        Content.Title = titleTextBox.Text;
448      }
449    }
450    #endregion
451
452    private string FormatFont(Font f) {
453      if (f == null) return "default";
454      else return f.Name + ", " + f.SizeInPoints.ToString() + "pt, " + f.Style.ToString();
455    }
456  }
457}
Note: See TracBrowser for help on using the repository browser.