Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/Options/Options.cs @ 2028

Last change on this file since 2028 was 2028, checked in by mstoeger, 15 years ago

fixed the data binding of the datarows to the listbox by overriding the tostring method. #670

File size: 9.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Windows.Forms;
5using HeuristicLab.Visualization.Legend;
6
7namespace HeuristicLab.Visualization.Options {
8  public partial class Options : UserControl {
9    private IChartDataRowsModel model;
10    private ViewSettings viewSettings;
11    private ViewSettings oldViewSettings;
12    private LineParams[] oldLineParams;
13    private string oldTitle;
14    private Dictionary<CheckBox, bool> ShowYAxisBoxes;
15    private bool oldShowXAxisGrid;
16    private Color oldXAxisGridColor;
17    private Font oldXAxisFont;
18    private Color oldXAxisColor;
19    private Dictionary<CheckBox, bool> yAxisClipChangeableBoxes;
20
21    internal class LineParams {
22      private string Label { get; set; }
23      private Color Color { get; set; }
24      private bool ShowMarkers { get; set; }
25      private int Thickness { get; set; }
26      private DrawingStyle Style { get; set; }
27      private readonly IDataRow row;
28
29      public LineParams(IDataRow row) {
30        Label = row.RowSettings.Label;
31        Color = row.RowSettings.Color;
32        Thickness = row.RowSettings.Thickness;
33        Style = row.RowSettings.Style;
34        this.row = row;
35        this.ShowMarkers = row.RowSettings.ShowMarkers;
36      }
37
38      public void applySettings() {
39        row.RowSettings.Label = Label;
40        row.RowSettings.Color = Color;
41        row.RowSettings.Thickness = Thickness;
42        row.RowSettings.Style = Style;
43        row.RowSettings.ShowMarkers = this.ShowMarkers;
44      }
45    }
46
47    public Options() {
48      InitializeComponent();
49
50      cbLegendPosition.Items.Add(LegendPosition.Top);
51      cbLegendPosition.Items.Add(LegendPosition.Bottom);
52      cbLegendPosition.Items.Add(LegendPosition.Left);
53      cbLegendPosition.Items.Add(LegendPosition.Right);
54
55      Model = new ChartDataRowsModel();
56    }
57
58    public IChartDataRowsModel Model {
59      get { return model; }
60      set {
61        model = value;
62        oldTitle = model.Title;
63        tbxTitle.Text = model.Title;
64        viewSettings = model.ViewSettings;
65        oldViewSettings = new ViewSettings(model.ViewSettings);
66        cbLegendPosition.SelectedItem = viewSettings.LegendPosition;
67      }
68    }
69
70    public void ResetSettings() {
71      model.XAxis.ShowGrid = oldShowXAxisGrid;
72      chkShowXAxisGrid.Checked = oldShowXAxisGrid;
73
74      model.XAxis.Color = oldXAxisColor;
75      model.XAxis.Font = oldXAxisFont;
76     
77      model.XAxis.GridColor = oldXAxisGridColor;
78      xAxisGridColorSelection.Color = oldXAxisGridColor;
79
80      foreach (var param in oldLineParams) {
81        param.applySettings();
82      }
83
84      foreach (var box in ShowYAxisBoxes) {
85        box.Key.Checked = box.Value;
86      }
87
88      foreach (KeyValuePair<CheckBox, bool> box in yAxisClipChangeableBoxes) {
89        box.Key.Checked = box.Value;
90      }
91
92      model.Title = oldTitle;
93      tbxTitle.Text = oldTitle;
94
95      viewSettings.LegendColor = oldViewSettings.LegendColor;
96      viewSettings.LegendPosition = oldViewSettings.LegendPosition;
97      viewSettings.LegendFont = oldViewSettings.LegendFont;
98      viewSettings.TitleColor = oldViewSettings.TitleColor;
99      viewSettings.TitleFont = oldViewSettings.TitleFont;
100      viewSettings.UpdateView();
101      cbLegendPosition.SelectedItem = viewSettings.LegendPosition;
102      this.LineSelectCB_SelectedIndexChanged(this, null);
103    }
104
105    private static IList<int> GetThicknesses() {
106      return new List<int>(new[] {1, 2, 3, 4, 5, 6, 7, 8});
107    }
108
109    private static IList<DrawingStyle> GetStyles() {
110      return new List<DrawingStyle>(new[] {DrawingStyle.Solid, DrawingStyle.Dashed});
111    }
112
113    private void btnChangeLegendFont_Click(object sender, EventArgs e) {
114      fdFont.Font = viewSettings.LegendFont;
115      fdFont.Color = viewSettings.LegendColor;
116
117      DialogResult dr = fdFont.ShowDialog();
118
119      if (dr == DialogResult.OK) {
120        viewSettings.LegendFont = fdFont.Font;
121        viewSettings.LegendColor = fdFont.Color;
122
123        viewSettings.UpdateView();
124      }
125    }
126
127    private void btnChangeTitleFont_Click(object sender, EventArgs e) {
128      fdFont.Font = viewSettings.TitleFont;
129      fdFont.Color = viewSettings.TitleColor;
130
131      DialogResult dr = fdFont.ShowDialog();
132
133      if (dr == DialogResult.OK) {
134        viewSettings.TitleFont = fdFont.Font;
135        viewSettings.TitleColor = fdFont.Color;
136
137        viewSettings.UpdateView();
138      }
139    }
140
141    private void btnChangeXAxisFont_Click(object sender, EventArgs e) {
142      fdFont.Font = model.XAxis.Font;
143      fdFont.Color = model.XAxis.Color;
144
145      DialogResult dr = fdFont.ShowDialog();
146
147      if (dr == DialogResult.OK) {
148        model.XAxis.Font = fdFont.Font;
149        model.XAxis.Color = fdFont.Color;
150
151        viewSettings.UpdateView();
152      }
153    }
154
155    private void Options_Load(object sender, EventArgs e) {
156      oldShowXAxisGrid = model.XAxis.ShowGrid;
157      chkShowXAxisGrid.Checked = model.XAxis.ShowGrid;
158
159      oldXAxisGridColor = model.XAxis.GridColor;
160      xAxisGridColorSelection.Color = model.XAxis.GridColor;
161
162      oldXAxisFont = model.XAxis.Font;
163      oldXAxisColor = model.XAxis.Color;
164
165      InitTabPageLines();
166      InitTabPageYAxes();
167    }
168
169    private void InitTabPageLines() {
170      if (model.Rows.Count != 0) {
171        int index = 0;
172        oldLineParams = new LineParams[model.Rows.Count];
173        foreach (var row in model.Rows) {
174          oldLineParams[index++] = new LineParams(row);
175        }
176        LineThicknessCB.DataSource = GetThicknesses();
177        LinestyleCB.DataSource = GetStyles();
178        LinestyleCB.SelectedItem = model.Rows[0].RowSettings.Style;
179        LineThicknessCB.SelectedItem = model.Rows[0].RowSettings.Thickness;
180        MarkercheckBox.Checked = model.Rows[0].RowSettings.ShowMarkers;
181
182        LineSelectCB.DataSource = model.Rows;
183
184        LineSelectCB.SelectedIndex = 0;
185        LineSelectCB_SelectedIndexChanged(this, null);
186      }
187    }
188
189    private void InitTabPageYAxes() {
190      ShowYAxisBoxes = new Dictionary<CheckBox, bool>();
191      yAxisClipChangeableBoxes = new Dictionary<CheckBox, bool>();
192
193      for (int i = 0; i < model.YAxes.Count; i++) {
194        YAxisDescriptor yAxisDescriptor = model.YAxes[i];
195
196        CheckBox cbxShowYAxis = new CheckBox();
197        cbxShowYAxis.Text = yAxisDescriptor.Label;
198        cbxShowYAxis.Checked = yAxisDescriptor.ShowYAxis;
199        ShowYAxisBoxes[cbxShowYAxis] = yAxisDescriptor.ShowYAxis;
200        cbxShowYAxis.CheckedChanged += delegate { yAxisDescriptor.ShowYAxis = cbxShowYAxis.Checked; };
201
202        flpShowYAxis.Controls.Add(cbxShowYAxis);
203
204        CheckBox cbxClipChangeable = new CheckBox();
205        cbxClipChangeable.Text = yAxisDescriptor.Label;
206        cbxClipChangeable.Checked = yAxisDescriptor.ClipChangeable;
207        yAxisClipChangeableBoxes[cbxClipChangeable] = yAxisDescriptor.ClipChangeable;
208        cbxClipChangeable.CheckedChanged += delegate { yAxisDescriptor.ClipChangeable = cbxClipChangeable.Checked; };
209
210        flpYAxisClipChangeable.Controls.Add(cbxClipChangeable);
211      }
212    }
213
214    private void LineSelectCB_SelectedIndexChanged(object sender, EventArgs e) {
215      if (LineSelectCB.SelectedValue != null) {
216        /*  int index =
217            LineThicknessCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Thickness.ToString());
218          LineThicknessCB.SelectedIndex = index;
219          index = LinestyleCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Style.ToString());
220          LinestyleCB.SelectedIndex = index;  */
221        LineThicknessCB.SelectedItem = ((IDataRow)LineSelectCB.SelectedValue).RowSettings.Thickness;
222        LinestyleCB.SelectedItem = ((IDataRow)LineSelectCB.SelectedValue).RowSettings.Style;
223        selectedLineColorSelection.Color = ((IDataRow)LineSelectCB.SelectedValue).RowSettings.Color;
224        MarkercheckBox.Checked = ((IDataRow)LineSelectCB.SelectedValue).RowSettings.ShowMarkers;
225      }
226    }
227
228    private void cbLegendPosition_SelectedIndexChanged(object sender, EventArgs e) {
229      viewSettings.LegendPosition = (LegendPosition)cbLegendPosition.SelectedItem;
230      viewSettings.UpdateView();
231    }
232
233    private void LinestyleCB_SelectedIndexChanged(object sender, EventArgs e) {
234      if (LineSelectCB.SelectedValue != null) {
235        ((IDataRow)LineSelectCB.SelectedValue).RowSettings.Style = (DrawingStyle)LinestyleCB.SelectedItem;
236      }
237    }
238
239    private void LineThicknessCB_SelectedIndexChanged(object sender, EventArgs e) {
240      if (LineSelectCB.SelectedValue != null) {
241        ((IDataRow)LineSelectCB.SelectedValue).RowSettings.Thickness = (int)LineThicknessCB.SelectedItem;
242      }
243    }
244
245    private void MarkercheckBox_CheckedChanged(object sender, EventArgs e) {
246      if (LineSelectCB.SelectedValue != null) {
247        ((IDataRow)LineSelectCB.SelectedValue).RowSettings.ShowMarkers = MarkercheckBox.Checked;
248      }
249    }
250
251    private void chkShowXAxisGrid_CheckedChanged(object sender, EventArgs e) {
252      model.XAxis.ShowGrid = chkShowXAxisGrid.Checked;
253    }
254
255    private void tbxTitle_TextChanged(object sender, EventArgs e) {
256      model.Title = tbxTitle.Text;
257      model.ViewSettings.UpdateView();
258    }
259
260    private void selectedLineColorSelection_ColorChanged(ColorSelection sender) {
261      ((IDataRow)LineSelectCB.SelectedValue).RowSettings.Color = selectedLineColorSelection.Color;
262    }
263
264    private void xAxisGridColorSelection_ColorChanged(ColorSelection sender) {
265      model.XAxis.GridColor = xAxisGridColorSelection.Color;
266    }
267  }
268}
Note: See TracBrowser for help on using the repository browser.