Free cookie consent management tool by TermsFeed Policy Generator

source: branches/symbreg-factors-2650/HeuristicLab.Analysis.Views/3.3/DataRowVisualPropertiesControl.cs @ 14791

Last change on this file since 14791 was 14589, checked in by gkronber, 8 years ago

#2650 merged r14548:14582 from trunk to to branch

File size: 9.3 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.Common.Resources;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28
29namespace HeuristicLab.Analysis.Views {
30  [View("DataRow Visual Properties")]
31  public partial class DataRowVisualPropertiesControl : UserControl {
32    protected bool SuppressEvents { get; set; }
33
34    private DataRowVisualProperties content;
35    public DataRowVisualProperties Content {
36      get { return content; }
37      set {
38        bool changed = (value != content);
39        content = value;
40        if (changed) OnContentChanged();
41      }
42    }
43
44    public DataRowVisualPropertiesControl() {
45      InitializeComponent();
46      chartTypeComboBox.DataSource = Enum.GetValues(typeof(DataRowVisualProperties.DataRowChartType));
47      lineStyleComboBox.DataSource = Enum.GetValues(typeof(DataRowVisualProperties.DataRowLineStyle));
48      aggregationComboBox.DataSource = Enum.GetValues(typeof(DataRowVisualProperties.DataRowHistogramAggregation));
49      clearColorButton.BackColor = Color.Transparent;
50      clearColorButton.BackgroundImage = VSImageLibrary.Delete;
51      SetEnabledStateOfControls();
52    }
53
54    protected virtual void OnContentChanged() {
55      SuppressEvents = true;
56      try {
57        if (Content == null) {
58          chartTypeComboBox.SelectedIndex = -1;
59          colorButton.BackColor = SystemColors.Control;
60          colorButton.Text = "?";
61          yAxisPrimaryRadioButton.Checked = false;
62          yAxisSecondaryRadioButton.Checked = false;
63          xAxisPrimaryRadioButton.Checked = false;
64          xAxisSecondaryRadioButton.Checked = false;
65          lineStyleComboBox.SelectedIndex = -1;
66          startIndexZeroCheckBox.Checked = false;
67          lineWidthNumericUpDown.Value = 1;
68          binsNumericUpDown.Value = 1;
69          binsApproximatelyRadioButton.Checked = false;
70          binsExactRadioButton.Checked = false;
71          aggregationComboBox.SelectedIndex = -1;
72          displayNameTextBox.Text = String.Empty;
73        } else {
74          chartTypeComboBox.SelectedItem = Content.ChartType;
75          if (Content.Color.IsEmpty) {
76            colorButton.BackColor = SystemColors.Control;
77            colorButton.Text = "?";
78          } else {
79            colorButton.BackColor = Content.Color;
80            colorButton.Text = String.Empty;
81          }
82          yAxisPrimaryRadioButton.Checked = !Content.SecondYAxis;
83          yAxisSecondaryRadioButton.Checked = Content.SecondYAxis;
84          xAxisPrimaryRadioButton.Checked = !Content.SecondXAxis;
85          xAxisSecondaryRadioButton.Checked = Content.SecondXAxis;
86          lineStyleComboBox.SelectedItem = Content.LineStyle;
87          startIndexZeroCheckBox.Checked = Content.StartIndexZero;
88          if (Content.LineWidth < lineWidthNumericUpDown.Minimum)
89            lineWidthNumericUpDown.Value = lineWidthNumericUpDown.Minimum;
90          else if (Content.LineWidth > lineWidthNumericUpDown.Maximum)
91            lineWidthNumericUpDown.Value = lineWidthNumericUpDown.Maximum;
92          else lineWidthNumericUpDown.Value = Content.LineWidth;
93          if (Content.Bins < binsNumericUpDown.Minimum)
94            binsNumericUpDown.Value = binsNumericUpDown.Minimum;
95          else if (Content.Bins > binsNumericUpDown.Maximum)
96            binsNumericUpDown.Value = binsNumericUpDown.Maximum;
97          else binsNumericUpDown.Value = Content.Bins;
98          binsApproximatelyRadioButton.Checked = !Content.ExactBins;
99          binsExactRadioButton.Checked = Content.ExactBins;
100          aggregationComboBox.SelectedItem = Content.Aggregation;
101          displayNameTextBox.Text = Content.DisplayName;
102          isVisibleInLegendCheckBox.Checked = Content.IsVisibleInLegend;
103        }
104      } finally { SuppressEvents = false; }
105      SetEnabledStateOfControls();
106    }
107
108    protected virtual void SetEnabledStateOfControls() {
109      commonGroupBox.Enabled = Content != null;
110      clearColorButton.Visible = Content != null && !Content.Color.IsEmpty;
111      lineChartGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Line;
112      histoGramGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Histogram;
113      isVisibleInLegendCheckBox.Enabled = Content != null;
114    }
115
116    #region Event Handlers
117    private void chartTypeComboBox_SelectedValueChanged(object sender, EventArgs e) {
118      if (!SuppressEvents && Content != null) {
119        DataRowVisualProperties.DataRowChartType selected = (DataRowVisualProperties.DataRowChartType)chartTypeComboBox.SelectedValue;
120        Content.ChartType = selected;
121        if (Content.ChartType != selected) {
122          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());
123          SuppressEvents = true;
124          try {
125            chartTypeComboBox.SelectedItem = Content.ChartType;
126          } finally { SuppressEvents = false; }
127        }
128        SetEnabledStateOfControls();
129      }
130    }
131
132    private void colorButton_Click(object sender, EventArgs e) {
133      if (colorDialog.ShowDialog() == DialogResult.OK) {
134        Content.Color = colorDialog.Color;
135        colorButton.BackColor = Content.Color;
136        colorButton.Text = String.Empty;
137        clearColorButton.Visible = true;
138      }
139    }
140
141    private void clearColorButton_Click(object sender, EventArgs e) {
142      if (!SuppressEvents && Content != null) {
143        SuppressEvents = true;
144        try {
145          Content.Color = Color.Empty;
146          colorButton.BackColor = SystemColors.Control;
147          colorButton.Text = "?";
148          clearColorButton.Visible = false;
149        } finally { SuppressEvents = false; }
150      }
151    }
152
153    private void yAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
154      if (!SuppressEvents && Content != null) {
155        SuppressEvents = true;
156        try {
157          Content.SecondYAxis = yAxisSecondaryRadioButton.Checked;
158        } finally { SuppressEvents = false; }
159      }
160    }
161
162    private void xAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
163      if (!SuppressEvents && Content != null) {
164        SuppressEvents = true;
165        try {
166          Content.SecondXAxis = xAxisSecondaryRadioButton.Checked;
167        } finally { SuppressEvents = false; }
168      }
169    }
170
171    private void lineStyleComboBox_SelectedValueChanged(object sender, EventArgs e) {
172      if (!SuppressEvents && Content != null) {
173        Content.LineStyle = (DataRowVisualProperties.DataRowLineStyle)lineStyleComboBox.SelectedValue;
174      }
175    }
176
177    private void startIndexZeroCheckBox_CheckedChanged(object sender, EventArgs e) {
178      if (!SuppressEvents && Content != null) {
179        Content.StartIndexZero = startIndexZeroCheckBox.Checked;
180      }
181    }
182
183    private void lineWidthNumericUpDown_ValueChanged(object sender, EventArgs e) {
184      if (!SuppressEvents && Content != null) {
185        Content.LineWidth = (int)lineWidthNumericUpDown.Value;
186      }
187    }
188
189    private void binsNumericUpDown_ValueChanged(object sender, EventArgs e) {
190      if (!SuppressEvents && Content != null) {
191        Content.Bins = (int)binsNumericUpDown.Value;
192      }
193    }
194
195    private void binNumberRadioButton_CheckedChanged(object sender, EventArgs e) {
196      if (!SuppressEvents && Content != null) {
197        SuppressEvents = true;
198        try {
199          Content.ExactBins = binsExactRadioButton.Checked;
200        } finally { SuppressEvents = false; }
201      }
202    }
203
204    private void aggregationComboBox_SelectedValueChanged(object sender, EventArgs e) {
205      if (!SuppressEvents && Content != null) {
206        SuppressEvents = true;
207        try {
208          Content.Aggregation = (DataRowVisualProperties.DataRowHistogramAggregation)aggregationComboBox.SelectedValue;
209        } finally { SuppressEvents = false; }
210      }
211    }
212
213    private void displayNameTextBox_Validated(object sender, EventArgs e) {
214      if (!SuppressEvents && Content != null) {
215        SuppressEvents = true;
216        try {
217          Content.DisplayName = displayNameTextBox.Text;
218        } finally { SuppressEvents = false; }
219      }
220    }
221
222    private void isVisibleInLegendCheckBox_CheckedChanged(object sender, EventArgs e) {
223      if (!SuppressEvents && Content != null) {
224        Content.IsVisibleInLegend = isVisibleInLegendCheckBox.Checked;
225      }
226    }
227    #endregion
228  }
229}
Note: See TracBrowser for help on using the repository browser.