Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2870_AutoDiff-nuget/HeuristicLab.Analysis.Views/3.3/ScatterPlotDataRowVisualPropertiesControl.cs @ 15787

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

#2640: Updated year of copyrights in license headers

File size: 7.4 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("ScatterPlot DataRow Visual Properties")]
31  public partial class ScatterPlotDataRowVisualPropertiesControl : UserControl {
32    protected bool SuppressEvents { get; set; }
33
34    private ScatterPlotDataRowVisualProperties content;
35    public ScatterPlotDataRowVisualProperties Content {
36      get { return content; }
37      set {
38        bool changed = (value != content);
39        content = value;
40        if (changed) OnContentChanged();
41      }
42    }
43
44    public ScatterPlotDataRowVisualPropertiesControl() {
45      InitializeComponent();
46      pointStyleComboBox.DataSource = Enum.GetValues(typeof(ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle));
47      regressionTypeComboBox.DataSource = Enum.GetValues(typeof(ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType));
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          pointStyleComboBox.SelectedIndex = -1;
58          colorButton.BackColor = SystemColors.Control;
59          colorButton.Text = "?";
60          isVisibleInLegendCheckBox.Checked = false;
61          pointSizeNumericUpDown.Value = 1;
62          displayNameTextBox.Text = String.Empty;
63          regressionTypeComboBox.SelectedIndex = -1;
64          polynomialRegressionOrderNumericUpDown.Value = 2;
65          isRegressionVisibleInLegendCheckBox.Checked = false;
66          regressionLegendTextBox.Text = string.Empty;
67        } else {
68          displayNameTextBox.Text = Content.DisplayName;
69          pointStyleComboBox.SelectedItem = Content.PointStyle;
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          pointSizeNumericUpDown.Value = Content.PointSize;
78          isVisibleInLegendCheckBox.Checked = Content.IsVisibleInLegend;
79          regressionTypeComboBox.SelectedItem = Content.RegressionType;
80          polynomialRegressionOrderNumericUpDown.Value = Content.PolynomialRegressionOrder;
81          isRegressionVisibleInLegendCheckBox.Checked = Content.IsRegressionVisibleInLegend;
82          regressionLegendTextBox.Text = content.RegressionDisplayName;
83        }
84      }
85      finally { SuppressEvents = false; }
86      SetEnabledStateOfControls();
87    }
88
89    protected virtual void SetEnabledStateOfControls() {
90      pointStyleComboBox.Enabled = Content != null;
91      colorButton.Enabled = Content != null;
92      clearColorButton.Visible = Content != null && !Content.Color.IsEmpty;
93      isVisibleInLegendCheckBox.Enabled = Content != null;
94      pointSizeNumericUpDown.Enabled = Content != null;
95      displayNameTextBox.Enabled = Content != null;
96      regressionTypeComboBox.Enabled = Content != null;
97      polynomialRegressionOrderNumericUpDown.Enabled = Content != null && Content.RegressionType == ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.Polynomial;
98      orderLabel.Enabled = polynomialRegressionOrderNumericUpDown.Enabled;
99      isRegressionVisibleInLegendCheckBox.Enabled = Content != null && Content.RegressionType != ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.None;
100      regressionLegendTextBox.Enabled = Content != null && Content.RegressionType != ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType.None;
101    }
102
103    #region Event Handlers
104    private void pointStyleComboBox_SelectedValueChanged(object sender, EventArgs e) {
105      if (!SuppressEvents && Content != null) {
106        var selected = (ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle)pointStyleComboBox.SelectedValue;
107        Content.PointStyle = selected;
108      }
109    }
110
111    private void colorButton_Click(object sender, EventArgs e) {
112      if (colorDialog.ShowDialog() == DialogResult.OK) {
113        Content.Color = colorDialog.Color;
114        colorButton.BackColor = Content.Color;
115        colorButton.Text = String.Empty;
116        clearColorButton.Visible = true;
117      }
118    }
119
120    private void clearColorButton_Click(object sender, EventArgs e) {
121      if (!SuppressEvents && Content != null) {
122        Content.Color = Color.Empty;
123        colorButton.BackColor = SystemColors.Control;
124        colorButton.Text = "?";
125        clearColorButton.Visible = false;
126      }
127    }
128
129    private void displayNameTextBox_Validated(object sender, EventArgs e) {
130      if (!SuppressEvents && Content != null) {
131        SuppressEvents = true;
132        try {
133          Content.DisplayName = displayNameTextBox.Text;
134        }
135        finally { SuppressEvents = false; }
136      }
137    }
138
139    private void pointSizeNumericUpDown_ValueChanged(object sender, EventArgs e) {
140      if (!SuppressEvents && Content != null) {
141        Content.PointSize = (int)pointSizeNumericUpDown.Value;
142      }
143    }
144
145    private void isVisibleInLegendCheckBox_CheckedChanged(object sender, EventArgs e) {
146      if (!SuppressEvents && Content != null) {
147        Content.IsVisibleInLegend = isVisibleInLegendCheckBox.Checked;
148      }
149    }
150
151    private void regressionTypeComboBox_SelectedValueChanged(object sender, EventArgs e) {
152      if (!SuppressEvents && Content != null) {
153        var selected = (ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType)regressionTypeComboBox.SelectedValue;
154        Content.RegressionType = selected;
155        SetEnabledStateOfControls();
156      }
157    }
158
159    private void polynomialRegressionOrderNumericUpDown_ValueChanged(object sender, EventArgs e) {
160      if (!SuppressEvents && Content != null) {
161        Content.PolynomialRegressionOrder = (int)polynomialRegressionOrderNumericUpDown.Value;
162      }
163    }
164
165    private void isRegressionVisibleInLegendCheckBox_CheckedChanged(object sender, EventArgs e) {
166      if (!SuppressEvents && Content != null) {
167        Content.IsRegressionVisibleInLegend = isRegressionVisibleInLegendCheckBox.Checked;
168      }
169    }
170
171    private void regressionLegendTextBox_Validated(object sender, EventArgs e) {
172      if (!SuppressEvents && Content != null) {
173        Content.RegressionDisplayName = regressionLegendTextBox.Text;
174      }
175    }
176    #endregion
177  }
178}
Note: See TracBrowser for help on using the repository browser.