- Timestamp:
- 11/29/08 12:40:21 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/DataRow.cs
r860 r867 4 4 5 5 namespace HeuristicLab.Visualization { 6 public enum Action { 7 Added, 8 Modified, 9 Deleted 10 } 11 6 12 public delegate void DataRowChangedHandler(IDataRow row); 7 public delegate void ValuesChangedHandler(IDataRow row, double[] values, int index );8 public delegate void ValueChangedHandler(IDataRow row, double value, int index );13 public delegate void ValuesChangedHandler(IDataRow row, double[] values, int index, Action action); 14 public delegate void ValueChangedHandler(IDataRow row, double value, int index, Action action); 9 15 10 16 public class DataRow : IDataRow { … … 15 21 private List<double> dataRow = new List<double>(); 16 22 23 24 public DataRow(string label) { 25 this.Label = label; 26 } 27 28 public DataRow(string label, Color color, int thickness, DrawingStyle style, List<double> dataRow) { 29 this.Label = label; 30 this.Color = color; 31 this.Thickness = thickness; 32 this.Style = style; 33 this.dataRow = dataRow; 34 } 35 17 36 /// <summary> 18 37 /// Raised when data row data changed. Should cause redraw in the view. … … 28 47 public event ValuesChangedHandler ValuesChanged; 29 48 30 protected void OnValuesChanged(double[] values, int index ) {49 protected void OnValuesChanged(double[] values, int index, Action action) { 31 50 if (ValuesChanged != null) { 32 ValuesChanged(this, values, index );51 ValuesChanged(this, values, index, action); 33 52 } 34 53 } … … 36 55 public event ValueChangedHandler ValueChanged; 37 56 38 protected void OnValueChanged(double value, int index ) {57 protected void OnValueChanged(double value, int index, Action action) { 39 58 if (ValueChanged != null) { 40 ValueChanged(this, value, index );59 ValueChanged(this, value, index, action); 41 60 } 42 61 } … … 76 95 public void AddValue(double value) { 77 96 dataRow.Add(value); 78 OnValueChanged(value, dataRow.Count - 1 );97 OnValueChanged(value, dataRow.Count - 1, Action.Added); 79 98 } 80 99 81 100 public void AddValue(double value, int index) { 82 dataRow.Add(value); 83 OnValueChanged(value, index); 101 //check if index is valid 102 if (index >= 0 && index < dataRow.Count) { 103 dataRow.Insert(index, value); 104 OnValueChanged(value, index, Action.Added); 105 } else { 106 throw new System.IndexOutOfRangeException(); 107 } 84 108 } 85 109 … … 90 114 dataRow.Add(d); 91 115 } 92 93 OnValuesChanged(values, startInd); 116 OnValuesChanged(values, startInd, Action.Added); 94 117 } 95 118 96 119 public void AddValues(double[] values, int index) { 120 int j = index; 121 97 122 //check if index to start changes is valid 98 if (index + values.Length< dataRow.Count) {123 if (index >=0 && (index + values.Length) < dataRow.Count) { 99 124 foreach (double d in values) { 100 dataRow.Add(d); 125 dataRow.Insert(j, d); 126 j++; 101 127 } 102 OnValuesChanged(values, index );128 OnValuesChanged(values, index, Action.Added); 103 129 } else { 104 130 throw new System.IndexOutOfRangeException(); … … 107 133 108 134 public void ModifyValue(double value, int index) { 109 throw new NotImplementedException(); 110 // TODO ValueChangedEvent auslösen 135 //check if index is valid 136 if (index >= 0 && index < dataRow.Count) { 137 dataRow[index] = value; 138 OnValueChanged(value, index, Action.Modified); 139 } else { 140 throw new System.IndexOutOfRangeException(); 141 } 111 142 } 112 143 113 144 public void ModifyValues(double[] values, int index) { 114 throw new NotImplementedException(); 115 // TODO ValuesChangedEvent auslösen 145 int startInd = index; 146 int modInd = index; 147 148 //check if index to start modification is valid 149 if (startInd >=0 && startInd + values.Length < dataRow.Count) { 150 foreach (double d in values) { 151 dataRow[modInd] = d; 152 modInd++; 153 } 154 OnValuesChanged(values, startInd, Action.Modified); 155 } else { 156 throw new System.IndexOutOfRangeException(); 157 } 116 158 } 117 159 118 160 public void RemoveValue(int index) { 119 throw new NotImplementedException(); 120 // TODO ValueChangedEvent auslösen 161 double remVal = dataRow[index]; 162 //check if index is valid 163 if (index >= 0 && index < dataRow.Count) { 164 dataRow.RemoveAt(index); 165 OnValueChanged(remVal, index, Action.Deleted); 166 } else { 167 throw new System.IndexOutOfRangeException(); 168 } 121 169 } 122 170 123 171 public void RemoveValues(int index, int count) { 124 throw new NotImplementedException(); 125 // TODO ValuesChangedEvent auslösen 172 double[] remValues = new double[count]; //removed values 173 int j = 0; 174 175 //check if count is valid 176 if (count > 0) { 177 //check if index is valid 178 if ((index >= 0) && (index + count <= dataRow.Count)) { 179 for (int i = index; i < (index + count); i++) { 180 remValues.SetValue(i, j); 181 dataRow.RemoveAt(i); 182 j++; 183 } 184 OnValuesChanged(remValues, index, Action.Deleted); 185 } else { 186 throw new System.IndexOutOfRangeException(); 187 } 188 } else { 189 throw new System.Exception("parameter count must be > 0!"); 190 } 126 191 } 127 192 … … 134 199 set { 135 200 dataRow[index] = value; 136 OnValueChanged(value, index );201 OnValueChanged(value, index, Action.Modified); 137 202 } 138 203 }
Note: See TracChangeset
for help on using the changeset viewer.