Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2389-EpsLexicase/HeuristicLab.Analysis.Views/3.3/DataRowVisualPropertiesControl.cs @ 17244

Last change on this file since 17244 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 7.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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      clearColorButton.BackColor = Color.Transparent;
49      clearColorButton.BackgroundImage = VSImageLibrary.Delete;
50      SetEnabledStateOfControls();
51    }
52
53    protected virtual void OnContentChanged() {
54      SuppressEvents = true;
55      try {
56        if (Content == null) {
57          chartTypeComboBox.SelectedIndex = -1;
58          colorButton.BackColor = SystemColors.Control;
59          colorButton.Text = "?";
60          yAxisPrimaryRadioButton.Checked = false;
61          yAxisSecondaryRadioButton.Checked = false;
62          xAxisPrimaryRadioButton.Checked = false;
63          xAxisSecondaryRadioButton.Checked = false;
64          lineStyleComboBox.SelectedIndex = -1;
65          startIndexZeroCheckBox.Checked = false;
66          lineWidthNumericUpDown.Value = 1;
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          displayNameTextBox.Text = Content.DisplayName;
89          isVisibleInLegendCheckBox.Checked = Content.IsVisibleInLegend;
90        }
91      } finally { SuppressEvents = false; }
92      SetEnabledStateOfControls();
93    }
94
95    protected virtual void SetEnabledStateOfControls() {
96      commonGroupBox.Enabled = Content != null;
97      clearColorButton.Visible = Content != null && !Content.Color.IsEmpty;
98      lineChartGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Line;
99      isVisibleInLegendCheckBox.Enabled = Content != null;
100    }
101
102    #region Event Handlers
103    private void chartTypeComboBox_SelectedValueChanged(object sender, EventArgs e) {
104      if (!SuppressEvents && Content != null) {
105        DataRowVisualProperties.DataRowChartType selected = (DataRowVisualProperties.DataRowChartType)chartTypeComboBox.SelectedValue;
106        Content.ChartType = selected;
107        if (Content.ChartType != selected) {
108          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());
109          SuppressEvents = true;
110          try {
111            chartTypeComboBox.SelectedItem = Content.ChartType;
112          } finally { SuppressEvents = false; }
113        }
114        SetEnabledStateOfControls();
115      }
116    }
117
118    private void colorButton_Click(object sender, EventArgs e) {
119      if (colorDialog.ShowDialog() == DialogResult.OK) {
120        Content.Color = colorDialog.Color;
121        colorButton.BackColor = Content.Color;
122        colorButton.Text = String.Empty;
123        clearColorButton.Visible = true;
124      }
125    }
126
127    private void clearColorButton_Click(object sender, EventArgs e) {
128      if (!SuppressEvents && Content != null) {
129        SuppressEvents = true;
130        try {
131          Content.Color = Color.Empty;
132          colorButton.BackColor = SystemColors.Control;
133          colorButton.Text = "?";
134          clearColorButton.Visible = false;
135        } finally { SuppressEvents = false; }
136      }
137    }
138
139    private void yAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
140      if (!SuppressEvents && Content != null) {
141        SuppressEvents = true;
142        try {
143          Content.SecondYAxis = yAxisSecondaryRadioButton.Checked;
144        } finally { SuppressEvents = false; }
145      }
146    }
147
148    private void xAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
149      if (!SuppressEvents && Content != null) {
150        SuppressEvents = true;
151        try {
152          Content.SecondXAxis = xAxisSecondaryRadioButton.Checked;
153        } finally { SuppressEvents = false; }
154      }
155    }
156
157    private void lineStyleComboBox_SelectedValueChanged(object sender, EventArgs e) {
158      if (!SuppressEvents && Content != null) {
159        Content.LineStyle = (DataRowVisualProperties.DataRowLineStyle)lineStyleComboBox.SelectedValue;
160      }
161    }
162
163    private void startIndexZeroCheckBox_CheckedChanged(object sender, EventArgs e) {
164      if (!SuppressEvents && Content != null) {
165        Content.StartIndexZero = startIndexZeroCheckBox.Checked;
166      }
167    }
168
169    private void lineWidthNumericUpDown_ValueChanged(object sender, EventArgs e) {
170      if (!SuppressEvents && Content != null) {
171        Content.LineWidth = (int)lineWidthNumericUpDown.Value;
172      }
173    }
174
175    private void displayNameTextBox_Validated(object sender, EventArgs e) {
176      if (!SuppressEvents && Content != null) {
177        SuppressEvents = true;
178        try {
179          Content.DisplayName = displayNameTextBox.Text;
180        } finally { SuppressEvents = false; }
181      }
182    }
183
184    private void isVisibleInLegendCheckBox_CheckedChanged(object sender, EventArgs e) {
185      if (!SuppressEvents && Content != null) {
186        Content.IsVisibleInLegend = isVisibleInLegendCheckBox.Checked;
187      }
188    }
189    #endregion
190  }
191}
Note: See TracBrowser for help on using the repository browser.