[8907] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11170] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8907] | 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
| 23 | using System.ComponentModel;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Common.Resources;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Analysis.Views {
|
---|
| 29 | public partial class ScatterPlotVisualPropertiesDialog : Form {
|
---|
| 30 | protected bool SuppressEvents { get; set; }
|
---|
| 31 | protected ScatterPlot Content { get; private set; }
|
---|
| 32 | private ScatterPlotVisualProperties originalScatterPlotVPs;
|
---|
| 33 | private Dictionary<string, ScatterPlotDataRowVisualProperties> originalScatterPlotDataRowVPs;
|
---|
| 34 |
|
---|
| 35 | private HashSet<string> modifiedDisplayNames;
|
---|
| 36 | public IEnumerable<string> RowsWithModifiedDisplayNames { get { return modifiedDisplayNames.AsEnumerable(); } }
|
---|
| 37 |
|
---|
| 38 | public ScatterPlotVisualPropertiesDialog(ScatterPlot scatterPlot) {
|
---|
| 39 | InitializeComponent();
|
---|
| 40 | #region Prepare controls
|
---|
| 41 | upButton.Text = string.Empty;
|
---|
| 42 | upButton.Image = VSImageLibrary.ArrowUp;
|
---|
| 43 | downButton.Text = string.Empty;
|
---|
| 44 | downButton.Image = VSImageLibrary.ArrowDown;
|
---|
| 45 | seriesListView.Items.Clear();
|
---|
| 46 | seriesListView.SmallImageList = new ImageList();
|
---|
| 47 | seriesListView.SmallImageList.Images.Add(VSImageLibrary.Graph);
|
---|
| 48 | #endregion
|
---|
| 49 |
|
---|
| 50 | Content = scatterPlot;
|
---|
| 51 | originalScatterPlotVPs = (ScatterPlotVisualProperties)Content.VisualProperties.Clone();
|
---|
| 52 | originalScatterPlotDataRowVPs = new Dictionary<string, ScatterPlotDataRowVisualProperties>();
|
---|
| 53 | foreach (ScatterPlotDataRow row in Content.Rows)
|
---|
| 54 | originalScatterPlotDataRowVPs.Add(row.Name, (ScatterPlotDataRowVisualProperties)row.VisualProperties.Clone());
|
---|
| 55 |
|
---|
| 56 | dataTableVisualPropertiesControl.Content = Content.VisualProperties;
|
---|
| 57 |
|
---|
| 58 | modifiedDisplayNames = new HashSet<string>();
|
---|
| 59 | FillSeriesListView();
|
---|
| 60 | RegisterContentEvents();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | private void RegisterContentEvents() {
|
---|
| 64 | foreach (ScatterPlotDataRow row in Content.Rows) {
|
---|
| 65 | row.VisualProperties.PropertyChanged += new PropertyChangedEventHandler(Row_VisualProperties_PropertyChanged);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | private void DeregisterContentEvents() {
|
---|
| 70 | foreach (ScatterPlotDataRow row in Content.Rows) {
|
---|
| 71 | row.VisualProperties.PropertyChanged -= new PropertyChangedEventHandler(Row_VisualProperties_PropertyChanged);
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | protected override void OnClosing(CancelEventArgs e) {
|
---|
| 76 | DeregisterContentEvents();
|
---|
| 77 | Application.DoEvents();
|
---|
| 78 | base.OnClosing(e);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | private void Row_VisualProperties_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 82 | foreach (ScatterPlotDataRow row in Content.Rows) {
|
---|
| 83 | if (e.PropertyName == "DisplayName" && row.VisualProperties == sender) {
|
---|
| 84 | modifiedDisplayNames.Add(row.Name);
|
---|
| 85 | break;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | private void seriesListView_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 91 | if (!SuppressEvents) {
|
---|
| 92 | if (seriesListView.SelectedItems.Count != 1) {
|
---|
| 93 | dataRowVisualPropertiesControl.Content = null;
|
---|
| 94 | upButton.Enabled = downButton.Enabled = false;
|
---|
| 95 | } else {
|
---|
| 96 | string rowName = seriesListView.SelectedItems[0].Text;
|
---|
| 97 | dataRowVisualPropertiesControl.Content = Content.Rows[rowName].VisualProperties;
|
---|
| 98 | upButton.Enabled = seriesListView.SelectedIndices[0] > 0;
|
---|
| 99 | downButton.Enabled = seriesListView.SelectedIndices[0] < seriesListView.Items.Count - 1;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | private void okButton_Click(object sender, System.EventArgs e) {
|
---|
| 105 | DialogResult = DialogResult.OK;
|
---|
| 106 | Close();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | private void cancelButton_Click(object sender, System.EventArgs e) {
|
---|
| 110 | DialogResult = DialogResult.Cancel;
|
---|
| 111 | foreach (ScatterPlotDataRow row in Content.Rows) {
|
---|
| 112 | row.VisualProperties = originalScatterPlotDataRowVPs[row.Name];
|
---|
| 113 | }
|
---|
| 114 | modifiedDisplayNames.Clear();
|
---|
| 115 | Content.VisualProperties = originalScatterPlotVPs;
|
---|
| 116 | Close();
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | private void upButton_Click(object sender, System.EventArgs e) {
|
---|
| 120 | if (seriesListView.SelectedIndices.Count == 1 && seriesListView.SelectedIndices[0] > 0) {
|
---|
| 121 | int index = seriesListView.SelectedIndices[0];
|
---|
| 122 | SuppressEvents = true;
|
---|
| 123 | try {
|
---|
| 124 | seriesListView.BeginUpdate();
|
---|
| 125 | ListViewItem selectedSeriesItem = seriesListView.Items[index];
|
---|
| 126 | seriesListView.Items.RemoveAt(index);
|
---|
| 127 | ListViewItem temp = seriesListView.Items[index - 1];
|
---|
| 128 | seriesListView.Items.RemoveAt(index - 1);
|
---|
| 129 | seriesListView.Items.Insert(index - 1, selectedSeriesItem);
|
---|
| 130 | seriesListView.Items.Insert(index, temp);
|
---|
| 131 | seriesListView.SelectedIndices.Clear();
|
---|
| 132 | seriesListView.EndUpdate();
|
---|
| 133 | }
|
---|
| 134 | finally { SuppressEvents = false; }
|
---|
| 135 | seriesListView.SelectedIndices.Add(index - 1);
|
---|
| 136 | UpdateAllSeriesPositions();
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | private void downButton_Click(object sender, System.EventArgs e) {
|
---|
| 141 | if (seriesListView.SelectedIndices.Count == 1 && seriesListView.SelectedIndices[0] < seriesListView.Items.Count - 1) {
|
---|
| 142 | int index = seriesListView.SelectedIndices[0];
|
---|
| 143 | SuppressEvents = true;
|
---|
| 144 | try {
|
---|
| 145 | seriesListView.BeginUpdate();
|
---|
| 146 | ListViewItem temp = seriesListView.Items[index + 1];
|
---|
| 147 | seriesListView.Items.RemoveAt(index + 1);
|
---|
| 148 | ListViewItem selectedSeriesItem = seriesListView.Items[index];
|
---|
| 149 | seriesListView.Items.RemoveAt(index);
|
---|
| 150 | seriesListView.Items.Insert(index, temp);
|
---|
| 151 | seriesListView.Items.Insert(index + 1, selectedSeriesItem);
|
---|
| 152 | seriesListView.SelectedIndices.Clear();
|
---|
| 153 | seriesListView.EndUpdate();
|
---|
| 154 | }
|
---|
| 155 | finally { SuppressEvents = false; }
|
---|
| 156 | seriesListView.SelectedIndices.Add(index + 1);
|
---|
| 157 | UpdateAllSeriesPositions();
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | #region Helpers
|
---|
| 162 | private void FillSeriesListView() {
|
---|
| 163 | seriesListView.SelectedIndices.Clear();
|
---|
| 164 | foreach (ScatterPlotDataRow row in Content.Rows) {
|
---|
| 165 | seriesListView.Items.Add(new ListViewItem(row.Name, 0));
|
---|
| 166 | }
|
---|
| 167 | if (seriesListView.Items.Count > 0)
|
---|
| 168 | seriesListView.SelectedIndices.Add(0);
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | private void UpdateAllSeriesPositions() {
|
---|
| 172 | Dictionary<string, ScatterPlotDataRow> rows = Content.Rows.ToDictionary(x => x.Name);
|
---|
| 173 | Content.Rows.Clear();
|
---|
| 174 | for (int i = 0; i < seriesListView.Items.Count; i++) {
|
---|
| 175 | ListViewItem item = seriesListView.Items[i];
|
---|
| 176 | Content.Rows.Add(rows[item.Text]);
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 | #endregion
|
---|
| 180 | }
|
---|
| 181 | }
|
---|