Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis.Views/3.3/DataRowVisualPropertiesControl.cs @ 6593

Last change on this file since 6593 was 6342, checked in by abeham, 14 years ago

#1465, #1469, #1470, #1494, #1496, #1497, #1539, #1487

  • merged to trunk
File size: 6.8 KB
RevLine 
[6010]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace 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));
[6012]46      lineStyleComboBox.DataSource = Enum.GetValues(typeof(DataRowVisualProperties.DataRowLineStyle));
[6010]47    }
48
49    protected virtual void OnContentChanged() {
50      SuppressEvents = true;
51      try {
52        if (Content == null) {
53          chartTypeComboBox.SelectedIndex = -1;
54          colorButton.BackColor = SystemColors.Control;
[6012]55          colorButton.Text = "?";
56          yAxisPrimaryRadioButton.Checked = false;
57          yAxisSecondaryRadioButton.Checked = false;
58          xAxisPrimaryRadioButton.Checked = false;
59          xAxisSecondaryRadioButton.Checked = false;
60          lineStyleComboBox.SelectedIndex = -1;
[6010]61          startIndexZeroCheckBox.Checked = false;
[6012]62          lineWidthNumericUpDown.Value = 1;
[6010]63          binsNumericUpDown.Value = 1;
[6012]64          binsApproximatelyRadioButton.Checked = false;
65          binsExactRadioButton.Checked = false;
[6010]66        } else {
67          chartTypeComboBox.SelectedItem = Content.ChartType;
[6011]68          if (Content.Color.IsEmpty) {
69            colorButton.BackColor = SystemColors.Control;
70            colorButton.Text = "?";
[6012]71          } else {
72            colorButton.BackColor = Content.Color;
73            colorButton.Text = String.Empty;
74          }
75          yAxisPrimaryRadioButton.Checked = !Content.SecondYAxis;
76          yAxisSecondaryRadioButton.Checked = Content.SecondYAxis;
77          xAxisPrimaryRadioButton.Checked = !Content.SecondXAxis;
78          xAxisSecondaryRadioButton.Checked = Content.SecondXAxis;
79          lineStyleComboBox.SelectedItem = Content.LineStyle;
[6010]80          startIndexZeroCheckBox.Checked = Content.StartIndexZero;
[6012]81          lineWidthNumericUpDown.Value = Content.LineWidth;
[6010]82          binsNumericUpDown.Value = Content.Bins;
[6012]83          binsApproximatelyRadioButton.Checked = !Content.ExactBins;
84          binsExactRadioButton.Checked = Content.ExactBins;
[6010]85        }
86      } finally { SuppressEvents = false; }
87      SetEnabledStateOfControls();
88    }
89
90    protected virtual void SetEnabledStateOfControls() {
91      commonGroupBox.Enabled = Content != null;
[6012]92      lineChartGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Line;
[6010]93      histoGramGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Histogram;
94    }
95
96    #region Event Handlers
97    private void chartTypeComboBox_SelectedValueChanged(object sender, EventArgs e) {
98      if (!SuppressEvents && Content != null) {
[6016]99        DataRowVisualProperties.DataRowChartType selected = (DataRowVisualProperties.DataRowChartType)chartTypeComboBox.SelectedValue;
100        Content.ChartType = selected;
101        if (Content.ChartType != selected) {
102          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());
103          SuppressEvents = true;
104          try {
105            chartTypeComboBox.SelectedItem = Content.ChartType;
106          } finally { SuppressEvents = false; }
107        }
[6010]108        SetEnabledStateOfControls();
109      }
110    }
111
112    private void colorButton_Click(object sender, EventArgs e) {
113      if (colorDialog.ShowDialog() == DialogResult.OK) {
114        Content.Color = colorDialog.Color;
115        colorButton.BackColor = Content.Color;
[6011]116        colorButton.Text = String.Empty;
[6010]117      }
118    }
119
[6012]120    private void yAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
[6010]121      if (!SuppressEvents && Content != null) {
[6012]122        SuppressEvents = true;
123        try {
124          Content.SecondYAxis = yAxisSecondaryRadioButton.Checked;
125        } finally { SuppressEvents = false; }
[6010]126      }
127    }
128
[6012]129    private void xAxisRadioButton_CheckedChanged(object sender, EventArgs e) {
[6011]130      if (!SuppressEvents && Content != null) {
[6012]131        SuppressEvents = true;
132        try {
133          Content.SecondXAxis = xAxisSecondaryRadioButton.Checked;
134        } finally { SuppressEvents = false; }
[6011]135      }
136    }
137
[6012]138    private void lineStyleComboBox_SelectedValueChanged(object sender, EventArgs e) {
139      if (!SuppressEvents && Content != null) {
140        Content.LineStyle = (DataRowVisualProperties.DataRowLineStyle)lineStyleComboBox.SelectedValue;
141      }
142    }
143
[6010]144    private void startIndexZeroCheckBox_CheckedChanged(object sender, EventArgs e) {
145      if (!SuppressEvents && Content != null) {
146        Content.StartIndexZero = startIndexZeroCheckBox.Checked;
147      }
148    }
149
[6012]150    private void lineWidthNumericUpDown_ValueChanged(object sender, EventArgs e) {
151      if (!SuppressEvents && Content != null) {
152        Content.LineWidth = (int)lineWidthNumericUpDown.Value;
153      }
154    }
155
[6010]156    private void binsNumericUpDown_ValueChanged(object sender, EventArgs e) {
157      if (!SuppressEvents && Content != null) {
158        Content.Bins = (int)binsNumericUpDown.Value;
159      }
160    }
161
[6012]162    private void binNumberRadioButton_CheckedChanged(object sender, EventArgs e) {
[6010]163      if (!SuppressEvents && Content != null) {
[6012]164        SuppressEvents = true;
165        try {
166          Content.ExactBins = binsExactRadioButton.Checked;
167        } finally { SuppressEvents = false; }
[6010]168      }
169    }
170    #endregion
171  }
172}
Note: See TracBrowser for help on using the repository browser.