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 |
|
---|
22 | using System;
|
---|
23 | using System.Drawing;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.MainForm;
|
---|
26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
27 |
|
---|
28 | namespace 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 | isVisibleInLegendCheckBox.Checked = Content.IsVisibleInLegend;
|
---|
97 | }
|
---|
98 | } finally { SuppressEvents = false; }
|
---|
99 | SetEnabledStateOfControls();
|
---|
100 | }
|
---|
101 |
|
---|
102 | protected virtual void SetEnabledStateOfControls() {
|
---|
103 | commonGroupBox.Enabled = Content != null;
|
---|
104 | lineChartGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Line;
|
---|
105 | histoGramGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Histogram;
|
---|
106 | isVisibleInLegendCheckBox.Enabled = Content != null;
|
---|
107 | }
|
---|
108 |
|
---|
109 | #region Event Handlers
|
---|
110 | private void chartTypeComboBox_SelectedValueChanged(object sender, EventArgs e) {
|
---|
111 | if (!SuppressEvents && Content != null) {
|
---|
112 | DataRowVisualProperties.DataRowChartType selected = (DataRowVisualProperties.DataRowChartType)chartTypeComboBox.SelectedValue;
|
---|
113 | Content.ChartType = selected;
|
---|
114 | if (Content.ChartType != selected) {
|
---|
115 | 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());
|
---|
116 | SuppressEvents = true;
|
---|
117 | try {
|
---|
118 | chartTypeComboBox.SelectedItem = Content.ChartType;
|
---|
119 | } finally { SuppressEvents = false; }
|
---|
120 | }
|
---|
121 | SetEnabledStateOfControls();
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void colorButton_Click(object sender, EventArgs e) {
|
---|
126 | if (colorDialog.ShowDialog() == DialogResult.OK) {
|
---|
127 | Content.Color = colorDialog.Color;
|
---|
128 | colorButton.BackColor = Content.Color;
|
---|
129 | colorButton.Text = String.Empty;
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | private void yAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
|
---|
134 | if (!SuppressEvents && Content != null) {
|
---|
135 | SuppressEvents = true;
|
---|
136 | try {
|
---|
137 | Content.SecondYAxis = yAxisSecondaryRadioButton.Checked;
|
---|
138 | } finally { SuppressEvents = false; }
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | private void xAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
|
---|
143 | if (!SuppressEvents && Content != null) {
|
---|
144 | SuppressEvents = true;
|
---|
145 | try {
|
---|
146 | Content.SecondXAxis = xAxisSecondaryRadioButton.Checked;
|
---|
147 | } finally { SuppressEvents = false; }
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | private void lineStyleComboBox_SelectedValueChanged(object sender, EventArgs e) {
|
---|
152 | if (!SuppressEvents && Content != null) {
|
---|
153 | Content.LineStyle = (DataRowVisualProperties.DataRowLineStyle)lineStyleComboBox.SelectedValue;
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | private void startIndexZeroCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
158 | if (!SuppressEvents && Content != null) {
|
---|
159 | Content.StartIndexZero = startIndexZeroCheckBox.Checked;
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | private void lineWidthNumericUpDown_ValueChanged(object sender, EventArgs e) {
|
---|
164 | if (!SuppressEvents && Content != null) {
|
---|
165 | Content.LineWidth = (int)lineWidthNumericUpDown.Value;
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | private void binsNumericUpDown_ValueChanged(object sender, EventArgs e) {
|
---|
170 | if (!SuppressEvents && Content != null) {
|
---|
171 | Content.Bins = (int)binsNumericUpDown.Value;
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | private void binNumberRadioButton_CheckedChanged(object sender, EventArgs e) {
|
---|
176 | if (!SuppressEvents && Content != null) {
|
---|
177 | SuppressEvents = true;
|
---|
178 | try {
|
---|
179 | Content.ExactBins = binsExactRadioButton.Checked;
|
---|
180 | } finally { SuppressEvents = false; }
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | private void displayNameTextBox_Validated(object sender, EventArgs e) {
|
---|
185 | if (!SuppressEvents && Content != null) {
|
---|
186 | SuppressEvents = true;
|
---|
187 | try {
|
---|
188 | Content.DisplayName = displayNameTextBox.Text;
|
---|
189 | } finally { SuppressEvents = false; }
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 | private void isVisibleInLegendCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
194 | if (!SuppressEvents && Content != null) {
|
---|
195 | Content.IsVisibleInLegend = isVisibleInLegendCheckBox.Checked;
|
---|
196 | }
|
---|
197 | }
|
---|
198 | #endregion
|
---|
199 | }
|
---|
200 | }
|
---|