source: branches/histogram/HeuristicLab.Analysis.Views/3.3/DataTableVisualPropertiesDialog.cs @ 6016

Last change on this file since 6016 was 6016, checked in by abeham, 9 years ago

#1465

  • added sorting of series to move them back and forth
    • the implementation currently is quite memory intensive in that all data rows are cloned, the collection is cleared and then they're readded in the correct order. Since the underlying collection is a collection and not a list I don't have the possibilities to insert them.
  • fixed histogram configuration
  • added a crude check if there are incompatibilities with bars
File size: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Windows.Forms;
24using HeuristicLab.Common.Resources;
25using HeuristicLab.Core;
26
27namespace HeuristicLab.Analysis.Views {
28  public partial class DataTableVisualPropertiesDialog : Form {
29    protected DataTable Content { get; private set; }
30    private DataTableVisualProperties originalDataTableVPs;
31    private Dictionary<string, DataRowVisualProperties> originalDataRowVPs;
32
33    public DataTableVisualPropertiesDialog(DataTable dataTable) {
34      InitializeComponent();
35      upButton.Text = string.Empty;
36      upButton.Image = VSImageLibrary.ArrowUp;
37      downButton.Text = string.Empty;
38      downButton.Image = VSImageLibrary.ArrowDown;
39      Content = dataTable;
40      originalDataTableVPs = (DataTableVisualProperties)Content.VisualProperties.Clone();
41      originalDataRowVPs = new Dictionary<string, DataRowVisualProperties>();
42      foreach (DataRow row in Content.Rows)
43        originalDataRowVPs.Add(row.Name, (DataRowVisualProperties)row.VisualProperties.Clone());
44      seriesListView.Items.Clear();
45      seriesListView.SmallImageList = new ImageList();
46      seriesListView.SmallImageList.Images.Add(VSImageLibrary.Graph);
47      FillSeriesListView();
48      dataTableVisualPropertiesControl.Content = Content.VisualProperties;
49    }
50
51    private void FillSeriesListView() {
52      seriesListView.SelectedIndices.Clear();
53      foreach (DataRow row in Content.Rows) {
54        seriesListView.Items.Add(new ListViewItem(row.Name, 0));
55      }
56      seriesListView.SelectedIndices.Add(0);
57    }
58
59    private void seriesListView_SelectedIndexChanged(object sender, System.EventArgs e) {
60      if (seriesListView.SelectedItems.Count == 0) return;
61      string rowName = seriesListView.SelectedItems[0].Text;
62      dataRowVisualPropertiesControl.Content = Content.Rows[rowName].VisualProperties;
63    }
64
65    private void okButton_Click(object sender, System.EventArgs e) {
66      DialogResult = DialogResult.OK;
67      Close();
68    }
69
70    private void cancelButton_Click(object sender, System.EventArgs e) {
71      DialogResult = DialogResult.Cancel;
72      foreach (DataRow row in Content.Rows) {
73        row.VisualProperties = originalDataRowVPs[row.Name];
74      }
75      Content.VisualProperties = originalDataTableVPs;
76      Close();
77    }
78
79    private void upButton_Click(object sender, System.EventArgs e) {
80      if (seriesListView.SelectedIndices.Count == 1 && seriesListView.SelectedIndices[0] > 0) {
81        int index = seriesListView.SelectedIndices[0];
82        seriesListView.BeginUpdate();
83        ListViewItem selectedSeriesItem = seriesListView.Items[index];
84        seriesListView.Items.RemoveAt(index);
85        ListViewItem temp = seriesListView.Items[index - 1];
86        seriesListView.Items.RemoveAt(index - 1);
87        seriesListView.Items.Insert(index - 1, selectedSeriesItem);
88        seriesListView.Items.Insert(index, temp);
89        seriesListView.EndUpdate();
90        UpdateAllSeriesPositions();
91      }
92    }
93
94    private void downButton_Click(object sender, System.EventArgs e) {
95      if (seriesListView.SelectedIndices.Count == 1 && seriesListView.SelectedIndices[0] < seriesListView.Items.Count - 1) {
96        int index = seriesListView.SelectedIndices[0];
97        seriesListView.BeginUpdate();
98        ListViewItem temp = seriesListView.Items[index + 1];
99        seriesListView.Items.RemoveAt(index + 1);
100        ListViewItem selectedSeriesItem = seriesListView.Items[index];
101        seriesListView.Items.RemoveAt(index);
102        seriesListView.Items.Insert(index, temp);
103        seriesListView.Items.Insert(index + 1, selectedSeriesItem);
104        seriesListView.EndUpdate();
105        UpdateAllSeriesPositions();
106      }
107    }
108
109    #region Helpers
110    private void UpdateAllSeriesPositions() {
111      NamedItemCollection<DataRow> rows = (NamedItemCollection<DataRow>)Content.Rows.Clone();
112      Content.Rows.Clear();
113      for (int i = 0; i < seriesListView.Items.Count; i++) {
114        ListViewItem item = seriesListView.Items[i];
115        Content.Rows.Add(rows[item.Text]);
116      }
117    }
118    #endregion
119  }
120}
Note: See TracBrowser for help on using the repository browser.