Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Analysis/3.3/DataVisualization/DataRow.cs @ 17603

Last change on this file since 17603 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 4.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 HEAL.Attic;
29
30namespace HeuristicLab.Analysis {
31  /// <summary>
32  /// A row of data values.
33  /// </summary>
34  [Item("DataRow", "A row of data values.")]
35  [StorableType("34A66F23-0FBB-414C-81C8-D3AA1C470446")]
36  public class DataRow : NamedItem , IDataRow {
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 {
60        visualProperties = value;
61        visualProperties.PropertyChanged += new PropertyChangedEventHandler(VisualProperties_PropertyChanged);
62      }
63    }
64    [Storable(Name = "values")]
65    private IEnumerable<double> StorableValues {
66      get { return values; }
67      set { values = new ObservableList<double>(value); }
68    }
69    #endregion
70
71    [StorableConstructor]
72    protected DataRow(StorableConstructorFlag _) : base(_) { }
73    protected DataRow(DataRow original, Cloner cloner)
74      : base(original, cloner) {
75      this.VisualProperties = (DataRowVisualProperties)cloner.Clone(original.visualProperties);
76      this.values = new ObservableList<double>(original.values);
77    }
78    public DataRow() : this("DataRow") { }
79    public DataRow(string name)
80      : base(name) {
81      if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataRow cannot be empty", name);
82      VisualProperties = new DataRowVisualProperties(name);
83      values = new ObservableList<double>();
84    }
85    public DataRow(string name, string description)
86      : base(name, description) {
87      if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataRow cannot be empty", name);
88      VisualProperties = new DataRowVisualProperties(name);
89      values = new ObservableList<double>();
90    }
91    public DataRow(string name, string description, IEnumerable<double> values)
92      : base(name, description) {
93      if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataRow cannot be empty", name);
94      VisualProperties = new DataRowVisualProperties(name);
95      this.values = new ObservableList<double>(values);
96    }
97
98    // BackwardsCompatibility3.3
99    #region Backwards compatible code, remove with 3.4
100    [StorableHook(HookType.AfterDeserialization)]
101    private void AfterDeserialization() {
102      if (VisualProperties == null) VisualProperties = new DataRowVisualProperties();
103    }
104    #endregion
105
106    public override IDeepCloneable Clone(Cloner cloner) {
107      return new DataRow(this, cloner);
108    }
109
110    public event EventHandler VisualPropertiesChanged;
111    protected virtual void OnVisualPropertiesChanged() {
112      EventHandler handler = VisualPropertiesChanged;
113      if (handler != null) handler(this, EventArgs.Empty);
114    }
115
116    private void VisualProperties_PropertyChanged(object sender, PropertyChangedEventArgs e) {
117      OnVisualPropertiesChanged();
118    }
119    protected override void OnNameChanged() {
120      base.OnNameChanged();
121      VisualProperties.DisplayName = Name;
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.