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