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