Changeset 2677
- Timestamp:
- 01/25/10 05:46:44 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 14 deleted
- 6 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data.Views/3.3/HeuristicLab.Data.Views-3.3.csproj
r2669 r2677 57 57 <DependentUpon>BoolDataView.cs</DependentUpon> 58 58 </Compile> 59 <Compile Include="StringConvertibleArrayDataView.cs">60 <SubType>UserControl</SubType>61 </Compile>62 <Compile Include="StringConvertibleArrayDataView.Designer.cs">63 <DependentUpon>StringConvertibleArrayDataView.cs</DependentUpon>64 </Compile>65 59 <Compile Include="StringConvertibleDataView.cs"> 66 60 <SubType>UserControl</SubType> … … 71 65 <Compile Include="HeuristicLabDataViewsPlugin.cs" /> 72 66 <Compile Include="Properties\AssemblyInfo.cs" /> 67 <Compile Include="StringConvertibleMatrixDataView.cs"> 68 <SubType>UserControl</SubType> 69 </Compile> 70 <Compile Include="StringConvertibleMatrixDataView.Designer.cs"> 71 <DependentUpon>StringConvertibleMatrixDataView.cs</DependentUpon> 72 </Compile> 73 73 </ItemGroup> 74 74 <ItemGroup> -
trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixDataView.Designer.cs
r2676 r2677 21 21 22 22 namespace HeuristicLab.Data.Views { 23 partial class StringConvertible ArrayDataView {23 partial class StringConvertibleMatrixDataView { 24 24 /// <summary> 25 25 /// Required designer variable. … … 46 46 private void InitializeComponent() { 47 47 this.components = new System.ComponentModel.Container(); 48 this. sizeLabel = new System.Windows.Forms.Label();49 this. sizeTextBox = new System.Windows.Forms.TextBox();48 this.rowsLabel = new System.Windows.Forms.Label(); 49 this.rowsTextBox = new System.Windows.Forms.TextBox(); 50 50 this.dataGridView = new System.Windows.Forms.DataGridView(); 51 51 this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components); 52 this.columnsTextBox = new System.Windows.Forms.TextBox(); 53 this.columnsLabel = new System.Windows.Forms.Label(); 52 54 ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); 53 55 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 54 56 this.SuspendLayout(); 55 57 // 56 // sizeLabel58 // rowsLabel 57 59 // 58 this. sizeLabel.AutoSize = true;59 this. sizeLabel.Location = new System.Drawing.Point(3, 3);60 this. sizeLabel.Name = "sizeLabel";61 this. sizeLabel.Size = new System.Drawing.Size(30, 13);62 this. sizeLabel.TabIndex = 0;63 this. sizeLabel.Text = "&Size:";60 this.rowsLabel.AutoSize = true; 61 this.rowsLabel.Location = new System.Drawing.Point(3, 3); 62 this.rowsLabel.Name = "rowsLabel"; 63 this.rowsLabel.Size = new System.Drawing.Size(37, 13); 64 this.rowsLabel.TabIndex = 0; 65 this.rowsLabel.Text = "&Rows:"; 64 66 // 65 // sizeTextBox67 // rowsTextBox 66 68 // 67 this. sizeTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)69 this.rowsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 68 70 | System.Windows.Forms.AnchorStyles.Right))); 69 this. sizeTextBox.Location = new System.Drawing.Point(50, 0);70 this. sizeTextBox.Name = "sizeTextBox";71 this. sizeTextBox.Size = new System.Drawing.Size(374, 20);72 this. sizeTextBox.TabIndex = 1;73 this. sizeTextBox.Validated += new System.EventHandler(this.sizeTextBox_Validated);74 this. sizeTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.sizeTextBox_KeyDown);75 this. sizeTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.sizeTextBox_Validating);71 this.rowsTextBox.Location = new System.Drawing.Point(69, 0); 72 this.rowsTextBox.Name = "rowsTextBox"; 73 this.rowsTextBox.Size = new System.Drawing.Size(355, 20); 74 this.rowsTextBox.TabIndex = 1; 75 this.rowsTextBox.Validated += new System.EventHandler(this.rowsTextBox_Validated); 76 this.rowsTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.rowsTextBox_KeyDown); 77 this.rowsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.rowsTextBox_Validating); 76 78 // 77 79 // dataGridView … … 85 87 this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 86 88 this.dataGridView.ColumnHeadersVisible = false; 87 this.dataGridView.Location = new System.Drawing.Point(0, 26);89 this.dataGridView.Location = new System.Drawing.Point(0, 52); 88 90 this.dataGridView.Name = "dataGridView"; 89 this.dataGridView.Size = new System.Drawing.Size(424, 3 78);90 this.dataGridView.TabIndex = 2;91 this.dataGridView.Size = new System.Drawing.Size(424, 352); 92 this.dataGridView.TabIndex = 4; 91 93 this.dataGridView.CellParsing += new System.Windows.Forms.DataGridViewCellParsingEventHandler(this.dataGridView_CellParsing); 92 94 this.dataGridView.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView_CellValidating); … … 98 100 this.errorProvider.ContainerControl = this; 99 101 // 100 // StringConvertibleArrayDataView 102 // columnsTextBox 103 // 104 this.columnsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 105 | System.Windows.Forms.AnchorStyles.Right))); 106 this.columnsTextBox.Location = new System.Drawing.Point(69, 26); 107 this.columnsTextBox.Name = "columnsTextBox"; 108 this.columnsTextBox.Size = new System.Drawing.Size(355, 20); 109 this.columnsTextBox.TabIndex = 3; 110 this.columnsTextBox.Validated += new System.EventHandler(this.columnsTextBox_Validated); 111 this.columnsTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.columnsTextBox_KeyDown); 112 this.columnsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.columnsTextBox_Validating); 113 // 114 // columnsLabel 115 // 116 this.columnsLabel.AutoSize = true; 117 this.columnsLabel.Location = new System.Drawing.Point(3, 29); 118 this.columnsLabel.Name = "columnsLabel"; 119 this.columnsLabel.Size = new System.Drawing.Size(50, 13); 120 this.columnsLabel.TabIndex = 2; 121 this.columnsLabel.Text = "&Columns:"; 122 // 123 // StringConvertibleMatrixDataView 101 124 // 102 125 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 103 126 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 104 127 this.Controls.Add(this.dataGridView); 105 this.Controls.Add(this.sizeTextBox); 106 this.Controls.Add(this.sizeLabel); 107 this.Name = "StringConvertibleArrayDataView"; 128 this.Controls.Add(this.columnsTextBox); 129 this.Controls.Add(this.rowsTextBox); 130 this.Controls.Add(this.columnsLabel); 131 this.Controls.Add(this.rowsLabel); 132 this.Name = "StringConvertibleMatrixDataView"; 108 133 this.Size = new System.Drawing.Size(424, 404); 109 134 ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); … … 116 141 #endregion 117 142 118 private System.Windows.Forms.Label sizeLabel;119 private System.Windows.Forms.TextBox sizeTextBox;143 private System.Windows.Forms.Label rowsLabel; 144 private System.Windows.Forms.TextBox rowsTextBox; 120 145 private System.Windows.Forms.DataGridView dataGridView; 121 146 private System.Windows.Forms.ErrorProvider errorProvider; 147 private System.Windows.Forms.TextBox columnsTextBox; 148 private System.Windows.Forms.Label columnsLabel; 122 149 123 150 } -
trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixDataView.cs
r2676 r2677 33 33 34 34 namespace HeuristicLab.Data.Views { 35 [Content(typeof(IStringConvertible ArrayData), true)]36 public partial class StringConvertible ArrayDataView : ObjectView {37 public IStringConvertible ArrayData StringConvertibleArrayData {38 get { return (IStringConvertible ArrayData)Object; }35 [Content(typeof(IStringConvertibleMatrixData), true)] 36 public partial class StringConvertibleMatrixDataView : ObjectView { 37 public IStringConvertibleMatrixData StringConvertibleMatrixData { 38 get { return (IStringConvertibleMatrixData)Object; } 39 39 set { base.Object = value; } 40 40 } 41 41 42 public StringConvertible ArrayDataView() {42 public StringConvertibleMatrixDataView() { 43 43 InitializeComponent(); 44 Caption = "StringConvertibleArrayDataView View"; 45 errorProvider.SetIconAlignment(sizeTextBox, ErrorIconAlignment.MiddleLeft); 46 errorProvider.SetIconPadding(sizeTextBox, 2); 44 Caption = "StringConvertibleMatrixDataView View"; 45 errorProvider.SetIconAlignment(rowsTextBox, ErrorIconAlignment.MiddleLeft); 46 errorProvider.SetIconPadding(rowsTextBox, 2); 47 errorProvider.SetIconAlignment(columnsTextBox, ErrorIconAlignment.MiddleLeft); 48 errorProvider.SetIconPadding(columnsTextBox, 2); 47 49 } 48 public StringConvertible ArrayDataView(IStringConvertibleArrayData stringConvertibleArrayData)50 public StringConvertibleMatrixDataView(IStringConvertibleMatrixData stringConvertibleArrayData) 49 51 : this() { 50 StringConvertible ArrayData = stringConvertibleArrayData;52 StringConvertibleMatrixData = stringConvertibleArrayData; 51 53 } 52 54 53 55 protected override void DeregisterObjectEvents() { 54 StringConvertible ArrayData.ItemChanged -= new EventHandler<EventArgs<int>>(StringConvertibleArrayData_ItemChanged);55 StringConvertible ArrayData.Reset -= new EventHandler(StringConvertibleArrayData_Reset);56 StringConvertibleMatrixData.ItemChanged -= new EventHandler<EventArgs<int, int>>(StringConvertibleMatrixData_ItemChanged); 57 StringConvertibleMatrixData.Reset -= new EventHandler(StringConvertibleMatrixData_Reset); 56 58 base.DeregisterObjectEvents(); 57 59 } … … 60 62 protected override void RegisterObjectEvents() { 61 63 base.RegisterObjectEvents(); 62 StringConvertible ArrayData.ItemChanged += new EventHandler<EventArgs<int>>(StringConvertibleArrayData_ItemChanged);63 StringConvertible ArrayData.Reset += new EventHandler(StringConvertibleArrayData_Reset);64 StringConvertibleMatrixData.ItemChanged += new EventHandler<EventArgs<int, int>>(StringConvertibleMatrixData_ItemChanged); 65 StringConvertibleMatrixData.Reset += new EventHandler(StringConvertibleMatrixData_Reset); 64 66 } 65 67 66 68 protected override void OnObjectChanged() { 67 69 base.OnObjectChanged(); 68 if (StringConvertibleArrayData == null) { 69 Caption = "StringConvertibleData View"; 70 sizeTextBox.Text = ""; 71 sizeTextBox.Enabled = false; 70 if (StringConvertibleMatrixData == null) { 71 Caption = "StringConvertibleMatrixData View"; 72 rowsTextBox.Text = ""; 73 rowsTextBox.Enabled = false; 74 columnsTextBox.Text = ""; 75 columnsTextBox.Enabled = false; 72 76 dataGridView.Rows.Clear(); 77 dataGridView.Columns.Clear(); 73 78 dataGridView.Enabled = false; 74 79 } else { 75 Caption = "StringConvertible ArrayData (" + StringConvertibleArrayData.GetType().Name + ")";80 Caption = "StringConvertibleMatrixData (" + StringConvertibleMatrixData.GetType().Name + ")"; 76 81 UpdateContent(); 77 82 } … … 79 84 80 85 private void UpdateContent() { 81 sizeTextBox.Text = StringConvertibleArrayData.Length.ToString(); 82 sizeTextBox.Enabled = true; 86 rowsTextBox.Text = StringConvertibleMatrixData.Rows.ToString(); 87 rowsTextBox.Enabled = (StringConvertibleMatrixData.Dimensions & StringConvertibleArrayDataDimensions.Rows) == StringConvertibleArrayDataDimensions.Rows; 88 columnsTextBox.Text = StringConvertibleMatrixData.Columns.ToString(); 89 columnsTextBox.Enabled = (StringConvertibleMatrixData.Dimensions & StringConvertibleArrayDataDimensions.Columns) == StringConvertibleArrayDataDimensions.Columns; 83 90 dataGridView.Rows.Clear(); 84 dataGridView.ColumnCount = 1; 85 dataGridView.RowCount = StringConvertibleArrayData.Length; 86 for (int i = 0; i < StringConvertibleArrayData.Length; i++) 87 dataGridView.Rows[i].Cells[0].Value = StringConvertibleArrayData.GetValue(i); 91 dataGridView.Columns.Clear(); 92 if ((StringConvertibleMatrixData.Rows > 0) && (StringConvertibleMatrixData.Columns > 0)) { 93 for (int i = 0; i < StringConvertibleMatrixData.Columns; i++) { 94 dataGridView.ColumnCount++; 95 dataGridView.Columns[dataGridView.ColumnCount - 1].FillWeight = float.Epsilon; // sum of all fill weights must not be larger than 65535 96 } 97 dataGridView.RowCount = StringConvertibleMatrixData.Rows; 98 for (int i = 0; i < StringConvertibleMatrixData.Rows; i++) { 99 for (int j = 0; j < StringConvertibleMatrixData.Columns; j++) 100 dataGridView.Rows[i].Cells[j].Value = StringConvertibleMatrixData.GetValue(i, j); 101 } 102 for (int i = 0; i < StringConvertibleMatrixData.Columns; i++) 103 dataGridView.Columns[i].Width = dataGridView.Columns[i].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); 104 } 88 105 dataGridView.Enabled = true; 89 106 } 90 107 91 private void StringConvertible ArrayData_ItemChanged(object sender, EventArgs<int> e) {108 private void StringConvertibleMatrixData_ItemChanged(object sender, EventArgs<int, int> e) { 92 109 if (InvokeRequired) 93 Invoke(new EventHandler<EventArgs<int>>(StringConvertibleArrayData_ItemChanged), sender, e); 94 else 95 dataGridView.Rows[e.Value].Cells[0].Value = StringConvertibleArrayData.GetValue(e.Value); 110 Invoke(new EventHandler<EventArgs<int, int>>(StringConvertibleMatrixData_ItemChanged), sender, e); 111 else { 112 dataGridView.Rows[e.Value].Cells[e.Value2].Value = StringConvertibleMatrixData.GetValue(e.Value, e.Value2); 113 Size size = dataGridView.Rows[e.Value].Cells[e.Value2].PreferredSize; 114 dataGridView.Columns[e.Value2].Width = Math.Max(dataGridView.Columns[e.Value2].Width, size.Width); 115 } 96 116 } 97 private void StringConvertible ArrayData_Reset(object sender, EventArgs e) {117 private void StringConvertibleMatrixData_Reset(object sender, EventArgs e) { 98 118 if (InvokeRequired) 99 Invoke(new EventHandler(StringConvertible ArrayData_Reset), sender, e);119 Invoke(new EventHandler(StringConvertibleMatrixData_Reset), sender, e); 100 120 else 101 121 UpdateContent(); 102 122 } 103 123 104 private void sizeTextBox_Validating(object sender, CancelEventArgs e) { 124 #region TextBox Events 125 private void rowsTextBox_Validating(object sender, CancelEventArgs e) { 105 126 int i = 0; 106 if (!int.TryParse( sizeTextBox.Text, out i) || (i < 0)) {127 if (!int.TryParse(rowsTextBox.Text, out i) || (i < 0)) { 107 128 e.Cancel = true; 108 errorProvider.SetError( sizeTextBox, "Invalid Array Length");109 sizeTextBox.SelectAll();129 errorProvider.SetError(rowsTextBox, "Invalid Number of Rows"); 130 rowsTextBox.SelectAll(); 110 131 } 111 132 } 112 private void sizeTextBox_Validated(object sender, EventArgs e) {113 StringConvertible ArrayData.Length = int.Parse(sizeTextBox.Text);114 errorProvider.SetError( sizeTextBox, string.Empty);133 private void rowsTextBox_Validated(object sender, EventArgs e) { 134 StringConvertibleMatrixData.Rows = int.Parse(rowsTextBox.Text); 135 errorProvider.SetError(rowsTextBox, string.Empty); 115 136 } 116 private void sizeTextBox_KeyDown(object sender, KeyEventArgs e) {137 private void rowsTextBox_KeyDown(object sender, KeyEventArgs e) { 117 138 if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) 118 sizeLabel.Focus(); // set focus on label to validate data139 rowsLabel.Focus(); // set focus on label to validate data 119 140 if (e.KeyCode == Keys.Escape) { 120 sizeTextBox.Text = StringConvertibleArrayData.Length.ToString();121 sizeLabel.Focus(); // set focus on label to validate data141 rowsTextBox.Text = StringConvertibleMatrixData.Columns.ToString(); 142 rowsLabel.Focus(); // set focus on label to validate data 122 143 } 123 144 } 145 private void columnsTextBox_Validating(object sender, CancelEventArgs e) { 146 int i = 0; 147 if (!int.TryParse(columnsTextBox.Text, out i) || (i < 0)) { 148 e.Cancel = true; 149 errorProvider.SetError(columnsTextBox, "Invalid Number of Columns"); 150 columnsTextBox.SelectAll(); 151 } 152 } 153 private void columnsTextBox_Validated(object sender, EventArgs e) { 154 StringConvertibleMatrixData.Columns = int.Parse(columnsTextBox.Text); 155 errorProvider.SetError(columnsTextBox, string.Empty); 156 } 157 private void columnsTextBox_KeyDown(object sender, KeyEventArgs e) { 158 if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) 159 columnsLabel.Focus(); // set focus on label to validate data 160 if (e.KeyCode == Keys.Escape) { 161 columnsTextBox.Text = StringConvertibleMatrixData.Columns.ToString(); 162 columnsLabel.Focus(); // set focus on label to validate data 163 } 164 } 165 #endregion 166 167 #region DataGridView Events 124 168 private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { 125 if (!StringConvertible ArrayData.Validate(e.FormattedValue.ToString())) {169 if (!StringConvertibleMatrixData.Validate(e.FormattedValue.ToString())) { 126 170 e.Cancel = true; 127 171 dataGridView.Rows[e.RowIndex].ErrorText = "Invalid Value"; … … 130 174 private void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) { 131 175 string value = e.Value.ToString(); 132 e.ParsingApplied = StringConvertible ArrayData.SetValue(value, e.RowIndex);133 if (e.ParsingApplied) e.Value = StringConvertible ArrayData.GetValue(e.RowIndex);176 e.ParsingApplied = StringConvertibleMatrixData.SetValue(value, e.RowIndex, e.ColumnIndex); 177 if (e.ParsingApplied) e.Value = StringConvertibleMatrixData.GetValue(e.RowIndex, e.ColumnIndex); 134 178 } 135 179 private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { 136 180 dataGridView.Rows[e.RowIndex].ErrorText = string.Empty; 137 181 } 182 #endregion 138 183 } 139 184 } -
trunk/sources/HeuristicLab.Data/3.3/BoolArrayData.cs
r2676 r2677 32 32 [Item("BoolArrayData", "Represents an array of boolean values.")] 33 33 [Creatable("Test")] 34 public sealed class BoolArrayData : ValueTypeArrayData<bool>, IStringConvertible ArrayData {34 public sealed class BoolArrayData : ValueTypeArrayData<bool>, IStringConvertibleMatrixData { 35 35 public BoolArrayData() : base() { } 36 36 public BoolArrayData(int length) : base(length) { } 37 37 public BoolArrayData(bool[] elements) : base(elements) { } 38 pr otectedBoolArrayData(BoolArrayData elements) : base(elements) { }38 private BoolArrayData(BoolArrayData elements) : base(elements) { } 39 39 40 40 public override IDeepCloneable Clone(Cloner cloner) { … … 44 44 } 45 45 46 #region IStringConvertibleArrayData Members 47 int IStringConvertibleArrayData.Length { 46 #region IStringConvertibleMatrixData Members 47 StringConvertibleArrayDataDimensions IStringConvertibleMatrixData.Dimensions { 48 get { return StringConvertibleArrayDataDimensions.Rows; } 49 } 50 int IStringConvertibleMatrixData.Rows { 48 51 get { return Length; } 49 52 set { Length = value; } 50 53 } 51 bool IStringConvertibleArrayData.Validate(string value){52 bool b;53 return bool.TryParse(value, out b);54 int IStringConvertibleMatrixData.Columns { 55 get { return 1; } 56 set { throw new NotSupportedException("Columns cannot be changed."); } 54 57 } 55 string IStringConvertibleArrayData.GetValue(int index) { 56 return this[index].ToString(); 58 59 bool IStringConvertibleMatrixData.Validate(string value) { 60 int i; 61 return int.TryParse(value, out i); 57 62 } 58 bool IStringConvertibleArrayData.SetValue(string value, int index) { 63 string IStringConvertibleMatrixData.GetValue(int rowIndex, int columIndex) { 64 return this[rowIndex].ToString(); 65 } 66 bool IStringConvertibleMatrixData.SetValue(string value, int rowIndex, int columnIndex) { 59 67 bool b; 60 68 if (bool.TryParse(value, out b)) { 61 this[ index] = b;69 this[rowIndex] = b; 62 70 return true; 63 71 } else { … … 65 73 } 66 74 } 67 event EventHandler<EventArgs<int >> IStringConvertibleArrayData.ItemChanged {75 event EventHandler<EventArgs<int, int>> IStringConvertibleMatrixData.ItemChanged { 68 76 add { base.ItemChanged += value; } 69 77 remove { base.ItemChanged -= value; } 70 78 } 71 event EventHandler IStringConvertible ArrayData.Reset {79 event EventHandler IStringConvertibleMatrixData.Reset { 72 80 add { base.Reset += value; } 73 81 remove { base.Reset -= value; } -
trunk/sources/HeuristicLab.Data/3.3/HeuristicLab.Data-3.3.csproj
r2676 r2677 104 104 </Compile> 105 105 <Compile Include="BoolArrayData.cs" /> 106 <Compile Include="IStringConvertibleArrayData.cs" /> 106 <Compile Include="IntMatrixData.cs" /> 107 <Compile Include="ValueTypeMatrixData.cs" /> 108 <Compile Include="StringConvertibleMatrixDataDimensions.cs" /> 109 <Compile Include="IStringConvertibleMatrixData.cs" /> 107 110 <Compile Include="ValueTypeArrayData.cs" /> 108 111 <Compile Include="IntArrayData.cs" /> -
trunk/sources/HeuristicLab.Data/3.3/IStringConvertibleMatrixData.cs
r2676 r2677 28 28 29 29 namespace HeuristicLab.Data { 30 public interface IStringConvertibleArrayData { 31 int Length { get; set; } 30 public interface IStringConvertibleMatrixData { 31 StringConvertibleArrayDataDimensions Dimensions { get; } 32 int Rows { get; set; } 33 int Columns { get; set; } 32 34 33 35 bool Validate(string value); 34 string GetValue(int index);35 bool SetValue(string value, int index);36 string GetValue(int rowIndex, int columnIndex); 37 bool SetValue(string value, int rowIndex, int columnIndex); 36 38 37 event EventHandler<EventArgs<int >> ItemChanged;39 event EventHandler<EventArgs<int, int>> ItemChanged; 38 40 event EventHandler Reset; 39 41 } -
trunk/sources/HeuristicLab.Data/3.3/IntArrayData.cs
r2676 r2677 32 32 [Item("IntArrayData", "Represents an array of integer values.")] 33 33 [Creatable("Test")] 34 public sealed class IntArrayData : ValueTypeArrayData<int>, IStringConvertible ArrayData {34 public sealed class IntArrayData : ValueTypeArrayData<int>, IStringConvertibleMatrixData { 35 35 public IntArrayData() : base() { } 36 36 public IntArrayData(int length) : base(length) { } 37 37 public IntArrayData(int[] elements) : base(elements) { } 38 pr otectedIntArrayData(IntArrayData elements) : base(elements) { }38 private IntArrayData(IntArrayData elements) : base(elements) { } 39 39 40 40 public override IDeepCloneable Clone(Cloner cloner) { … … 44 44 } 45 45 46 #region IStringConvertibleArrayData Members 47 int IStringConvertibleArrayData.Length { 46 #region IStringConvertibleMatrixData Members 47 StringConvertibleArrayDataDimensions IStringConvertibleMatrixData.Dimensions { 48 get { return StringConvertibleArrayDataDimensions.Rows; } 49 } 50 int IStringConvertibleMatrixData.Rows { 48 51 get { return Length; } 49 52 set { Length = value; } 50 53 } 51 bool IStringConvertibleArrayData.Validate(string value) { 54 int IStringConvertibleMatrixData.Columns { 55 get { return 1; } 56 set { throw new NotSupportedException("Columns cannot be changed."); } 57 } 58 59 bool IStringConvertibleMatrixData.Validate(string value) { 52 60 int i; 53 61 return int.TryParse(value, out i); 54 62 } 55 string IStringConvertible ArrayData.GetValue(int index) {56 return this[ index].ToString();63 string IStringConvertibleMatrixData.GetValue(int rowIndex, int columIndex) { 64 return this[rowIndex].ToString(); 57 65 } 58 bool IStringConvertible ArrayData.SetValue(string value, int index) {66 bool IStringConvertibleMatrixData.SetValue(string value, int rowIndex, int columnIndex) { 59 67 int i; 60 68 if (int.TryParse(value, out i)) { 61 this[ index] = i;69 this[rowIndex] = i; 62 70 return true; 63 71 } else { … … 65 73 } 66 74 } 67 event EventHandler<EventArgs<int >> IStringConvertibleArrayData.ItemChanged {75 event EventHandler<EventArgs<int, int>> IStringConvertibleMatrixData.ItemChanged { 68 76 add { base.ItemChanged += value; } 69 77 remove { base.ItemChanged -= value; } 70 78 } 71 event EventHandler IStringConvertible ArrayData.Reset {79 event EventHandler IStringConvertibleMatrixData.Reset { 72 80 add { base.Reset += value; } 73 81 remove { base.Reset -= value; } -
trunk/sources/HeuristicLab.Data/3.3/IntMatrixData.cs
r2520 r2677 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 using System.Globalization;28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 29 30 30 namespace HeuristicLab.Data { 31 /// <summary>32 /// A two-dimensional matrix of integer values.33 /// </summary>34 31 [EmptyStorableClass] 35 public class IntMatrixData : ArrayDataBase { 36 /// <summary> 37 /// Gets or sets the int values of the matrix. 38 /// </summary> 39 /// <remarks>Uses property <see cref="ArrayDataBase.Data"/> of base class <see cref="ArrayDataBase"/>. 40 /// No own data storage present.</remarks> 41 public new int[,] Data { 42 get { return (int[,])base.Data; } 43 set { base.Data = value; } 32 [Item("IntMatrixData", "Represents a matrix of integer values.")] 33 [Creatable("Test")] 34 public sealed class IntMatrixData : ValueTypeMatrixData<int>, IStringConvertibleMatrixData { 35 public IntMatrixData() : base() { } 36 public IntMatrixData(int rows, int columns) : base(rows, columns) { } 37 public IntMatrixData(int[,] elements) : base(elements) { } 38 private IntMatrixData(IntMatrixData elements) : base(elements) { } 39 40 public override IDeepCloneable Clone(Cloner cloner) { 41 IntMatrixData clone = new IntMatrixData(this); 42 cloner.RegisterClonedObject(this, clone); 43 return clone; 44 44 } 45 45 46 /// <summary> 47 /// Initializes a new instance of <see cref="IntMatrixData"/>. 48 /// </summary> 49 public IntMatrixData() { 50 Data = new int[1, 1]; 46 #region IStringConvertibleMatrixData Members 47 StringConvertibleArrayDataDimensions IStringConvertibleMatrixData.Dimensions { 48 get { return StringConvertibleArrayDataDimensions.Both; } 51 49 } 52 /// <summary>53 /// Initializes a new instance of <see cref="IntMatrixData"/>.54 /// <note type="caution"> No CopyConstructor! <paramref name="data"/> is not copied!</note>55 /// </summary>56 /// <param name="data">The two-dimensional int matrix the instance should represent.</param>57 public IntMatrixData(int[,] data) {58 Data = data;50 int IStringConvertibleMatrixData.Rows { 51 get { return Rows; } 52 set { Rows = value; } 53 } 54 int IStringConvertibleMatrixData.Columns { 55 get { return Columns; } 56 set { Columns = value; } 59 57 } 60 58 61 /// <summary> 62 /// The string representation of the matrix. 63 /// </summary> 64 /// <returns>The elements of the matrix as a string, line by line, each element separated by a 65 /// semicolon and formatted according to the local number format.</returns> 66 public override string ToString() { 67 return ToString(CultureInfo.CurrentCulture.NumberFormat); 59 bool IStringConvertibleMatrixData.Validate(string value) { 60 int i; 61 return int.TryParse(value, out i); 68 62 } 69 70 /// <summary> 71 /// The string representation of the matrix, considering a specified <paramref name="format"/>. 72 /// </summary> 73 /// <param name="format">The <see cref="NumberFormatInfo"/> the int values are formatted accordingly.</param> 74 /// <returns>The elements of the matrix as a string, line by line, each element separated by a 75 /// semicolon and formatted according to the specified <paramref name="format"/>.</returns> 76 private string ToString(NumberFormatInfo format) { 77 StringBuilder builder = new StringBuilder(); 78 for (int i = 0; i < Data.GetLength(0); i++) { 79 for (int j = 0; j < Data.GetLength(1); j++) { 80 builder.Append(";"); 81 builder.Append(Data[i, j].ToString(format)); 82 } 63 string IStringConvertibleMatrixData.GetValue(int rowIndex, int columIndex) { 64 return this[rowIndex, columIndex].ToString(); 65 } 66 bool IStringConvertibleMatrixData.SetValue(string value, int rowIndex, int columnIndex) { 67 int i; 68 if (int.TryParse(value, out i)) { 69 this[rowIndex, columnIndex] = i; 70 return true; 71 } else { 72 return false; 83 73 } 84 if (builder.Length > 0) builder.Remove(0, 1);85 return builder.ToString();86 74 } 75 event EventHandler<EventArgs<int, int>> IStringConvertibleMatrixData.ItemChanged { 76 add { base.ItemChanged += value; } 77 remove { base.ItemChanged -= value; } 78 } 79 event EventHandler IStringConvertibleMatrixData.Reset { 80 add { base.Reset += value; } 81 remove { base.Reset -= value; } 82 } 83 #endregion 87 84 } 88 85 } -
trunk/sources/HeuristicLab.Data/3.3/ValueTypeArrayData.cs
r2676 r2677 37 37 get { return array.Length; } 38 38 protected set { 39 if (value < 0) throw new ArgumentException("Array length cannot be smaller than 0."); 40 T[] newArray = new T[value]; 41 Array.Copy(array, newArray, Math.Min(value, array.Length)); 42 array = newArray; 43 OnReset(); 39 if (value != Length) { 40 Array.Resize<T>(ref array, value); 41 OnReset(); 42 } 44 43 } 45 44 } … … 91 90 } 92 91 93 protected event EventHandler<EventArgs<int >> ItemChanged;92 protected event EventHandler<EventArgs<int, int>> ItemChanged; 94 93 private void OnItemChanged(int index) { 95 94 if (ItemChanged != null) 96 ItemChanged(this, new EventArgs<int >(index));95 ItemChanged(this, new EventArgs<int, int>(index, 0)); 97 96 OnChanged(); 98 97 }
Note: See TracChangeset
for help on using the changeset viewer.