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