Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/Options/OptionsDialog.cs @ 1389

Last change on this file since 1389 was 1389, checked in by dwagner, 16 years ago

Added Functionality: Changes in dialog are directly applied to the linechart & reset button resets the values (#478)

File size: 7.0 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 OptionsDialog : Form {
9    private readonly IChartDataRowsModel model;
10    private readonly ViewSettings viewSettings;
11    private readonly ViewSettings oldViewSettings;
12    private LineParams[] oldLineParams;
13    private Dictionary<CheckBox,bool> ShowYAxisBoxes;
14
15    internal class LineParams {
16      string Label { get; set; }
17      Color Color { get; set; }
18      int Thickness { get; set; }
19      DrawingStyle Style { get; set; }
20      private readonly IDataRow row;
21
22      public LineParams(IDataRow row) {
23        Label = row.Label;
24        Color = row.Color;
25        Thickness = row.Thickness;
26        Style = row.Style;
27        this.row = row;
28      }
29
30      public void applySettings() {
31        row.Label = Label;
32        row.Color = Color;
33        row.Thickness = Thickness;
34        row.Style = Style;
35      }
36    }
37
38    public OptionsDialog(IChartDataRowsModel model) {
39      InitializeComponent();
40
41      this.model = model;
42      viewSettings = model.ViewSettings;
43      oldViewSettings = new ViewSettings(model.ViewSettings);
44
45      cbLegendPosition.Items.Add(LegendPosition.Top);
46      cbLegendPosition.Items.Add(LegendPosition.Bottom);
47      cbLegendPosition.Items.Add(LegendPosition.Left);
48      cbLegendPosition.Items.Add(LegendPosition.Right);
49
50      cbLegendPosition.SelectedItem = viewSettings.LegendPosition;
51    }
52
53    private void OptionsDialogSelectColorBtn_Click(object sender, EventArgs e) {
54      ColorDialog dlg = new ColorDialog();
55      dlg.ShowDialog();
56      ColorPreviewTB.BackColor = dlg.Color;
57      ((IDataRow)LineSelectCB.SelectedValue).Color = dlg.Color;
58    }
59
60    public IList<int> GetThicknesses() {
61      return new List<int>(new int[] {1, 2, 3, 4, 5, 6, 7, 8});
62    }
63
64    public IList<DrawingStyle> GetStyles() {
65      return new List<DrawingStyle>(new DrawingStyle[] {DrawingStyle.Solid, DrawingStyle.Dashed});
66    }
67
68    private void OptionsDialog_Load(object sender, EventArgs e) {
69      InitTabPageLines();
70      InitTabPageYAxes();
71    }
72
73    private void InitTabPageLines() {
74      if (model.Rows.Count != 0) {
75        int index = 0;
76        oldLineParams = new LineParams[model.Rows.Count];
77        foreach (var row in model.Rows) {
78          oldLineParams[index++]= new LineParams(row);
79        }
80        LineThicknessCB.DataSource = GetThicknesses();
81        LinestyleCB.DataSource = GetStyles();
82        LinestyleCB.SelectedItem = model.Rows[0].Style;
83        LineThicknessCB.SelectedItem = model.Rows[0].Thickness;
84
85        LineSelectCB.DataSource = model.Rows;
86        LineSelectCB.DisplayMember = "Label";
87
88       
89        LineSelectCB.SelectedIndex = 0;
90        LineSelectCB_SelectedIndexChanged(this, null);
91       
92      }
93    }
94
95    private void InitTabPageYAxes() {
96      ShowYAxisBoxes = new Dictionary<CheckBox, bool>();
97      for (int i = 0; i < model.YAxes.Count; i++) {
98        YAxisDescriptor yAxisDescriptor = model.YAxes[i];
99
100        CheckBox chkbox = new CheckBox();
101        chkbox.Text = yAxisDescriptor.Label;
102        chkbox.Checked = yAxisDescriptor.ShowYAxis;
103        ShowYAxisBoxes[chkbox] = yAxisDescriptor.ShowYAxis;
104        chkbox.CheckedChanged += delegate { yAxisDescriptor.ShowYAxis = chkbox.Checked; };
105       
106        dataRowsFlowLayout.Controls.Add(chkbox);
107      }
108    }
109
110    private void LineSelectCB_SelectedIndexChanged(object sender, EventArgs e) {
111      if (LineSelectCB.SelectedValue != null) {
112      /*  int index =
113          LineThicknessCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Thickness.ToString());
114        LineThicknessCB.SelectedIndex = index;
115        index = LinestyleCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Style.ToString());
116        LinestyleCB.SelectedIndex = index;  */
117        LineThicknessCB.SelectedItem = ((IDataRow) LineSelectCB.SelectedValue).Thickness;
118        LinestyleCB.SelectedItem = ((IDataRow)LineSelectCB.SelectedValue).Style;
119        ColorPreviewTB.BackColor = ((IDataRow)LineSelectCB.SelectedValue).Color;   
120      }
121    }
122
123   
124    private void OptionsDialogOkButton_Click(object sender, EventArgs e) {
125      Close();
126    }
127   
128
129   
130
131    private void cbLegendPosition_SelectedIndexChanged(object sender, EventArgs e) {
132      viewSettings.LegendPosition = (LegendPosition)cbLegendPosition.SelectedItem;
133      viewSettings.UpdateView();
134    }
135
136    private void btnChangeTitleFont_Click(object sender, EventArgs e) {
137      fdFont.Font = viewSettings.TitleFont;
138      fdFont.Color = viewSettings.TitleColor;
139
140      DialogResult dr = fdFont.ShowDialog();
141
142      if(dr == DialogResult.OK) {
143        viewSettings.TitleFont = fdFont.Font;
144        viewSettings.TitleColor = fdFont.Color;
145
146        viewSettings.UpdateView();
147      }
148    }
149
150    private void btnChangeLegendFont_Click(object sender, EventArgs e) {
151      fdFont.Font = viewSettings.LegendFont;
152      fdFont.Color = viewSettings.LegendColor;
153
154      DialogResult dr = fdFont.ShowDialog();
155
156      if (dr == DialogResult.OK) {
157        viewSettings.LegendFont = fdFont.Font;
158        viewSettings.LegendColor = fdFont.Color;
159
160        viewSettings.UpdateView();
161      }
162    }
163
164    private void btnChangeXAxisFont_Click(object sender, EventArgs e) {
165      fdFont.Font = viewSettings.XAxisFont;
166      fdFont.Color = viewSettings.XAxisColor;
167
168      DialogResult dr = fdFont.ShowDialog();
169
170      if (dr == DialogResult.OK) {
171        viewSettings.XAxisFont = fdFont.Font;
172        viewSettings.XAxisColor = fdFont.Color;
173
174        viewSettings.UpdateView();
175      }
176    }
177
178    private void OptionsDialogResetButton_Click(object sender, EventArgs e) {
179      foreach (var param in oldLineParams) {
180        param.applySettings();
181      }
182
183      foreach (var box in ShowYAxisBoxes) {
184        box.Key.Checked = box.Value;
185      }
186      viewSettings.LegendColor = oldViewSettings.LegendColor;
187      viewSettings.LegendPosition = oldViewSettings.LegendPosition;
188      viewSettings.LegendFont = oldViewSettings.LegendFont;
189      viewSettings.TitleColor = oldViewSettings.TitleColor;
190      viewSettings.TitleFont = oldViewSettings.TitleFont;
191      viewSettings.XAxisColor = oldViewSettings.LegendColor;
192      viewSettings.XAxisFont = oldViewSettings.XAxisFont;
193      viewSettings.UpdateView();
194      cbLegendPosition.SelectedItem = viewSettings.LegendPosition;
195      this.LineSelectCB_SelectedIndexChanged(this,null);
196    }
197
198    private void LinestyleCB_SelectedIndexChanged(object sender, EventArgs e) {
199      if (LineSelectCB.SelectedValue != null)
200        ((IDataRow)LineSelectCB.SelectedValue).Style = (DrawingStyle)LinestyleCB.SelectedItem;
201    }
202
203    private void LineThicknessCB_SelectedIndexChanged(object sender, EventArgs e) {
204      if (LineSelectCB.SelectedValue != null)
205        ((IDataRow)LineSelectCB.SelectedValue).Thickness = (int)LineThicknessCB.SelectedItem;
206    }
207
208
209
210
211  }
212}
Note: See TracBrowser for help on using the repository browser.