[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;
|
---|
[2040] | 12 | private List<LineParams> oldLineParams;
|
---|
[1839] | 13 | private string oldTitle;
|
---|
[1586] | 14 | private Dictionary<CheckBox, bool> ShowYAxisBoxes;
|
---|
[1876] | 15 | private bool oldShowXAxisGrid;
|
---|
[1885] | 16 | private Color oldXAxisGridColor;
|
---|
[1993] | 17 | private Font oldXAxisFont;
|
---|
| 18 | private Color oldXAxisColor;
|
---|
[1586] | 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) {
|
---|
[1962] | 30 | Label = row.RowSettings.Label;
|
---|
| 31 | Color = row.RowSettings.Color;
|
---|
| 32 | Thickness = row.RowSettings.Thickness;
|
---|
[1972] | 33 | Style = row.RowSettings.Style;
|
---|
[1586] | 34 | this.row = row;
|
---|
[1972] | 35 | this.ShowMarkers = row.RowSettings.ShowMarkers;
|
---|
[1586] | 36 | }
|
---|
| 37 |
|
---|
| 38 | public void applySettings() {
|
---|
[1962] | 39 | row.RowSettings.Label = Label;
|
---|
| 40 | row.RowSettings.Color = Color;
|
---|
| 41 | row.RowSettings.Thickness = Thickness;
|
---|
[1972] | 42 | row.RowSettings.Style = Style;
|
---|
| 43 | row.RowSettings.ShowMarkers = this.ShowMarkers;
|
---|
[1586] | 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;
|
---|
[1839] | 62 | oldTitle = model.Title;
|
---|
| 63 | tbxTitle.Text = model.Title;
|
---|
[1586] | 64 | viewSettings = model.ViewSettings;
|
---|
| 65 | oldViewSettings = new ViewSettings(model.ViewSettings);
|
---|
| 66 | cbLegendPosition.SelectedItem = viewSettings.LegendPosition;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public void ResetSettings() {
|
---|
[1881] | 71 | model.XAxis.ShowGrid = oldShowXAxisGrid;
|
---|
[1885] | 72 | chkShowXAxisGrid.Checked = oldShowXAxisGrid;
|
---|
[1993] | 73 |
|
---|
| 74 | model.XAxis.Color = oldXAxisColor;
|
---|
| 75 | model.XAxis.Font = oldXAxisFont;
|
---|
[1885] | 76 |
|
---|
| 77 | model.XAxis.GridColor = oldXAxisGridColor;
|
---|
| 78 | xAxisGridColorSelection.Color = oldXAxisGridColor;
|
---|
[1876] | 79 |
|
---|
[1586] | 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 |
|
---|
[1839] | 92 | model.Title = oldTitle;
|
---|
| 93 | tbxTitle.Text = oldTitle;
|
---|
| 94 |
|
---|
[1586] | 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 |
|
---|
[1880] | 105 | private static IList<int> GetThicknesses() {
|
---|
[1586] | 106 | return new List<int>(new[] {1, 2, 3, 4, 5, 6, 7, 8});
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[1880] | 109 | private static IList<DrawingStyle> GetStyles() {
|
---|
[1586] | 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) {
|
---|
[1993] | 142 | fdFont.Font = model.XAxis.Font;
|
---|
| 143 | fdFont.Color = model.XAxis.Color;
|
---|
[1586] | 144 |
|
---|
| 145 | DialogResult dr = fdFont.ShowDialog();
|
---|
| 146 |
|
---|
| 147 | if (dr == DialogResult.OK) {
|
---|
[1993] | 148 | model.XAxis.Font = fdFont.Font;
|
---|
| 149 | model.XAxis.Color = fdFont.Color;
|
---|
[1586] | 150 |
|
---|
| 151 | viewSettings.UpdateView();
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | private void Options_Load(object sender, EventArgs e) {
|
---|
[2040] | 156 | model.DataRowAdded += model_DataRowAdded;
|
---|
[1881] | 157 | oldShowXAxisGrid = model.XAxis.ShowGrid;
|
---|
| 158 | chkShowXAxisGrid.Checked = model.XAxis.ShowGrid;
|
---|
[1876] | 159 |
|
---|
[1885] | 160 | oldXAxisGridColor = model.XAxis.GridColor;
|
---|
| 161 | xAxisGridColorSelection.Color = model.XAxis.GridColor;
|
---|
| 162 |
|
---|
[1993] | 163 | oldXAxisFont = model.XAxis.Font;
|
---|
| 164 | oldXAxisColor = model.XAxis.Color;
|
---|
| 165 |
|
---|
[1586] | 166 | InitTabPageLines();
|
---|
| 167 | InitTabPageYAxes();
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[2040] | 170 | void model_DataRowAdded(IDataRow row)
|
---|
| 171 | {
|
---|
| 172 | LineSelectCB.Items.Add(row);
|
---|
| 173 | oldLineParams.Add(new LineParams(row));
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[1586] | 176 | private void InitTabPageLines() {
|
---|
| 177 | if (model.Rows.Count != 0) {
|
---|
| 178 | int index = 0;
|
---|
[2040] | 179 | oldLineParams = new List<LineParams>();
|
---|
[1586] | 180 | foreach (var row in model.Rows) {
|
---|
[2040] | 181 | oldLineParams.Add(new LineParams(row));
|
---|
| 182 | LineSelectCB.Items.Add(row);
|
---|
[1586] | 183 | }
|
---|
| 184 | LineThicknessCB.DataSource = GetThicknesses();
|
---|
| 185 | LinestyleCB.DataSource = GetStyles();
|
---|
[1972] | 186 | LinestyleCB.SelectedItem = model.Rows[0].RowSettings.Style;
|
---|
[1962] | 187 | LineThicknessCB.SelectedItem = model.Rows[0].RowSettings.Thickness;
|
---|
[1972] | 188 | MarkercheckBox.Checked = model.Rows[0].RowSettings.ShowMarkers;
|
---|
[1586] | 189 |
|
---|
[2040] | 190 | // LineSelectCB.DataSource = model.Rows;
|
---|
| 191 | LineSelectCB.DisplayMember = "RowSettings.Label";
|
---|
[1586] | 192 |
|
---|
[2040] | 193 |
|
---|
[1586] | 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) {
|
---|
[2040] | 225 | if (LineSelectCB.SelectedItem != null) {
|
---|
[1586] | 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; */
|
---|
[2040] | 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;
|
---|
[1586] | 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) {
|
---|
[2040] | 244 | if (LineSelectCB.SelectedItem != null) {
|
---|
| 245 | ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Style = (DrawingStyle)LinestyleCB.SelectedItem;
|
---|
[1586] | 246 | }
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | private void LineThicknessCB_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[2040] | 250 | if (LineSelectCB.SelectedItem != null) {
|
---|
| 251 | ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Thickness = (int)LineThicknessCB.SelectedItem;
|
---|
[1586] | 252 | }
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | private void MarkercheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[2040] | 256 | if (LineSelectCB.SelectedItem != null) {
|
---|
| 257 | ((IDataRow)LineSelectCB.SelectedItem).RowSettings.ShowMarkers = MarkercheckBox.Checked;
|
---|
[1586] | 258 | }
|
---|
| 259 | }
|
---|
[1839] | 260 |
|
---|
[1876] | 261 | private void chkShowXAxisGrid_CheckedChanged(object sender, EventArgs e) {
|
---|
[1881] | 262 | model.XAxis.ShowGrid = chkShowXAxisGrid.Checked;
|
---|
[1876] | 263 | }
|
---|
| 264 |
|
---|
[1839] | 265 | private void tbxTitle_TextChanged(object sender, EventArgs e) {
|
---|
| 266 | model.Title = tbxTitle.Text;
|
---|
| 267 | model.ViewSettings.UpdateView();
|
---|
| 268 | }
|
---|
[1885] | 269 |
|
---|
| 270 | private void selectedLineColorSelection_ColorChanged(ColorSelection sender) {
|
---|
[2040] | 271 | if(LineSelectCB.SelectedItem!=null)
|
---|
| 272 | ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Color = selectedLineColorSelection.Color;
|
---|
[1885] | 273 | }
|
---|
| 274 |
|
---|
| 275 | private void xAxisGridColorSelection_ColorChanged(ColorSelection sender) {
|
---|
| 276 | model.XAxis.GridColor = xAxisGridColorSelection.Color;
|
---|
| 277 | }
|
---|
[2040] | 278 |
|
---|
| 279 | private void btnAddLine_Click(object sender, EventArgs e) {
|
---|
| 280 | addLineDialog = new AddLineDialog(model);
|
---|
| 281 | addLineDialog.Show();
|
---|
| 282 | }
|
---|
[1586] | 283 | }
|
---|
| 284 | } |
---|