Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1380 was 1350, checked in by mstoeger, 16 years ago

Implemented multiple Y-Axes. A LineChart has several Y-Axes and each Y-Axis has several data rows. The same clipping area is set for all data rows belonging to a Y-Axis. (#433)

File size: 4.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Windows.Forms;
4using HeuristicLab.Visualization.Legend;
5
6namespace HeuristicLab.Visualization.Options {
7  public partial class OptionsDialog : Form {
8    private readonly IChartDataRowsModel model;
9    private readonly ViewSettings viewSettings;
10
11    public OptionsDialog(IChartDataRowsModel model) {
12      InitializeComponent();
13
14      this.model = model;
15      viewSettings = model.ViewSettings;
16
17      cbLegendPosition.Items.Add(LegendPosition.Top);
18      cbLegendPosition.Items.Add(LegendPosition.Bottom);
19      cbLegendPosition.Items.Add(LegendPosition.Left);
20      cbLegendPosition.Items.Add(LegendPosition.Right);
21
22      cbLegendPosition.SelectedItem = viewSettings.LegendPosition;
23    }
24
25    private void OptionsDialogSelectColorBtn_Click(object sender, EventArgs e) {
26      ColorDialog dlg = new ColorDialog();
27      dlg.ShowDialog();
28      ColorPreviewTB.BackColor = dlg.Color;
29    }
30
31    public IList<int> GetThicknesses() {
32      return new List<int>(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8});
33    }
34
35    public IList<DrawingStyle> GetStyles() {
36      return new List<DrawingStyle>(new DrawingStyle[] {DrawingStyle.Solid, DrawingStyle.Dashed});
37    }
38
39    private void OptionsDialog_Load(object sender, EventArgs e) {
40      if (model.Rows.Count != 0) {
41        LineSelectCB.DataSource = model.Rows;
42        LineSelectCB.DisplayMember = "Label";
43
44        LineThicknessCB.DataSource = GetThicknesses();
45        LinestyleCB.DataSource = GetStyles();
46        LineSelectCB.SelectedIndex = 0;
47        LineSelectCB_SelectedIndexChanged(this, null);
48      }
49
50      InitTabPageYAxes();
51    }
52
53    private void InitTabPageYAxes() {
54      for (int i = 0; i < model.YAxes.Count; i++) {
55        YAxisDescriptor yAxisDescriptor = model.YAxes[i];
56
57        CheckBox chkbox = new CheckBox();
58        chkbox.Text = yAxisDescriptor.Label;
59        chkbox.Checked = yAxisDescriptor.ShowYAxis;
60        chkbox.CheckedChanged += delegate { yAxisDescriptor.ShowYAxis = chkbox.Checked; };
61       
62        dataRowsFlowLayout.Controls.Add(chkbox);
63      }
64    }
65
66    private void LineSelectCB_SelectedIndexChanged(object sender, EventArgs e) {
67      if (LineSelectCB.SelectedValue != null) {
68        int index =
69          LineThicknessCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Thickness.ToString());
70        LineThicknessCB.SelectedIndex = index;
71        index = LinestyleCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Style.ToString());
72        LinestyleCB.SelectedIndex = index;
73        ColorPreviewTB.BackColor = ((IDataRow)LineSelectCB.SelectedValue).Color;
74      }
75    }
76
77    private void OptionsDialogCancelButton_Click(object sender, EventArgs e) {
78      Close();
79    }
80
81    private void OptionsDialogOkButton_Click(object sender, EventArgs e) {
82      ApplyChanges();
83
84      Close();
85    }
86
87    private void OptionsDialogApplyBtn_Click(object sender, EventArgs e) {
88      ApplyChanges(); 
89    }
90
91    private void ApplyChanges() {
92      if (LineSelectCB.SelectedValue != null) {
93        ((IDataRow)LineSelectCB.SelectedValue).Thickness = (int)LineThicknessCB.SelectedItem;
94        ((IDataRow)LineSelectCB.SelectedValue).Color = ColorPreviewTB.BackColor;
95        ((IDataRow)LineSelectCB.SelectedValue).Style = (DrawingStyle)LinestyleCB.SelectedItem;
96      }
97    }
98
99    private void cbLegendPosition_SelectedIndexChanged(object sender, EventArgs e) {
100      viewSettings.LegendPosition = (LegendPosition)cbLegendPosition.SelectedItem;
101      viewSettings.UpdateView();
102    }
103
104    private void btnChangeTitleFont_Click(object sender, EventArgs e) {
105      fdFont.Font = viewSettings.TitleFont;
106      fdFont.Color = viewSettings.TitleColor;
107
108      DialogResult dr = fdFont.ShowDialog();
109
110      if(dr == DialogResult.OK) {
111        viewSettings.TitleFont = fdFont.Font;
112        viewSettings.TitleColor = fdFont.Color;
113
114        viewSettings.UpdateView();
115      }
116    }
117
118    private void btnChangeLegendFont_Click(object sender, EventArgs e) {
119      fdFont.Font = viewSettings.LegendFont;
120      fdFont.Color = viewSettings.LegendColor;
121
122      DialogResult dr = fdFont.ShowDialog();
123
124      if (dr == DialogResult.OK) {
125        viewSettings.LegendFont = fdFont.Font;
126        viewSettings.LegendColor = fdFont.Color;
127
128        viewSettings.UpdateView();
129      }
130    }
131
132    private void btnChangeXAxisFont_Click(object sender, EventArgs e) {
133      fdFont.Font = viewSettings.XAxisFont;
134      fdFont.Color = viewSettings.XAxisColor;
135
136      DialogResult dr = fdFont.ShowDialog();
137
138      if (dr == DialogResult.OK) {
139        viewSettings.XAxisFont = fdFont.Font;
140        viewSettings.XAxisColor = fdFont.Color;
141
142        viewSettings.UpdateView();
143      }
144    }
145  }
146}
Note: See TracBrowser for help on using the repository browser.