Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/Options/AddLineDialog.cs @ 3038

Last change on this file since 3038 was 2040, checked in by dwagner, 15 years ago

dw: Added new dialog for adding lines using the options dialog. (#478)

File size: 4.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Reflection;
5using System.Windows.Forms;
6
7namespace HeuristicLab.Visualization.Options {
8  public partial class AddLineDialog : Form {
9    private readonly IChartDataRowsModel model;
10
11    public AddLineDialog(IChartDataRowsModel model) {
12      InitializeComponent();
13      this.model = model;
14    }
15
16    private void AddLineDialog_Load(object sender, EventArgs e) {
17      cbAddLineDialogGeneralType.SelectedIndex = 0;
18      clbAddLineDialogAggregatorLines.Enabled = false;
19      clbAddLineDialogAggregatorLines.DataSource = model.Rows;
20      clbAddLineDialogAggregatorLines.DisplayMember = "Label";
21      cbAddLineDialogYAxis.DataSource = model.YAxes;
22      cbAddLineDialogYAxis.DisplayMember = "Label";
23    }
24
25    private void cbAddLineDialogGeneralType_SelectedIndexChanged(object sender,
26                                                                 EventArgs e) {
27      if (cbAddLineDialogGeneralType.SelectedItem != null) {
28        if (cbAddLineDialogGeneralType.SelectedIndex == 1) {
29//Aggregator selected
30          clbAddLineDialogAggregatorLines.Enabled = true;
31          cbAddLineDialogYAxis.Enabled = false;
32          Type[] types = Assembly.GetExecutingAssembly().GetTypes();
33          List<Type> aggregatorTypes = new List<Type>();
34          foreach (Type type in types) {
35            if (type.GetInterface(typeof (IAggregator).FullName) != null) {
36              aggregatorTypes.Add(type);
37            }
38          }
39          cbAddLineDialogSubtype.DataSource = aggregatorTypes;
40          cbAddLineDialogSubtype.DisplayMember = "Name";
41        } else {
42          cbAddLineDialogYAxis.Enabled = true;
43          clbAddLineDialogAggregatorLines.Enabled = false;
44          cbAddLineDialogSubtype.DataSource = null;
45          cbAddLineDialogSubtype.Items.Clear();
46          cbAddLineDialogSubtype.Items.Add(DataRowType.Normal);
47          cbAddLineDialogSubtype.Items.Add(DataRowType.Points);
48          cbAddLineDialogSubtype.Items.Add(DataRowType.SingleValue);
49          cbAddLineDialogSubtype.SelectedIndex = 0;
50        }
51      }
52    }
53
54    private void btnAddLineDialogCancel_Click(object sender, EventArgs e) {
55      Close();
56    }
57
58    private void btnAddLineDialogOk_Click(object sender, EventArgs e) {
59      //TODO: Generate the new DataRow and add it to the Model
60
61      string label = txtAddLineDialogLabel.Text;
62      IDataRow newDataRow;
63      if (cbAddLineDialogGeneralType.SelectedIndex == 0) {
64        //Default init in Constructor is 0!
65        newDataRow = new DataRow();
66        switch (cbAddLineDialogSubtype.SelectedIndex) {
67          case 0:
68            newDataRow.RowSettings.LineType = DataRowType.Normal;
69            break;
70          case 1:
71            newDataRow.RowSettings.LineType = DataRowType.Points;
72            break;
73          case 2:
74            newDataRow.RowSettings.LineType = DataRowType.SingleValue;
75            break;
76        }
77
78        newDataRow.YAxis = (YAxisDescriptor) cbAddLineDialogYAxis.SelectedItem;
79      } else {
80        if (cbAddLineDialogSubtype.SelectedValue == null)
81          return;
82        newDataRow =
83          (IDataRow)
84          Activator.CreateInstance((Type) cbAddLineDialogSubtype.SelectedValue);
85        YAxisDescriptor yAxis = null;
86        foreach (var item in clbAddLineDialogAggregatorLines.CheckedItems) {
87          if (yAxis == null)
88            yAxis = ((IDataRow) item).YAxis;
89          //else if (((DataRow) item).YAxis != yAxis)
90          //  throw new ArgumentException("Watches for lines on different YAxis not supported");
91          ((IAggregator) newDataRow).AddWatch((IDataRow) item);
92        }
93        newDataRow.YAxis = yAxis;
94      }
95      newDataRow.RowSettings.Label = label;
96      newDataRow.RowSettings.Color = Color.DarkRed;
97      newDataRow.RowSettings.Thickness = 3;
98      newDataRow.RowSettings.Style = DrawingStyle.Solid;
99      newDataRow.RowSettings.ShowMarkers = true;
100      model.AddDataRow(newDataRow);
101      Close();
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.