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