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 Options : UserControl {
|
---|
9 | private IChartDataRowsModel model;
|
---|
10 | private ViewSettings viewSettings;
|
---|
11 | private ViewSettings oldViewSettings;
|
---|
12 | private List<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 | model.DataRowAdded += model_DataRowAdded;
|
---|
157 | oldShowXAxisGrid = model.XAxis.ShowGrid;
|
---|
158 | chkShowXAxisGrid.Checked = model.XAxis.ShowGrid;
|
---|
159 |
|
---|
160 | oldXAxisGridColor = model.XAxis.GridColor;
|
---|
161 | xAxisGridColorSelection.Color = model.XAxis.GridColor;
|
---|
162 |
|
---|
163 | oldXAxisFont = model.XAxis.Font;
|
---|
164 | oldXAxisColor = model.XAxis.Color;
|
---|
165 |
|
---|
166 | InitTabPageLines();
|
---|
167 | InitTabPageYAxes();
|
---|
168 | }
|
---|
169 |
|
---|
170 | void model_DataRowAdded(IDataRow row)
|
---|
171 | {
|
---|
172 | LineSelectCB.Items.Add(row);
|
---|
173 | oldLineParams.Add(new LineParams(row));
|
---|
174 | }
|
---|
175 |
|
---|
176 | private void InitTabPageLines() {
|
---|
177 | if (model.Rows.Count != 0) {
|
---|
178 | int index = 0;
|
---|
179 | oldLineParams = new List<LineParams>();
|
---|
180 | foreach (var row in model.Rows) {
|
---|
181 | oldLineParams.Add(new LineParams(row));
|
---|
182 | LineSelectCB.Items.Add(row);
|
---|
183 | }
|
---|
184 | LineThicknessCB.DataSource = GetThicknesses();
|
---|
185 | LinestyleCB.DataSource = GetStyles();
|
---|
186 | LinestyleCB.SelectedItem = model.Rows[0].RowSettings.Style;
|
---|
187 | LineThicknessCB.SelectedItem = model.Rows[0].RowSettings.Thickness;
|
---|
188 | MarkercheckBox.Checked = model.Rows[0].RowSettings.ShowMarkers;
|
---|
189 |
|
---|
190 | // LineSelectCB.DataSource = model.Rows;
|
---|
191 | LineSelectCB.DisplayMember = "RowSettings.Label";
|
---|
192 |
|
---|
193 |
|
---|
194 | LineSelectCB.SelectedIndex = 0;
|
---|
195 | LineSelectCB_SelectedIndexChanged(this, null);
|
---|
196 | }
|
---|
197 | }
|
---|
198 |
|
---|
199 | private void InitTabPageYAxes() {
|
---|
200 | ShowYAxisBoxes = new Dictionary<CheckBox, bool>();
|
---|
201 | yAxisClipChangeableBoxes = new Dictionary<CheckBox, bool>();
|
---|
202 |
|
---|
203 | for (int i = 0; i < model.YAxes.Count; i++) {
|
---|
204 | YAxisDescriptor yAxisDescriptor = model.YAxes[i];
|
---|
205 |
|
---|
206 | CheckBox cbxShowYAxis = new CheckBox();
|
---|
207 | cbxShowYAxis.Text = yAxisDescriptor.Label;
|
---|
208 | cbxShowYAxis.Checked = yAxisDescriptor.ShowYAxis;
|
---|
209 | ShowYAxisBoxes[cbxShowYAxis] = yAxisDescriptor.ShowYAxis;
|
---|
210 | cbxShowYAxis.CheckedChanged += delegate { yAxisDescriptor.ShowYAxis = cbxShowYAxis.Checked; };
|
---|
211 |
|
---|
212 | flpShowYAxis.Controls.Add(cbxShowYAxis);
|
---|
213 |
|
---|
214 | CheckBox cbxClipChangeable = new CheckBox();
|
---|
215 | cbxClipChangeable.Text = yAxisDescriptor.Label;
|
---|
216 | cbxClipChangeable.Checked = yAxisDescriptor.ClipChangeable;
|
---|
217 | yAxisClipChangeableBoxes[cbxClipChangeable] = yAxisDescriptor.ClipChangeable;
|
---|
218 | cbxClipChangeable.CheckedChanged += delegate { yAxisDescriptor.ClipChangeable = cbxClipChangeable.Checked; };
|
---|
219 |
|
---|
220 | flpYAxisClipChangeable.Controls.Add(cbxClipChangeable);
|
---|
221 | }
|
---|
222 | }
|
---|
223 |
|
---|
224 | private void LineSelectCB_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
225 | if (LineSelectCB.SelectedItem != null) {
|
---|
226 | /* int index =
|
---|
227 | LineThicknessCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Thickness.ToString());
|
---|
228 | LineThicknessCB.SelectedIndex = index;
|
---|
229 | index = LinestyleCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Style.ToString());
|
---|
230 | LinestyleCB.SelectedIndex = index; */
|
---|
231 | LineThicknessCB.SelectedItem = ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Thickness;
|
---|
232 | LinestyleCB.SelectedItem = ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Style;
|
---|
233 | selectedLineColorSelection.Color = ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Color;
|
---|
234 | MarkercheckBox.Checked = ((IDataRow)LineSelectCB.SelectedItem).RowSettings.ShowMarkers;
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 | private void cbLegendPosition_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
239 | viewSettings.LegendPosition = (LegendPosition)cbLegendPosition.SelectedItem;
|
---|
240 | viewSettings.UpdateView();
|
---|
241 | }
|
---|
242 |
|
---|
243 | private void LinestyleCB_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
244 | if (LineSelectCB.SelectedItem != null) {
|
---|
245 | ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Style = (DrawingStyle)LinestyleCB.SelectedItem;
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | private void LineThicknessCB_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
250 | if (LineSelectCB.SelectedItem != null) {
|
---|
251 | ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Thickness = (int)LineThicknessCB.SelectedItem;
|
---|
252 | }
|
---|
253 | }
|
---|
254 |
|
---|
255 | private void MarkercheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
256 | if (LineSelectCB.SelectedItem != null) {
|
---|
257 | ((IDataRow)LineSelectCB.SelectedItem).RowSettings.ShowMarkers = MarkercheckBox.Checked;
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | private void chkShowXAxisGrid_CheckedChanged(object sender, EventArgs e) {
|
---|
262 | model.XAxis.ShowGrid = chkShowXAxisGrid.Checked;
|
---|
263 | }
|
---|
264 |
|
---|
265 | private void tbxTitle_TextChanged(object sender, EventArgs e) {
|
---|
266 | model.Title = tbxTitle.Text;
|
---|
267 | model.ViewSettings.UpdateView();
|
---|
268 | }
|
---|
269 |
|
---|
270 | private void selectedLineColorSelection_ColorChanged(ColorSelection sender) {
|
---|
271 | if(LineSelectCB.SelectedItem!=null)
|
---|
272 | ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Color = selectedLineColorSelection.Color;
|
---|
273 | }
|
---|
274 |
|
---|
275 | private void xAxisGridColorSelection_ColorChanged(ColorSelection sender) {
|
---|
276 | model.XAxis.GridColor = xAxisGridColorSelection.Color;
|
---|
277 | }
|
---|
278 |
|
---|
279 | private void btnAddLine_Click(object sender, EventArgs e) {
|
---|
280 | addLineDialog = new AddLineDialog(model);
|
---|
281 | addLineDialog.Show();
|
---|
282 | }
|
---|
283 | }
|
---|
284 | } |
---|