Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis/3.3/DataRow.cs @ 4703

Last change on this file since 4703 was 4703, checked in by swagner, 14 years ago

Reviewed diversity analysis branch and merged it into the trunk (#1188)

File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using HeuristicLab.Collections;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Analysis {
31  /// <summary>
32  /// A row of data values.
33  /// </summary>
34  [Item("DataRow", "A row of data values.")]
35  [StorableClass]
36  public sealed class DataRow : NamedItem {
37    private DataRowVisualProperties visualProperties;
38    public DataRowVisualProperties VisualProperties {
39      get { return visualProperties; }
40      set {
41        if (visualProperties != value) {
42          if (value == null) throw new ArgumentNullException("VisualProperties");
43          if (visualProperties != null) visualProperties.PropertyChanged -= new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
44          visualProperties = value;
45          visualProperties.PropertyChanged += new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
46          OnVisualPropertiesChanged();
47        }
48      }
49    }
50    private ObservableList<double> values;
51    public ObservableList<double> Values {
52      get { return values; }
53    }
54
55    #region Persistence Properties
56    [Storable(Name = "VisualProperties")]
57    private DataRowVisualProperties StorableVisualProperties {
58      get { return VisualProperties; }
59      set { VisualProperties = value; }
60    }
61    [Storable(Name = "values")]
62    private IEnumerable<double> StorableValues {
63      get { return values; }
64      set { values = new ObservableList<double>(value); }
65    }
66    #endregion
67
68    public DataRow()
69      : base() {
70      VisualProperties = new DataRowVisualProperties();
71      values = new ObservableList<double>();
72    }
73    public DataRow(string name)
74      : base(name) {
75      VisualProperties = new DataRowVisualProperties();
76      values = new ObservableList<double>();
77    }
78    public DataRow(string name, string description)
79      : base(name, description) {
80      VisualProperties = new DataRowVisualProperties();
81      values = new ObservableList<double>();
82    }
83    public DataRow(string name, string description, DataRowVisualProperties visualProperties)
84      : base(name, description) {
85      VisualProperties = visualProperties;
86      values = new ObservableList<double>();
87    }
88    [StorableConstructor]
89    private DataRow(bool deserializing) { }
90
91    // BackwardsCompatibility3.3
92    #region Backwards compatible code, remove with 3.4
93    [StorableHook(HookType.AfterDeserialization)]
94    private void AfterDeserialization() {
95      if (VisualProperties == null) VisualProperties = new DataRowVisualProperties();
96    }
97    #endregion
98
99    public override IDeepCloneable Clone(Cloner cloner) {
100      DataRow clone = new DataRow(Name, Description);
101      cloner.RegisterClonedObject(this, clone);
102      clone.VisualProperties = (DataRowVisualProperties)cloner.Clone(visualProperties);
103      clone.values.AddRange(values);
104      return clone;
105    }
106
107    public event EventHandler VisualPropertiesChanged;
108    private void OnVisualPropertiesChanged() {
109      EventHandler handler = VisualPropertiesChanged;
110      if (handler != null) handler(this, EventArgs.Empty);
111    }
112
113    private void VisualProperties_PropertyChanged(object sender, PropertyChangedEventArgs e) {
114      OnVisualPropertiesChanged();
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.