using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using HeuristicLab.Visualization.Legend; namespace HeuristicLab.Visualization.Options { public partial class Options : UserControl { private IChartDataRowsModel model; private ViewSettings viewSettings; private ViewSettings oldViewSettings; private List oldLineParams; private string oldTitle; private Dictionary ShowYAxisBoxes; private bool oldShowXAxisGrid; private Color oldXAxisGridColor; private Font oldXAxisFont; private Color oldXAxisColor; private Dictionary yAxisClipChangeableBoxes; internal class LineParams { private string Label { get; set; } private Color Color { get; set; } private bool ShowMarkers { get; set; } private int Thickness { get; set; } private DrawingStyle Style { get; set; } private readonly IDataRow row; public LineParams(IDataRow row) { Label = row.RowSettings.Label; Color = row.RowSettings.Color; Thickness = row.RowSettings.Thickness; Style = row.RowSettings.Style; this.row = row; this.ShowMarkers = row.RowSettings.ShowMarkers; } public void applySettings() { row.RowSettings.Label = Label; row.RowSettings.Color = Color; row.RowSettings.Thickness = Thickness; row.RowSettings.Style = Style; row.RowSettings.ShowMarkers = this.ShowMarkers; } } public Options() { InitializeComponent(); cbLegendPosition.Items.Add(LegendPosition.Top); cbLegendPosition.Items.Add(LegendPosition.Bottom); cbLegendPosition.Items.Add(LegendPosition.Left); cbLegendPosition.Items.Add(LegendPosition.Right); Model = new ChartDataRowsModel(); } public IChartDataRowsModel Model { get { return model; } set { model = value; oldTitle = model.Title; tbxTitle.Text = model.Title; viewSettings = model.ViewSettings; oldViewSettings = new ViewSettings(model.ViewSettings); cbLegendPosition.SelectedItem = viewSettings.LegendPosition; } } public void ResetSettings() { model.XAxis.ShowGrid = oldShowXAxisGrid; chkShowXAxisGrid.Checked = oldShowXAxisGrid; model.XAxis.Color = oldXAxisColor; model.XAxis.Font = oldXAxisFont; model.XAxis.GridColor = oldXAxisGridColor; xAxisGridColorSelection.Color = oldXAxisGridColor; foreach (var param in oldLineParams) { param.applySettings(); } foreach (var box in ShowYAxisBoxes) { box.Key.Checked = box.Value; } foreach (KeyValuePair box in yAxisClipChangeableBoxes) { box.Key.Checked = box.Value; } model.Title = oldTitle; tbxTitle.Text = oldTitle; viewSettings.LegendColor = oldViewSettings.LegendColor; viewSettings.LegendPosition = oldViewSettings.LegendPosition; viewSettings.LegendFont = oldViewSettings.LegendFont; viewSettings.TitleColor = oldViewSettings.TitleColor; viewSettings.TitleFont = oldViewSettings.TitleFont; viewSettings.UpdateView(); cbLegendPosition.SelectedItem = viewSettings.LegendPosition; this.LineSelectCB_SelectedIndexChanged(this, null); } private static IList GetThicknesses() { return new List(new[] {1, 2, 3, 4, 5, 6, 7, 8}); } private static IList GetStyles() { return new List(new[] {DrawingStyle.Solid, DrawingStyle.Dashed}); } private void btnChangeLegendFont_Click(object sender, EventArgs e) { fdFont.Font = viewSettings.LegendFont; fdFont.Color = viewSettings.LegendColor; DialogResult dr = fdFont.ShowDialog(); if (dr == DialogResult.OK) { viewSettings.LegendFont = fdFont.Font; viewSettings.LegendColor = fdFont.Color; viewSettings.UpdateView(); } } private void btnChangeTitleFont_Click(object sender, EventArgs e) { fdFont.Font = viewSettings.TitleFont; fdFont.Color = viewSettings.TitleColor; DialogResult dr = fdFont.ShowDialog(); if (dr == DialogResult.OK) { viewSettings.TitleFont = fdFont.Font; viewSettings.TitleColor = fdFont.Color; viewSettings.UpdateView(); } } private void btnChangeXAxisFont_Click(object sender, EventArgs e) { fdFont.Font = model.XAxis.Font; fdFont.Color = model.XAxis.Color; DialogResult dr = fdFont.ShowDialog(); if (dr == DialogResult.OK) { model.XAxis.Font = fdFont.Font; model.XAxis.Color = fdFont.Color; viewSettings.UpdateView(); } } private void Options_Load(object sender, EventArgs e) { model.DataRowAdded += model_DataRowAdded; oldShowXAxisGrid = model.XAxis.ShowGrid; chkShowXAxisGrid.Checked = model.XAxis.ShowGrid; oldXAxisGridColor = model.XAxis.GridColor; xAxisGridColorSelection.Color = model.XAxis.GridColor; oldXAxisFont = model.XAxis.Font; oldXAxisColor = model.XAxis.Color; InitTabPageLines(); InitTabPageYAxes(); } void model_DataRowAdded(IDataRow row) { LineSelectCB.Items.Add(row); oldLineParams.Add(new LineParams(row)); } private void InitTabPageLines() { if (model.Rows.Count != 0) { int index = 0; oldLineParams = new List(); foreach (var row in model.Rows) { oldLineParams.Add(new LineParams(row)); LineSelectCB.Items.Add(row); } LineThicknessCB.DataSource = GetThicknesses(); LinestyleCB.DataSource = GetStyles(); LinestyleCB.SelectedItem = model.Rows[0].RowSettings.Style; LineThicknessCB.SelectedItem = model.Rows[0].RowSettings.Thickness; MarkercheckBox.Checked = model.Rows[0].RowSettings.ShowMarkers; // LineSelectCB.DataSource = model.Rows; LineSelectCB.DisplayMember = "RowSettings.Label"; LineSelectCB.SelectedIndex = 0; LineSelectCB_SelectedIndexChanged(this, null); } } private void InitTabPageYAxes() { ShowYAxisBoxes = new Dictionary(); yAxisClipChangeableBoxes = new Dictionary(); for (int i = 0; i < model.YAxes.Count; i++) { YAxisDescriptor yAxisDescriptor = model.YAxes[i]; CheckBox cbxShowYAxis = new CheckBox(); cbxShowYAxis.Text = yAxisDescriptor.Label; cbxShowYAxis.Checked = yAxisDescriptor.ShowYAxis; ShowYAxisBoxes[cbxShowYAxis] = yAxisDescriptor.ShowYAxis; cbxShowYAxis.CheckedChanged += delegate { yAxisDescriptor.ShowYAxis = cbxShowYAxis.Checked; }; flpShowYAxis.Controls.Add(cbxShowYAxis); CheckBox cbxClipChangeable = new CheckBox(); cbxClipChangeable.Text = yAxisDescriptor.Label; cbxClipChangeable.Checked = yAxisDescriptor.ClipChangeable; yAxisClipChangeableBoxes[cbxClipChangeable] = yAxisDescriptor.ClipChangeable; cbxClipChangeable.CheckedChanged += delegate { yAxisDescriptor.ClipChangeable = cbxClipChangeable.Checked; }; flpYAxisClipChangeable.Controls.Add(cbxClipChangeable); } } private void LineSelectCB_SelectedIndexChanged(object sender, EventArgs e) { if (LineSelectCB.SelectedItem != null) { /* int index = LineThicknessCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Thickness.ToString()); LineThicknessCB.SelectedIndex = index; index = LinestyleCB.FindStringExact(((IDataRow)LineSelectCB.SelectedValue).Style.ToString()); LinestyleCB.SelectedIndex = index; */ LineThicknessCB.SelectedItem = ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Thickness; LinestyleCB.SelectedItem = ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Style; selectedLineColorSelection.Color = ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Color; MarkercheckBox.Checked = ((IDataRow)LineSelectCB.SelectedItem).RowSettings.ShowMarkers; } } private void cbLegendPosition_SelectedIndexChanged(object sender, EventArgs e) { viewSettings.LegendPosition = (LegendPosition)cbLegendPosition.SelectedItem; viewSettings.UpdateView(); } private void LinestyleCB_SelectedIndexChanged(object sender, EventArgs e) { if (LineSelectCB.SelectedItem != null) { ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Style = (DrawingStyle)LinestyleCB.SelectedItem; } } private void LineThicknessCB_SelectedIndexChanged(object sender, EventArgs e) { if (LineSelectCB.SelectedItem != null) { ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Thickness = (int)LineThicknessCB.SelectedItem; } } private void MarkercheckBox_CheckedChanged(object sender, EventArgs e) { if (LineSelectCB.SelectedItem != null) { ((IDataRow)LineSelectCB.SelectedItem).RowSettings.ShowMarkers = MarkercheckBox.Checked; } } private void chkShowXAxisGrid_CheckedChanged(object sender, EventArgs e) { model.XAxis.ShowGrid = chkShowXAxisGrid.Checked; } private void tbxTitle_TextChanged(object sender, EventArgs e) { model.Title = tbxTitle.Text; model.ViewSettings.UpdateView(); } private void selectedLineColorSelection_ColorChanged(ColorSelection sender) { if(LineSelectCB.SelectedItem!=null) ((IDataRow)LineSelectCB.SelectedItem).RowSettings.Color = selectedLineColorSelection.Color; } private void xAxisGridColorSelection_ColorChanged(ColorSelection sender) { model.XAxis.GridColor = xAxisGridColorSelection.Color; } private void btnAddLine_Click(object sender, EventArgs e) { addLineDialog = new AddLineDialog(model); addLineDialog.Show(); } } }