Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis.Views/3.3/DataRowVisualPropertiesControl.cs @ 14185

Last change on this file since 14185 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 7.7 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.Drawing;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Analysis.Views {
29  [View("DataRow Visual Properties")]
30  public partial class DataRowVisualPropertiesControl : UserControl {
31    protected bool SuppressEvents { get; set; }
32
33    private DataRowVisualProperties content;
34    public DataRowVisualProperties Content {
35      get { return content; }
36      set {
37        bool changed = (value != content);
38        content = value;
39        if (changed) OnContentChanged();
40      }
41    }
42
43    public DataRowVisualPropertiesControl() {
44      InitializeComponent();
45      chartTypeComboBox.DataSource = Enum.GetValues(typeof(DataRowVisualProperties.DataRowChartType));
46      lineStyleComboBox.DataSource = Enum.GetValues(typeof(DataRowVisualProperties.DataRowLineStyle));
47      SetEnabledStateOfControls();
48    }
49
50    protected virtual void OnContentChanged() {
51      SuppressEvents = true;
52      try {
53        if (Content == null) {
54          chartTypeComboBox.SelectedIndex = -1;
55          colorButton.BackColor = SystemColors.Control;
56          colorButton.Text = "?";
57          yAxisPrimaryRadioButton.Checked = false;
58          yAxisSecondaryRadioButton.Checked = false;
59          xAxisPrimaryRadioButton.Checked = false;
60          xAxisSecondaryRadioButton.Checked = false;
61          lineStyleComboBox.SelectedIndex = -1;
62          startIndexZeroCheckBox.Checked = false;
63          lineWidthNumericUpDown.Value = 1;
64          binsNumericUpDown.Value = 1;
65          binsApproximatelyRadioButton.Checked = false;
66          binsExactRadioButton.Checked = false;
67          displayNameTextBox.Text = String.Empty;
68        } else {
69          chartTypeComboBox.SelectedItem = Content.ChartType;
70          if (Content.Color.IsEmpty) {
71            colorButton.BackColor = SystemColors.Control;
72            colorButton.Text = "?";
73          } else {
74            colorButton.BackColor = Content.Color;
75            colorButton.Text = String.Empty;
76          }
77          yAxisPrimaryRadioButton.Checked = !Content.SecondYAxis;
78          yAxisSecondaryRadioButton.Checked = Content.SecondYAxis;
79          xAxisPrimaryRadioButton.Checked = !Content.SecondXAxis;
80          xAxisSecondaryRadioButton.Checked = Content.SecondXAxis;
81          lineStyleComboBox.SelectedItem = Content.LineStyle;
82          startIndexZeroCheckBox.Checked = Content.StartIndexZero;
83          if (Content.LineWidth < lineWidthNumericUpDown.Minimum)
84            lineWidthNumericUpDown.Value = lineWidthNumericUpDown.Minimum;
85          else if (Content.LineWidth > lineWidthNumericUpDown.Maximum)
86            lineWidthNumericUpDown.Value = lineWidthNumericUpDown.Maximum;
87          else lineWidthNumericUpDown.Value = Content.LineWidth;
88          if (Content.Bins < binsNumericUpDown.Minimum)
89            binsNumericUpDown.Value = binsNumericUpDown.Minimum;
90          else if (Content.Bins > binsNumericUpDown.Maximum)
91            binsNumericUpDown.Value = binsNumericUpDown.Maximum;
92          else binsNumericUpDown.Value = Content.Bins;
93          binsApproximatelyRadioButton.Checked = !Content.ExactBins;
94          binsExactRadioButton.Checked = Content.ExactBins;
95          displayNameTextBox.Text = Content.DisplayName;
96        }
97      } finally { SuppressEvents = false; }
98      SetEnabledStateOfControls();
99    }
100
101    protected virtual void SetEnabledStateOfControls() {
102      commonGroupBox.Enabled = Content != null;
103      lineChartGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Line;
104      histoGramGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Histogram;
105    }
106
107    #region Event Handlers
108    private void chartTypeComboBox_SelectedValueChanged(object sender, EventArgs e) {
109      if (!SuppressEvents && Content != null) {
110        DataRowVisualProperties.DataRowChartType selected = (DataRowVisualProperties.DataRowChartType)chartTypeComboBox.SelectedValue;
111        Content.ChartType = selected;
112        if (Content.ChartType != selected) {
113          MessageBox.Show("There may be incompatibilities with other series or the data is not suited to be displayed as " + selected.ToString() + ".", "Failed to set type to " + selected.ToString());
114          SuppressEvents = true;
115          try {
116            chartTypeComboBox.SelectedItem = Content.ChartType;
117          } finally { SuppressEvents = false; }
118        }
119        SetEnabledStateOfControls();
120      }
121    }
122
123    private void colorButton_Click(object sender, EventArgs e) {
124      if (colorDialog.ShowDialog() == DialogResult.OK) {
125        Content.Color = colorDialog.Color;
126        colorButton.BackColor = Content.Color;
127        colorButton.Text = String.Empty;
128      }
129    }
130
131    private void yAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
132      if (!SuppressEvents && Content != null) {
133        SuppressEvents = true;
134        try {
135          Content.SecondYAxis = yAxisSecondaryRadioButton.Checked;
136        } finally { SuppressEvents = false; }
137      }
138    }
139
140    private void xAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
141      if (!SuppressEvents && Content != null) {
142        SuppressEvents = true;
143        try {
144          Content.SecondXAxis = xAxisSecondaryRadioButton.Checked;
145        } finally { SuppressEvents = false; }
146      }
147    }
148
149    private void lineStyleComboBox_SelectedValueChanged(object sender, EventArgs e) {
150      if (!SuppressEvents && Content != null) {
151        Content.LineStyle = (DataRowVisualProperties.DataRowLineStyle)lineStyleComboBox.SelectedValue;
152      }
153    }
154
155    private void startIndexZeroCheckBox_CheckedChanged(object sender, EventArgs e) {
156      if (!SuppressEvents && Content != null) {
157        Content.StartIndexZero = startIndexZeroCheckBox.Checked;
158      }
159    }
160
161    private void lineWidthNumericUpDown_ValueChanged(object sender, EventArgs e) {
162      if (!SuppressEvents && Content != null) {
163        Content.LineWidth = (int)lineWidthNumericUpDown.Value;
164      }
165    }
166
167    private void binsNumericUpDown_ValueChanged(object sender, EventArgs e) {
168      if (!SuppressEvents && Content != null) {
169        Content.Bins = (int)binsNumericUpDown.Value;
170      }
171    }
172
173    private void binNumberRadioButton_CheckedChanged(object sender, EventArgs e) {
174      if (!SuppressEvents && Content != null) {
175        SuppressEvents = true;
176        try {
177          Content.ExactBins = binsExactRadioButton.Checked;
178        } finally { SuppressEvents = false; }
179      }
180    }
181
182    private void displayNameTextBox_Validated(object sender, EventArgs e) {
183      if (!SuppressEvents && Content != null) {
184        SuppressEvents = true;
185        try {
186          Content.DisplayName = displayNameTextBox.Text;
187        } finally { SuppressEvents = false; }
188      }
189    }
190    #endregion
191  }
192}
Note: See TracBrowser for help on using the repository browser.