[761] | 1 | using System;
|
---|
| 2 | using System.Drawing;
|
---|
[860] | 3 | using System.Collections.Generic;
|
---|
[761] | 4 |
|
---|
| 5 | namespace HeuristicLab.Visualization {
|
---|
| 6 | 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);
|
---|
| 9 |
|
---|
| 10 | public class DataRow : IDataRow {
|
---|
| 11 | private string label = "";
|
---|
| 12 | private Color color = Color.Black;
|
---|
| 13 | private int thickness = 2;
|
---|
| 14 | private DrawingStyle style = DrawingStyle.Solid;
|
---|
[860] | 15 | private List<double> dataRow = new List<double>();
|
---|
[761] | 16 |
|
---|
| 17 | /// <summary>
|
---|
| 18 | /// Raised when data row data changed. Should cause redraw in the view.
|
---|
| 19 | /// </summary>
|
---|
| 20 | public event DataRowChangedHandler DataRowChanged;
|
---|
| 21 |
|
---|
| 22 | protected void OnDataRowChanged(IDataRow row) {
|
---|
| 23 | if (DataRowChanged != null) {
|
---|
| 24 | DataRowChanged(this);
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public event ValuesChangedHandler ValuesChanged;
|
---|
| 29 |
|
---|
| 30 | protected void OnValuesChanged(double[] values, int index) {
|
---|
| 31 | if (ValuesChanged != null) {
|
---|
| 32 | ValuesChanged(this, values, index);
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public event ValueChangedHandler ValueChanged;
|
---|
| 37 |
|
---|
| 38 | protected void OnValueChanged(double value, int index) {
|
---|
| 39 | if (ValueChanged != null) {
|
---|
| 40 | ValueChanged(this, value, index);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public string Label {
|
---|
| 45 | get { return label; }
|
---|
| 46 | set {
|
---|
| 47 | label = value;
|
---|
| 48 | OnDataRowChanged(this);
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public Color Color {
|
---|
| 53 | get { return color; }
|
---|
| 54 | set {
|
---|
| 55 | color = value;
|
---|
| 56 | OnDataRowChanged(this);
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public int Thickness {
|
---|
| 61 | get { return thickness; }
|
---|
| 62 | set {
|
---|
| 63 | thickness = value;
|
---|
| 64 | OnDataRowChanged(this);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | public DrawingStyle Style {
|
---|
| 69 | get { return style; }
|
---|
| 70 | set {
|
---|
| 71 | style = value;
|
---|
| 72 | OnDataRowChanged(this);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | public void AddValue(double value) {
|
---|
[860] | 77 | dataRow.Add(value);
|
---|
| 78 | OnValueChanged(value, dataRow.Count - 1);
|
---|
[761] | 79 | }
|
---|
| 80 |
|
---|
| 81 | public void AddValue(double value, int index) {
|
---|
[860] | 82 | dataRow.Add(value);
|
---|
| 83 | OnValueChanged(value, index);
|
---|
[761] | 84 | }
|
---|
| 85 |
|
---|
| 86 | public void AddValues(double[] values) {
|
---|
[860] | 87 | int startInd = dataRow.Count;
|
---|
| 88 |
|
---|
| 89 | foreach (double d in values) {
|
---|
| 90 | dataRow.Add(d);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | OnValuesChanged(values, startInd);
|
---|
[761] | 94 | }
|
---|
| 95 |
|
---|
| 96 | public void AddValues(double[] values, int index) {
|
---|
[860] | 97 | //check if index to start changes is valid
|
---|
| 98 | if (index + values.Length < dataRow.Count) {
|
---|
| 99 | foreach (double d in values) {
|
---|
| 100 | dataRow.Add(d);
|
---|
| 101 | }
|
---|
| 102 | OnValuesChanged(values, index);
|
---|
| 103 | } else {
|
---|
| 104 | throw new System.IndexOutOfRangeException();
|
---|
| 105 | }
|
---|
[761] | 106 | }
|
---|
| 107 |
|
---|
| 108 | public void ModifyValue(double value, int index) {
|
---|
| 109 | throw new NotImplementedException();
|
---|
| 110 | // TODO ValueChangedEvent auslösen
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public void ModifyValues(double[] values, int index) {
|
---|
| 114 | throw new NotImplementedException();
|
---|
| 115 | // TODO ValuesChangedEvent auslösen
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | public void RemoveValue(int index) {
|
---|
| 119 | throw new NotImplementedException();
|
---|
| 120 | // TODO ValueChangedEvent auslösen
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | public void RemoveValues(int index, int count) {
|
---|
| 124 | throw new NotImplementedException();
|
---|
| 125 | // TODO ValuesChangedEvent auslösen
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public int Count {
|
---|
[860] | 129 | get { return dataRow.Count; }
|
---|
[761] | 130 | }
|
---|
| 131 |
|
---|
| 132 | public double this[int index] {
|
---|
[860] | 133 | get { return dataRow[index]; }
|
---|
[761] | 134 | set {
|
---|
[860] | 135 | dataRow[index] = value;
|
---|
| 136 | OnValueChanged(value, index);
|
---|
[761] | 137 | }
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | } |
---|