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.Drawing;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using HeuristicLab.MainForm;
|
---|
25 | using HeuristicLab.MainForm.WindowsForms;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Analysis.Views {
|
---|
28 | [View("Scatter Plot Visual Properties")]
|
---|
29 | public partial class ScatterPlotVisualPropertiesControl : UserControl {
|
---|
30 | protected bool SuppressEvents { get; set; }
|
---|
31 |
|
---|
32 | private ScatterPlotVisualProperties content;
|
---|
33 | public ScatterPlotVisualProperties Content {
|
---|
34 | get { return content; }
|
---|
35 | set {
|
---|
36 | bool changed = (value != content);
|
---|
37 | content = value;
|
---|
38 | if (changed) OnContentChanged();
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | public ScatterPlotVisualPropertiesControl() {
|
---|
43 | InitializeComponent();
|
---|
44 | errorProvider.SetIconAlignment(xAxisMinimumFixedTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
45 | errorProvider.SetIconAlignment(xAxisMaximumFixedTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
46 | errorProvider.SetIconAlignment(yAxisMinimumFixedTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
47 | errorProvider.SetIconAlignment(yAxisMaximumFixedTextBox, ErrorIconAlignment.MiddleLeft);
|
---|
48 | errorProvider.SetIconPadding(xAxisMinimumFixedTextBox, 2);
|
---|
49 | errorProvider.SetIconPadding(xAxisMaximumFixedTextBox, 2);
|
---|
50 | errorProvider.SetIconPadding(yAxisMinimumFixedTextBox, 2);
|
---|
51 | errorProvider.SetIconPadding(yAxisMaximumFixedTextBox, 2);
|
---|
52 | }
|
---|
53 |
|
---|
54 | protected virtual void OnContentChanged() {
|
---|
55 | SuppressEvents = true;
|
---|
56 | try {
|
---|
57 | if (Content == null) {
|
---|
58 | titleFontLabel.Text = "( none )";
|
---|
59 | axisFontLabel.Text = "( none )";
|
---|
60 | titleTextBox.Text = string.Empty;
|
---|
61 |
|
---|
62 | xAxisTitleTextBox.Text = string.Empty;
|
---|
63 | xAxisMinimumAutoRadioButton.Checked = false;
|
---|
64 | xAxisMinimumFixedRadioButton.Checked = false;
|
---|
65 | xAxisMinimumFixedTextBox.Text = string.Empty;
|
---|
66 | xAxisMaximumAutoRadioButton.Checked = false;
|
---|
67 | xAxisMaximumFixedRadioButton.Checked = false;
|
---|
68 | xAxisMaximumFixedTextBox.Text = string.Empty;
|
---|
69 | xAxisGridCheckBox.Checked = false;
|
---|
70 |
|
---|
71 | yAxisTitleTextBox.Text = string.Empty;
|
---|
72 | yAxisMinimumAutoRadioButton.Checked = false;
|
---|
73 | yAxisMinimumFixedRadioButton.Checked = false;
|
---|
74 | yAxisMinimumFixedTextBox.Text = string.Empty;
|
---|
75 | yAxisMaximumAutoRadioButton.Checked = false;
|
---|
76 | yAxisMaximumFixedRadioButton.Checked = false;
|
---|
77 | yAxisMaximumFixedTextBox.Text = string.Empty;
|
---|
78 | yAxisGridCheckBox.Checked = false;
|
---|
79 | } else {
|
---|
80 | titleFontLabel.Text = "( " + FormatFont(Content.TitleFont) + " )";
|
---|
81 | axisFontLabel.Text = "( " + FormatFont(Content.AxisTitleFont) + " )";
|
---|
82 | titleTextBox.Text = Content.Title;
|
---|
83 |
|
---|
84 | xAxisTitleTextBox.Text = Content.XAxisTitle;
|
---|
85 | xAxisMinimumAutoRadioButton.Checked = Content.XAxisMinimumAuto;
|
---|
86 | xAxisMinimumFixedRadioButton.Checked = !Content.XAxisMinimumAuto;
|
---|
87 | xAxisMinimumFixedTextBox.Text = Content.XAxisMinimumFixedValue.ToString();
|
---|
88 | xAxisMaximumAutoRadioButton.Checked = Content.XAxisMaximumAuto;
|
---|
89 | xAxisMaximumFixedRadioButton.Checked = !Content.XAxisMaximumAuto;
|
---|
90 | xAxisMaximumFixedTextBox.Text = Content.XAxisMaximumFixedValue.ToString();
|
---|
91 | xAxisGridCheckBox.Checked = Content.XAxisGrid;
|
---|
92 |
|
---|
93 | yAxisTitleTextBox.Text = Content.YAxisTitle;
|
---|
94 | yAxisMinimumAutoRadioButton.Checked = Content.YAxisMinimumAuto;
|
---|
95 | yAxisMinimumFixedRadioButton.Checked = !Content.YAxisMinimumAuto;
|
---|
96 | yAxisMinimumFixedTextBox.Text = Content.YAxisMinimumFixedValue.ToString();
|
---|
97 | yAxisMaximumAutoRadioButton.Checked = Content.YAxisMaximumAuto;
|
---|
98 | yAxisMaximumFixedRadioButton.Checked = !Content.YAxisMaximumAuto;
|
---|
99 | yAxisMaximumFixedTextBox.Text = Content.YAxisMaximumFixedValue.ToString();
|
---|
100 | yAxisGridCheckBox.Checked = Content.YAxisGrid;
|
---|
101 | }
|
---|
102 | } finally { SuppressEvents = false; }
|
---|
103 | SetEnabledStateOfControls();
|
---|
104 | }
|
---|
105 |
|
---|
106 | protected virtual void SetEnabledStateOfControls() {
|
---|
107 | axisTabControl.Enabled = Content != null;
|
---|
108 | xAxisMinimumFixedTextBox.Enabled = xAxisMinimumFixedRadioButton.Checked;
|
---|
109 | xAxisMaximumFixedTextBox.Enabled = xAxisMaximumFixedRadioButton.Checked;
|
---|
110 |
|
---|
111 | yAxisMinimumFixedTextBox.Enabled = yAxisMinimumFixedRadioButton.Checked;
|
---|
112 | yAxisMaximumFixedTextBox.Enabled = yAxisMaximumFixedRadioButton.Checked;
|
---|
113 | }
|
---|
114 |
|
---|
115 | #region Event Handlers
|
---|
116 | private void yTitleTextBox_Validated(object sender, System.EventArgs e) {
|
---|
117 | if (!SuppressEvents && Content != null) {
|
---|
118 | Content.YAxisTitle = yAxisTitleTextBox.Text;
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | private void xTitleTextBox_Validated(object sender, System.EventArgs e) {
|
---|
123 | if (!SuppressEvents && Content != null) {
|
---|
124 | Content.XAxisTitle = xAxisTitleTextBox.Text;
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | private void xAxisMinimumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
129 | if (!SuppressEvents && Content != null) {
|
---|
130 | TextBox tb = (TextBox)sender;
|
---|
131 | double val;
|
---|
132 | if (double.TryParse(tb.Text, out val)) {
|
---|
133 | if (val >= Content.XAxisMaximumFixedValue) {
|
---|
134 | errorProvider.SetError(tb, "Number must be smaller than maximum.");
|
---|
135 | e.Cancel = true;
|
---|
136 | } else {
|
---|
137 | Content.XAxisMinimumFixedValue = val;
|
---|
138 | errorProvider.SetError(tb, string.Empty);
|
---|
139 | }
|
---|
140 | } else {
|
---|
141 | errorProvider.SetError(tb, "Not a valid number.");
|
---|
142 | e.Cancel = true;
|
---|
143 | }
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | private void xAxisMaximumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
148 | if (!SuppressEvents && Content != null) {
|
---|
149 | TextBox tb = (TextBox)sender;
|
---|
150 | double val;
|
---|
151 | if (double.TryParse(tb.Text, out val)) {
|
---|
152 | if (val <= Content.XAxisMinimumFixedValue) {
|
---|
153 | errorProvider.SetError(tb, "Number must be greater than minimum.");
|
---|
154 | e.Cancel = true;
|
---|
155 | } else {
|
---|
156 | Content.XAxisMaximumFixedValue = val;
|
---|
157 | errorProvider.SetError(tb, string.Empty);
|
---|
158 | }
|
---|
159 | } else {
|
---|
160 | errorProvider.SetError(tb, "Not a valid number.");
|
---|
161 | e.Cancel = true;
|
---|
162 | }
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | private void yAxisMinimumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
167 | if (!SuppressEvents && Content != null) {
|
---|
168 | TextBox tb = (TextBox)sender;
|
---|
169 | double val;
|
---|
170 | if (double.TryParse(tb.Text, out val)) {
|
---|
171 | if (val >= Content.YAxisMaximumFixedValue) {
|
---|
172 | errorProvider.SetError(tb, "Number must be smaller than maximum.");
|
---|
173 | e.Cancel = true;
|
---|
174 | } else {
|
---|
175 | Content.YAxisMinimumFixedValue = val;
|
---|
176 | errorProvider.SetError(tb, string.Empty);
|
---|
177 | }
|
---|
178 | } else {
|
---|
179 | errorProvider.SetError(tb, "Not a valid number.");
|
---|
180 | e.Cancel = true;
|
---|
181 | }
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | private void yAxisMaximumFixedTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
186 | if (!SuppressEvents && Content != null) {
|
---|
187 | TextBox tb = (TextBox)sender;
|
---|
188 | double val;
|
---|
189 | if (double.TryParse(tb.Text, out val)) {
|
---|
190 | if (val <= Content.YAxisMinimumFixedValue) {
|
---|
191 | errorProvider.SetError(tb, "Number must be greater than minimum.");
|
---|
192 | e.Cancel = true;
|
---|
193 | } else {
|
---|
194 | Content.YAxisMaximumFixedValue = val;
|
---|
195 | errorProvider.SetError(tb, string.Empty);
|
---|
196 | }
|
---|
197 | } else {
|
---|
198 | errorProvider.SetError(tb, "Not a valid number.");
|
---|
199 | e.Cancel = true;
|
---|
200 | }
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 | private void xAxisMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
|
---|
205 | if (!SuppressEvents && Content != null) {
|
---|
206 | SuppressEvents = true;
|
---|
207 | try {
|
---|
208 | Content.XAxisMinimumAuto = xAxisMinimumAutoRadioButton.Checked;
|
---|
209 | if (Content.XAxisMinimumAuto) xAxisMinimumFixedTextBox.Text = double.NaN.ToString();
|
---|
210 | } finally { SuppressEvents = false; }
|
---|
211 | SetEnabledStateOfControls();
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | private void xAxisMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
|
---|
216 | if (!SuppressEvents && Content != null) {
|
---|
217 | SuppressEvents = true;
|
---|
218 | try {
|
---|
219 | Content.XAxisMaximumAuto = xAxisMaximumAutoRadioButton.Checked;
|
---|
220 | if (Content.XAxisMaximumAuto) xAxisMaximumFixedTextBox.Text = double.NaN.ToString();
|
---|
221 | } finally { SuppressEvents = false; }
|
---|
222 | SetEnabledStateOfControls();
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | private void yAxisMinimumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
|
---|
227 | if (!SuppressEvents && Content != null) {
|
---|
228 | SuppressEvents = true;
|
---|
229 | try {
|
---|
230 | Content.YAxisMinimumAuto = yAxisMinimumAutoRadioButton.Checked;
|
---|
231 | if (Content.YAxisMinimumAuto) yAxisMinimumFixedTextBox.Text = double.NaN.ToString();
|
---|
232 | } finally { SuppressEvents = false; }
|
---|
233 | SetEnabledStateOfControls();
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | private void yAxisMaximumRadioButton_CheckedChanged(object sender, System.EventArgs e) {
|
---|
238 | if (!SuppressEvents && Content != null) {
|
---|
239 | SuppressEvents = true;
|
---|
240 | try {
|
---|
241 | Content.YAxisMaximumAuto = yAxisMaximumAutoRadioButton.Checked;
|
---|
242 | if (Content.YAxisMaximumAuto) yAxisMaximumFixedTextBox.Text = double.NaN.ToString();
|
---|
243 | } finally { SuppressEvents = false; }
|
---|
244 | SetEnabledStateOfControls();
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | private void titleFontButton_Click(object sender, System.EventArgs e) {
|
---|
249 | titleFontDialog.Font = Content.TitleFont;
|
---|
250 | titleFontDialog.Color = Content.TitleColor;
|
---|
251 | if (titleFontDialog.ShowDialog() == DialogResult.OK) {
|
---|
252 | Content.TitleFont = titleFontDialog.Font;
|
---|
253 | Content.TitleColor = titleFontDialog.Color;
|
---|
254 | titleFontLabel.Text = "( " + FormatFont(Content.TitleFont) + " )";
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 | private void axisFontButton_Click(object sender, System.EventArgs e) {
|
---|
259 | axisFontDialog.Font = Content.AxisTitleFont;
|
---|
260 | axisFontDialog.Color = Content.AxisTitleColor;
|
---|
261 | if (axisFontDialog.ShowDialog() == DialogResult.OK) {
|
---|
262 | Content.AxisTitleFont = axisFontDialog.Font;
|
---|
263 | Content.AxisTitleColor = axisFontDialog.Color;
|
---|
264 | axisFontLabel.Text = "( " + FormatFont(Content.AxisTitleFont) + " )";
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | private void titleTextBox_Validated(object sender, System.EventArgs e) {
|
---|
269 | if (!SuppressEvents && Content != null) {
|
---|
270 | Content.Title = titleTextBox.Text;
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | private void yAxisGridCheckBox_CheckedChanged(object sender, System.EventArgs e) {
|
---|
275 | if (!SuppressEvents && Content != null) {
|
---|
276 | Content.YAxisGrid = yAxisGridCheckBox.Checked;
|
---|
277 | }
|
---|
278 | }
|
---|
279 |
|
---|
280 | private void xAxisGridCheckBox_CheckedChanged(object sender, System.EventArgs e) {
|
---|
281 | if (!SuppressEvents && Content != null) {
|
---|
282 | Content.XAxisGrid = xAxisGridCheckBox.Checked;
|
---|
283 | }
|
---|
284 | }
|
---|
285 | #endregion
|
---|
286 |
|
---|
287 | private string FormatFont(Font f) {
|
---|
288 | if (f == null) return "default";
|
---|
289 | else return f.Name + ", " + f.SizeInPoints.ToString() + "pt, " + f.Style.ToString();
|
---|
290 | }
|
---|
291 | }
|
---|
292 | }
|
---|