Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Analysis.Views/3.3/DataTableVisualPropertiesControl.cs @ 10355

Last change on this file since 10355 was 6760, checked in by epitzer, 13 years ago

#1530 integrate changes from trunk

File size: 18.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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    }
45
46    protected virtual void OnContentChanged() {
47      SuppressEvents = true;
48      try {
49        if (Content == null) {
50          titleFontLabel.Text = "(  )";
51          axisFontLabel.Text = "(  )";
52
53          xAxisPrimaryTitleTextBox.Text = string.Empty;
54          xAxisPrimaryMinimumAutoRadioButton.Checked = false;
55          xAxisPrimaryMinimumFixedRadioButton.Checked = false;
56          xAxisPrimaryMinimumFixedTextBox.Text = string.Empty;
57          xAxisPrimaryMaximumAutoRadioButton.Checked = false;
58          xAxisPrimaryMaximumFixedRadioButton.Checked = false;
59          xAxisPrimaryMaximumFixedTextBox.Text = string.Empty;
60          xAxisSecondaryTitleTextBox.Text = string.Empty;
61          xAxisSecondaryMinimumAutoRadioButton.Checked = false;
62          xAxisSecondaryMinimumFixedRadioButton.Checked = false;
63          xAxisSecondaryMinimumFixedTextBox.Text = string.Empty;
64          xAxisSecondaryMaximumAutoRadioButton.Checked = false;
65          xAxisSecondaryMaximumFixedRadioButton.Checked = false;
66          xAxisSecondaryMaximumFixedTextBox.Text = string.Empty;
67
68          yAxisPrimaryTitleTextBox.Text = string.Empty;
69          yAxisPrimaryMinimumAutoRadioButton.Checked = false;
70          yAxisPrimaryMinimumFixedRadioButton.Checked = false;
71          yAxisPrimaryMinimumFixedTextBox.Text = string.Empty;
72          yAxisPrimaryMaximumAutoRadioButton.Checked = false;
73          yAxisPrimaryMaximumFixedRadioButton.Checked = false;
74          yAxisPrimaryMaximumFixedTextBox.Text = string.Empty;
75          yAxisSecondaryTitleTextBox.Text = string.Empty;
76          yAxisSecondaryMinimumAutoRadioButton.Checked = false;
77          yAxisSecondaryMinimumFixedRadioButton.Checked = false;
78          yAxisSecondaryMinimumFixedTextBox.Text = string.Empty;
79          yAxisSecondaryMaximumAutoRadioButton.Checked = false;
80          yAxisSecondaryMaximumFixedRadioButton.Checked = false;
81          yAxisSecondaryMaximumFixedTextBox.Text = string.Empty;
82        } else {
83          titleFontLabel.Text = "( " + FormatFont(Content.TitleFont) + " )";
84          axisFontLabel.Text = "( " + FormatFont(Content.AxisTitleFont) + " )";
85
86          xAxisPrimaryTitleTextBox.Text = Content.XAxisTitle;
87          xAxisPrimaryMinimumAutoRadioButton.Checked = Content.XAxisMinimumAuto;
88          xAxisPrimaryMinimumFixedRadioButton.Checked = !Content.XAxisMinimumAuto;
89          xAxisPrimaryMinimumFixedTextBox.Text = Content.XAxisMinimumFixedValue.ToString();
90          xAxisPrimaryMaximumAutoRadioButton.Checked = Content.XAxisMaximumAuto;
91          xAxisPrimaryMaximumFixedRadioButton.Checked = !Content.XAxisMaximumAuto;
92          xAxisPrimaryMaximumFixedTextBox.Text = Content.XAxisMaximumFixedValue.ToString();
93          xAxisSecondaryTitleTextBox.Text = Content.SecondXAxisTitle;
94          xAxisSecondaryMinimumAutoRadioButton.Checked = Content.SecondXAxisMinimumAuto;
95          xAxisSecondaryMinimumFixedRadioButton.Checked = !Content.SecondXAxisMinimumAuto;
96          xAxisSecondaryMinimumFixedTextBox.Text = Content.SecondXAxisMinimumFixedValue.ToString();
97          xAxisSecondaryMaximumAutoRadioButton.Checked = Content.SecondXAxisMaximumAuto;
98          xAxisSecondaryMaximumFixedRadioButton.Checked = !Content.SecondXAxisMaximumAuto;
99          xAxisSecondaryMaximumFixedTextBox.Text = Content.SecondXAxisMaximumFixedValue.ToString();
100
101          yAxisPrimaryTitleTextBox.Text = Content.YAxisTitle;
102          yAxisPrimaryMinimumAutoRadioButton.Checked = Content.YAxisMinimumAuto;
103          yAxisPrimaryMinimumFixedRadioButton.Checked = !Content.YAxisMinimumAuto;
104          yAxisPrimaryMinimumFixedTextBox.Text = Content.YAxisMinimumFixedValue.ToString();
105          yAxisPrimaryMaximumAutoRadioButton.Checked = Content.YAxisMaximumAuto;
106          yAxisPrimaryMaximumFixedRadioButton.Checked = !Content.YAxisMaximumAuto;
107          yAxisPrimaryMaximumFixedTextBox.Text = Content.YAxisMaximumFixedValue.ToString();
108          yAxisSecondaryTitleTextBox.Text = Content.SecondYAxisTitle;
109          yAxisSecondaryMinimumAutoRadioButton.Checked = Content.SecondYAxisMinimumAuto;
110          yAxisSecondaryMinimumFixedRadioButton.Checked = !Content.SecondYAxisMinimumAuto;
111          yAxisSecondaryMinimumFixedTextBox.Text = Content.SecondYAxisMinimumFixedValue.ToString();
112          yAxisSecondaryMaximumAutoRadioButton.Checked = Content.SecondYAxisMaximumAuto;
113          yAxisSecondaryMaximumFixedRadioButton.Checked = !Content.SecondYAxisMaximumAuto;
114          yAxisSecondaryMaximumFixedTextBox.Text = Content.SecondYAxisMaximumFixedValue.ToString();
115        }
116      } finally { SuppressEvents = false; }
117      SetEnabledStateOfControls();
118    }
119
120    protected virtual void SetEnabledStateOfControls() {
121      axisTabControl.Enabled = Content != null;
122      xAxisPrimaryMinimumFixedTextBox.Enabled = xAxisPrimaryMinimumFixedRadioButton.Checked;
123      xAxisPrimaryMaximumFixedTextBox.Enabled = xAxisPrimaryMaximumFixedRadioButton.Checked;
124      xAxisSecondaryMinimumFixedTextBox.Enabled = xAxisSecondaryMinimumFixedRadioButton.Checked;
125      xAxisSecondaryMaximumFixedTextBox.Enabled = xAxisSecondaryMaximumFixedRadioButton.Checked;
126
127      yAxisPrimaryMinimumFixedTextBox.Enabled = yAxisPrimaryMinimumFixedRadioButton.Checked;
128      yAxisPrimaryMaximumFixedTextBox.Enabled = yAxisPrimaryMaximumFixedRadioButton.Checked;
129      yAxisSecondaryMinimumFixedTextBox.Enabled = yAxisSecondaryMinimumFixedRadioButton.Checked;
130      yAxisSecondaryMaximumFixedTextBox.Enabled = yAxisSecondaryMaximumFixedRadioButton.Checked;
131    }
132
133    #region Event Handlers
134    private void yPrimaryTitleTextBox_Validated(object sender, System.EventArgs e) {
135      if (!SuppressEvents && Content != null) {
136        Content.YAxisTitle = yAxisPrimaryTitleTextBox.Text;
137      }
138    }
139
140    private void ySecondaryTitleTextBox_Validated(object sender, System.EventArgs e) {
141      if (!SuppressEvents && Content != null) {
142        Content.SecondYAxisTitle = yAxisSecondaryTitleTextBox.Text;
143      }
144    }
145
146    private void xPrimaryTitleTextBox_Validated(object sender, System.EventArgs e) {
147      if (!SuppressEvents && Content != null) {
148        Content.XAxisTitle = xAxisPrimaryTitleTextBox.Text;
149      }
150    }
151
152    private void xSecondaryTitleTextBox_Validated(object sender, System.EventArgs e) {
153      if (!SuppressEvents && Content != null) {
154        Content.SecondXAxisTitle = xAxisSecondaryTitleTextBox.Text;
155      }
156    }
157
158    private void xAxisPrimaryMinimumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
159      if (!SuppressEvents && Content != null) {
160        TextBox tb = (TextBox)sender;
161        double val;
162        if (double.TryParse(tb.Text, out val)) {
163          if (val >= Content.XAxisMaximumFixedValue) {
164            errorProvider.SetError(tb, "Number must be smaller than maximum.");
165            e.Cancel = true;
166          } else {
167            Content.XAxisMinimumFixedValue = val;
168            errorProvider.SetError(tb, string.Empty);
169          }
170        } else {
171          errorProvider.SetError(tb, "Not a valid number.");
172          e.Cancel = true;
173        }
174      }
175    }
176
177    private void xAxisPrimaryMaximumFixedTextBox_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.XAxisMinimumFixedValue) {
183            errorProvider.SetError(tb, "Number must be greater than minimum.");
184            e.Cancel = true;
185          } else {
186            Content.XAxisMaximumFixedValue = 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 xAxisSecondaryMinimumFixedTextBox_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.SecondXAxisMaximumFixedValue) {
202            errorProvider.SetError(tb, "Number must be smaller than maximum.");
203            e.Cancel = true;
204          } else {
205            Content.SecondXAxisMinimumFixedValue = 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 xAxisSecondaryMaximumFixedTextBox_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.SecondXAxisMinimumFixedValue) {
221            errorProvider.SetError(tb, "Number must be greater than minimum.");
222            e.Cancel = true;
223          } else {
224            Content.SecondXAxisMaximumFixedValue = 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 yAxisPrimaryMinimumFixedTextBox_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.YAxisMaximumFixedValue) {
240            errorProvider.SetError(tb, "Number must be smaller than maximum.");
241            e.Cancel = true;
242          } else {
243            Content.YAxisMinimumFixedValue = 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 yAxisPrimaryMaximumFixedTextBox_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.YAxisMinimumFixedValue) {
259            errorProvider.SetError(tb, "Number must be greater than minimum.");
260            e.Cancel = true;
261          } else {
262            Content.YAxisMaximumFixedValue = 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 yAxisSecondaryMinimumFixedTextBox_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.SecondYAxisMaximumFixedValue) {
278            errorProvider.SetError(tb, "Number must be smaller than maximum.");
279            e.Cancel = true;
280          } else {
281            Content.SecondYAxisMinimumFixedValue = 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 yAxisSecondaryMaximumFixedTextBox_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.SecondYAxisMinimumFixedValue) {
297            errorProvider.SetError(tb, "Number must be greater than minimum.");
298            e.Cancel = true;
299          } else {
300            Content.SecondYAxisMaximumFixedValue = 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 xAxisPrimaryMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
311      if (!SuppressEvents && Content != null) {
312        SuppressEvents = true;
313        try {
314          Content.XAxisMinimumAuto = xAxisPrimaryMinimumAutoRadioButton.Checked;
315          if (Content.XAxisMinimumAuto) xAxisPrimaryMinimumFixedTextBox.Text = double.NaN.ToString();
316        } finally { SuppressEvents = false; }
317        SetEnabledStateOfControls();
318      }
319    }
320
321    private void xAxisPrimaryMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
322      if (!SuppressEvents && Content != null) {
323        SuppressEvents = true;
324        try {
325          Content.XAxisMaximumAuto = xAxisPrimaryMaximumAutoRadioButton.Checked;
326          if (Content.XAxisMaximumAuto) xAxisPrimaryMaximumFixedTextBox.Text = double.NaN.ToString();
327        } finally { SuppressEvents = false; }
328        SetEnabledStateOfControls();
329      }
330    }
331
332    private void xAxisSecondaryMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
333      if (!SuppressEvents && Content != null) {
334        SuppressEvents = true;
335        try {
336          Content.SecondXAxisMinimumAuto = xAxisSecondaryMinimumAutoRadioButton.Checked;
337          if (Content.SecondXAxisMinimumAuto) xAxisSecondaryMinimumFixedTextBox.Text = double.NaN.ToString();
338        } finally { SuppressEvents = false; }
339        SetEnabledStateOfControls();
340      }
341    }
342
343    private void xAxisSecondaryMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
344      if (!SuppressEvents && Content != null) {
345        SuppressEvents = true;
346        try {
347          Content.SecondXAxisMaximumAuto = xAxisSecondaryMaximumAutoRadioButton.Checked;
348          if (Content.SecondXAxisMaximumAuto) xAxisSecondaryMaximumFixedTextBox.Text = double.NaN.ToString();
349        } finally { SuppressEvents = false; }
350        SetEnabledStateOfControls();
351      }
352    }
353
354    private void yAxisPrimaryMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
355      if (!SuppressEvents && Content != null) {
356        SuppressEvents = true;
357        try {
358          Content.YAxisMinimumAuto = yAxisPrimaryMinimumAutoRadioButton.Checked;
359          if (Content.YAxisMinimumAuto) yAxisPrimaryMinimumFixedTextBox.Text = double.NaN.ToString();
360        } finally { SuppressEvents = false; }
361        SetEnabledStateOfControls();
362      }
363    }
364
365    private void yAxisPrimaryMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
366      if (!SuppressEvents && Content != null) {
367        SuppressEvents = true;
368        try {
369          Content.YAxisMaximumAuto = yAxisPrimaryMaximumAutoRadioButton.Checked;
370          if (Content.YAxisMaximumAuto) yAxisPrimaryMaximumFixedTextBox.Text = double.NaN.ToString();
371        } finally { SuppressEvents = false; }
372        SetEnabledStateOfControls();
373      }
374    }
375
376    private void yAxisSecondaryMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
377      if (!SuppressEvents && Content != null) {
378        SuppressEvents = true;
379        try {
380          Content.SecondYAxisMinimumAuto = yAxisSecondaryMinimumAutoRadioButton.Checked;
381          if (Content.SecondYAxisMinimumAuto) yAxisSecondaryMinimumFixedTextBox.Text = double.NaN.ToString();
382        } finally { SuppressEvents = false; }
383        SetEnabledStateOfControls();
384      }
385    }
386
387    private void yAxisSecondaryMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
388      if (!SuppressEvents && Content != null) {
389        SuppressEvents = true;
390        try {
391          Content.SecondYAxisMaximumAuto = yAxisSecondaryMaximumAutoRadioButton.Checked;
392          if (Content.SecondYAxisMaximumAuto) yAxisSecondaryMaximumFixedTextBox.Text = double.NaN.ToString();
393        } finally { SuppressEvents = false; }
394        SetEnabledStateOfControls();
395      }
396    }
397
398    private void titleFontButton_Click(object sender, System.EventArgs e) {
399      titleFontDialog.Font = Content.TitleFont;
400      titleFontDialog.Color = Content.TitleColor;
401      if (titleFontDialog.ShowDialog() == DialogResult.OK) {
402        Content.TitleFont = titleFontDialog.Font;
403        Content.TitleColor = titleFontDialog.Color;
404        titleFontLabel.Text = "( " + FormatFont(Content.TitleFont) + " )";
405      }
406    }
407
408    private void axisFontButton_Click(object sender, System.EventArgs e) {
409      axisFontDialog.Font = Content.AxisTitleFont;
410      axisFontDialog.Color = Content.AxisTitleColor;
411      if (axisFontDialog.ShowDialog() == DialogResult.OK) {
412        Content.AxisTitleFont = axisFontDialog.Font;
413        Content.AxisTitleColor = axisFontDialog.Color;
414        axisFontLabel.Text = "( " + FormatFont(Content.AxisTitleFont) + " )";
415      }
416    }
417    #endregion
418
419    private string FormatFont(Font f) {
420      if (f == null) return string.Empty;
421      else return f.Name + ", " + f.SizeInPoints.ToString() + "pt, " + f.Style.ToString();
422    }
423  }
424}
Note: See TracBrowser for help on using the repository browser.