Changeset 3320
- Timestamp:
- 04/13/10 10:36:51 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs
r3317 r3320 61 61 Content.ItemChanged -= new EventHandler<EventArgs<int, int>>(Content_ItemChanged); 62 62 Content.Reset -= new EventHandler(Content_Reset); 63 Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged); 64 Content.RowNamesChanged -= new EventHandler(Content_RowNamesChanged); 63 65 base.DeregisterContentEvents(); 64 66 } … … 69 71 Content.ItemChanged += new EventHandler<EventArgs<int, int>>(Content_ItemChanged); 70 72 Content.Reset += new EventHandler(Content_Reset); 71 } 73 Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged); 74 Content.RowNamesChanged += new EventHandler(Content_RowNamesChanged); 75 } 76 77 72 78 73 79 protected override void OnContentChanged() { … … 128 134 } 129 135 136 private void Content_RowNamesChanged(object sender, EventArgs e) { 137 UpdateColumnHeaders(); 138 } 139 140 private void Content_ColumnNamesChanged(object sender, EventArgs e) { 141 UpdateRowHeaders(); 142 } 143 130 144 private void Content_ItemChanged(object sender, EventArgs<int, int> e) { 131 145 if (InvokeRequired) … … 218 232 219 233 private void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { 220 //if (Content != null && Content.SortableView) { 221 if (e.Button == MouseButtons.Left) { 222 bool addToSortedIndizes = (Control.ModifierKeys & Keys.Control) == Keys.Control; 223 SortOrder newSortOrder = SortOrder.Ascending; 224 if (sortedColumnIndizes.Any(x => x.Key == e.ColumnIndex)) { 225 SortOrder oldSortOrder = sortedColumnIndizes.Where(x => x.Key == e.ColumnIndex).First().Value; 226 int enumLength = Enum.GetValues(typeof(SortOrder)).Length; 227 newSortOrder = oldSortOrder = (SortOrder)Enum.Parse(typeof(SortOrder), ((((int)oldSortOrder) + 1) % enumLength).ToString()); 234 if (Content != null) { 235 if (e.Button == MouseButtons.Left && Content.SortableView) { 236 bool addToSortedIndizes = (Control.ModifierKeys & Keys.Control) == Keys.Control; 237 SortOrder newSortOrder = SortOrder.Ascending; 238 if (sortedColumnIndizes.Any(x => x.Key == e.ColumnIndex)) { 239 SortOrder oldSortOrder = sortedColumnIndizes.Where(x => x.Key == e.ColumnIndex).First().Value; 240 int enumLength = Enum.GetValues(typeof(SortOrder)).Length; 241 newSortOrder = oldSortOrder = (SortOrder)Enum.Parse(typeof(SortOrder), ((((int)oldSortOrder) + 1) % enumLength).ToString()); 242 } 243 244 if (!addToSortedIndizes) 245 sortedColumnIndizes.Clear(); 246 247 if (sortedColumnIndizes.Any(x => x.Key == e.ColumnIndex)) { 248 int sortedIndex = sortedColumnIndizes.FindIndex(x => x.Key == e.ColumnIndex); 249 if (newSortOrder != SortOrder.None) 250 sortedColumnIndizes[sortedIndex] = new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder); 251 else 252 sortedColumnIndizes.RemoveAt(sortedIndex); 253 } else 254 if (newSortOrder != SortOrder.None) 255 sortedColumnIndizes.Add(new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder)); 256 Sort(); 257 } else if (e.Button == MouseButtons.Right) { 258 if (Content.ColumnNames.Count() != 0) 259 contextMenu.Show(MousePosition); 228 260 } 229 230 if (!addToSortedIndizes) 231 sortedColumnIndizes.Clear(); 232 233 if (sortedColumnIndizes.Any(x => x.Key == e.ColumnIndex)) { 234 int sortedIndex = sortedColumnIndizes.FindIndex(x => x.Key == e.ColumnIndex); 235 if (newSortOrder != SortOrder.None) 236 sortedColumnIndizes[sortedIndex] = new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder); 237 else 238 sortedColumnIndizes.RemoveAt(sortedIndex); 239 } else 240 if (newSortOrder != SortOrder.None) 241 sortedColumnIndizes.Add(new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder)); 242 Sort(); 243 } else if (e.Button == MouseButtons.Right) { 244 if (Content.ColumnNames.Count() != 0) 245 contextMenu.Show(MousePosition); 246 } 247 248 //} 261 } 249 262 } 250 263 -
trunk/sources/HeuristicLab.Data/3.3/BoolMatrix.cs
r3317 r3320 89 89 set { this.RowNames = value; } 90 90 } 91 bool IStringConvertibleMatrix.SortableView { 92 get { return this.SortableView; } 93 set { this.SortableView = value; } 94 } 91 95 bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) { 92 96 return Validate(value, out errorMessage); -
trunk/sources/HeuristicLab.Data/3.3/DoubleMatrix.cs
r3317 r3320 89 89 set { this.RowNames = value; } 90 90 } 91 bool IStringConvertibleMatrix.SortableView { 92 get { return this.SortableView; } 93 set { this.SortableView = value; } 94 } 91 95 bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) { 92 96 return Validate(value, out errorMessage); -
trunk/sources/HeuristicLab.Data/3.3/IStringConvertibleMatrix.cs
r3317 r3320 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 24 using System.Collections.Generic;25 25 26 26 namespace HeuristicLab.Data { 27 27 public interface IStringConvertibleMatrix { 28 bool ReadOnlyView { get; set; }29 28 int Rows { get; set; } 30 29 int Columns { get; set; } 31 32 30 IEnumerable<string> ColumnNames { get; set; } 33 31 IEnumerable<string> RowNames { get; set; } 34 //bool SortableView { get; } 32 33 bool ReadOnlyView { get; set; } 34 bool SortableView { get; set; } 35 35 36 36 bool Validate(string value, out string errorMessage); … … 38 38 bool SetValue(string value, int rowIndex, int columnIndex); 39 39 40 event EventHandler ColumnNamesChanged; 41 event EventHandler RowNamesChanged; 40 42 event EventHandler ReadOnlyViewChanged; 43 event EventHandler SortableViewChanged; 41 44 event EventHandler<EventArgs<int, int>> ItemChanged; 42 45 event EventHandler Reset; -
trunk/sources/HeuristicLab.Data/3.3/StringMatrix.cs
r3317 r3320 67 67 } 68 68 } 69 [Storable] 70 private bool sortableView; 71 public bool SortableView { 72 get { return sortableView; } 73 set { 74 if (value != sortableView) { 75 sortableView = value; 76 OnSortableViewChanged(); 77 } 78 } 79 } 69 80 70 81 public virtual int Rows { … … 75 86 Array.Copy(matrix, newMatrix, Math.Min(value * Columns, matrix.Length)); 76 87 matrix = newMatrix; 88 while (rowNames.Count > value) 89 rowNames.RemoveAt(rowNames.Count - 1); 90 while (rowNames.Count < value) 91 rowNames.Add("Row " + rowNames.Count); 77 92 OnReset(); 78 93 } … … 87 102 Array.Copy(matrix, i * Columns, newMatrix, i * value, Math.Min(value, Columns)); 88 103 matrix = newMatrix; 104 while (columnNames.Count > value) 105 columnNames.RemoveAt(columnNames.Count - 1); 106 while (columnNames.Count < value) 107 columnNames.Add("Column " + columnNames.Count); 89 108 OnReset(); 90 109 } … … 107 126 columnNames = new List<string>(); 108 127 rowNames = new List<string>(); 128 sortableView = false; 109 129 } 110 130 public StringMatrix(int rows, int columns) { … … 116 136 columnNames = new List<string>(); 117 137 rowNames = new List<string>(); 138 sortableView = false; 118 139 } 119 140 protected StringMatrix(int rows, int columns, IEnumerable<string> columnNames) … … 134 155 columnNames = new List<string>(); 135 156 rowNames = new List<string>(); 157 sortableView = false; 136 158 } 137 159 protected StringMatrix(string[,] elements, IEnumerable<string> columnNames) … … 148 170 cloner.RegisterClonedObject(this, clone); 149 171 clone.ReadOnlyView = ReadOnlyView; 172 clone.SortableView = SortableView; 150 173 clone.matrix = (string[,])matrix.Clone(); 151 174 clone.columnNames = new List<string>(columnNames); … … 194 217 } 195 218 219 public event EventHandler ColumnNamesChanged; 220 protected virtual void OnColumnNamesChanged() { 221 EventHandler handler = ColumnNamesChanged; 222 if (handler != null) 223 handler(this, EventArgs.Empty); 224 } 225 public event EventHandler RowNamesChanged; 226 protected virtual void OnRowNamesChanged() { 227 EventHandler handler = RowNamesChanged; 228 if (handler != null) 229 handler(this, EventArgs.Empty); 230 } 231 public event EventHandler SortableViewChanged; 232 protected virtual void OnSortableViewChanged() { 233 EventHandler handler = SortableViewChanged; 234 if (handler != null) 235 handler(this, EventArgs.Empty); 236 } 196 237 public event EventHandler<EventArgs<int, int>> ItemChanged; 197 238 protected virtual void OnItemChanged(int rowIndex, int columnIndex) { … … 224 265 set { this.RowNames = value; } 225 266 } 267 bool IStringConvertibleMatrix.SortableView { 268 get { return this.SortableView; } 269 set { this.SortableView = value; } 270 } 226 271 bool IStringConvertibleMatrix.Validate(string value, out string errorMessage) { 227 272 return Validate(value, out errorMessage); -
trunk/sources/HeuristicLab.Data/3.3/ValueTypeMatrix.cs
r3310 r3320 67 67 } 68 68 } 69 [Storable] 70 private bool sortableView; 71 public bool SortableView { 72 get { return sortableView; } 73 set { 74 if (value != sortableView) { 75 sortableView = value; 76 OnSortableViewChanged(); 77 } 78 } 79 } 69 80 70 81 public virtual int Rows { … … 75 86 Array.Copy(matrix, newArray, Math.Min(value * Columns, matrix.Length)); 76 87 matrix = newArray; 88 while (rowNames.Count > value) 89 rowNames.RemoveAt(rowNames.Count - 1); 90 while (rowNames.Count < value) 91 rowNames.Add("Row " + rowNames.Count); 77 92 OnReset(); 78 93 } … … 87 102 Array.Copy(matrix, i * Columns, newArray, i * value, Math.Min(value, Columns)); 88 103 matrix = newArray; 104 while (columnNames.Count > value) 105 columnNames.RemoveAt(columnNames.Count - 1); 106 while (columnNames.Count < value) 107 columnNames.Add("Column " + columnNames.Count); 89 108 OnReset(); 90 109 } … … 105 124 columnNames = new List<string>(); 106 125 rowNames = new List<string>(); 126 sortableView = false; 107 127 } 108 128 protected ValueTypeMatrix(int rows, int columns) { … … 110 130 columnNames = new List<string>(); 111 131 rowNames = new List<string>(); 132 sortableView = false; 112 133 } 113 134 protected ValueTypeMatrix(int rows, int columns, IEnumerable<string> columnNames) … … 124 145 columnNames = new List<string>(); 125 146 rowNames = new List<string>(); 147 sortableView = false; 126 148 } 127 149 protected ValueTypeMatrix(T[,] elements, IEnumerable<string> columnNames) … … 136 158 public override IDeepCloneable Clone(Cloner cloner) { 137 159 ValueTypeMatrix<T> clone = (ValueTypeMatrix<T>)base.Clone(cloner); 160 clone.SortableView = SortableView; 138 161 clone.matrix = (T[,])matrix.Clone(); 139 162 clone.columnNames = new List<string>(columnNames); … … 161 184 } 162 185 186 public event EventHandler ColumnNamesChanged; 187 protected virtual void OnColumnNamesChanged() { 188 EventHandler handler = ColumnNamesChanged; 189 if(handler!=null) 190 handler(this,EventArgs.Empty); 191 } 192 public event EventHandler RowNamesChanged; 193 protected virtual void OnRowNamesChanged() { 194 EventHandler handler = RowNamesChanged; 195 if (handler != null) 196 handler(this, EventArgs.Empty); 197 } 198 public event EventHandler SortableViewChanged; 199 protected virtual void OnSortableViewChanged() { 200 EventHandler handler = SortableViewChanged; 201 if (handler != null) 202 handler(this, EventArgs.Empty); 203 } 163 204 public event EventHandler<EventArgs<int, int>> ItemChanged; 164 205 protected virtual void OnItemChanged(int rowIndex, int columnIndex) {
Note: See TracChangeset
for help on using the changeset viewer.