Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Analysis.Views/3.3/DataRowVisualPropertiesControl.cs @ 6646

Last change on this file since 6646 was 6628, checked in by abeham, 13 years ago

#1541, #1603, #1606, #1607

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