Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/DataBarSet.cs @ 16123

Last change on this file since 16123 was 14588, checked in by jzenisek, 8 years ago

#2719 updated databar set and view

File size: 5.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8using HeuristicLab.Analysis;
9using HeuristicLab.Collections;
10using HeuristicLab.Common;
11using HeuristicLab.Core;
12using HeuristicLab.Data;
13using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
14
15namespace HeuristicLab.DatastreamAnalysis {
16  /// <summary>
17  /// A set of bars, each having name and value.
18  /// </summary>
19  [Item("DataBarSet", "A set of bars, each having name and value.")]
20  [StorableClass]
21  public class DataBarSet : NamedItem {
22    public static new Image StaticItemImage {
23      get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
24    }
25
26    #region properties
27
28    [Storable]
29    private NamedItemCollection<DataBar> bars;
30
31    public NamedItemCollection<DataBar> Bars {
32      get { return bars; }
33      set {
34        if (bars != value) {
35          if(value == null) throw new ArgumentNullException("Value for Bars must not be null.");
36          if(bars != null) DeregisterBarsEvents();
37          bars = value;
38          RegisterBarsEvents();
39        }
40      }
41    }
42
43    #endregion
44
45    #region constructors, cloner,...
46    [StorableConstructor]
47    protected DataBarSet(bool deserializing) : base(deserializing) { }
48
49    public DataBarSet() : base() {
50      Name = "DataBarSet";
51      Bars = new NamedItemCollection<DataBar>();
52    }
53
54    public DataBarSet(string name) : base(name) {
55      Bars = new NamedItemCollection<DataBar>();
56    }
57
58    public DataBarSet(string name, string description) : base(name, description) {
59      Bars = new NamedItemCollection<DataBar>();
60    }
61
62    public DataBarSet(DataBarSet original, Cloner cloner) : base(original, cloner) {
63      Bars = cloner.Clone(original.bars);
64    }
65
66    public override IDeepCloneable Clone(Cloner cloner) {
67      return new DataBarSet(this, cloner);
68    }
69    #endregion
70
71    #region events
72
73    //public event EventHandler BarsPropertyChanged;
74
75
76    //protected virtual void OnBarsPropertyChanged() {
77    //  EventHandler handler = BarsPropertyChanged;
78    //  if (handler != null) handler(this, EventArgs.Empty);
79    //}
80
81    //private void Bars_PropertyChanged(object sender, PropertyChangedEventArgs e) {
82    //  OnBarsPropertyChanged();
83    //}
84
85    public event EventHandler ThresholdsPropertyChanged;
86
87    protected virtual void OnThresholdsPropertyChanged() {
88      EventHandler handler = ThresholdsPropertyChanged;
89      if (handler != null) handler(this, EventArgs.Empty);
90    }
91
92    private void Thresholds_PropertyChanged(object sender, PropertyChangedEventArgs e) {
93      OnThresholdsPropertyChanged();
94    }
95
96
97
98    public event EventHandler BarsPropertyChanged;
99    public event EventHandler BarValueChanged;
100    protected virtual void OnBarsPropertyChanged() {
101      EventHandler handler = BarsPropertyChanged;
102      if (handler != null) handler(this, EventArgs.Empty);
103    }
104
105    protected virtual void OnBarValueChanged(PropertyChangedEventArgs e) {
106      EventHandler handler = BarValueChanged;
107      if(handler != null) handler(this, e);
108    }
109
110    protected virtual void RegisterBarsEvents() {
111      bars.ItemsAdded += new CollectionItemsChangedEventHandler<DataBar>(Bars_ItemsAdded);
112      bars.ItemsRemoved += new CollectionItemsChangedEventHandler<DataBar>(Bars_ItemsChanged);
113      bars.ItemsReplaced += new CollectionItemsChangedEventHandler<DataBar>(Bars_ItemsChanged);
114      bars.CollectionReset += new CollectionItemsChangedEventHandler<DataBar>(Bars_ItemsChanged);
115    }
116
117    protected virtual void DeregisterBarsEvents() {
118      bars.ItemsAdded -= new CollectionItemsChangedEventHandler<DataBar>(Bars_ItemsAdded);
119      bars.ItemsRemoved -= new CollectionItemsChangedEventHandler<DataBar>(Bars_ItemsChanged);
120      bars.ItemsReplaced -= new CollectionItemsChangedEventHandler<DataBar>(Bars_ItemsChanged);
121      bars.CollectionReset -= new CollectionItemsChangedEventHandler<DataBar>(Bars_ItemsChanged);
122    }
123
124    private void Bars_ItemsAdded(object sender, CollectionItemsChangedEventArgs<DataBar> e) {
125      foreach (var bar in e.Items) {
126        bar.ValuePropertyChanged += new PropertyChangedEventHandler(Bars_ValueChanged);
127        //bar.ThresholdPropertyChanged += new PropertyChangedEventHandler();
128      }
129      OnBarsPropertyChanged();
130    }
131
132    private void Bars_ItemsChanged(object sender, CollectionItemsChangedEventArgs<DataBar> e) {
133      OnBarsPropertyChanged();
134    }
135
136    private void Bars_ValueChanged(object sender, PropertyChangedEventArgs e) {
137      OnBarValueChanged(e);
138    }
139
140    #endregion
141
142    #region helpers
143    public static Dictionary<TKey, TValue> CloneDictionary<TKey, TValue>(Dictionary<TKey, TValue> original) where TValue : ICloneable {
144      Dictionary<TKey, TValue> ret = new Dictionary<TKey, TValue>(original.Count, original.Comparer);
145
146      foreach (KeyValuePair<TKey, TValue> entry in original) {
147        ret.Add(entry.Key, (TValue)entry.Value.Clone());
148      }
149      return ret;
150    }
151    #endregion
152  }
153}
Note: See TracBrowser for help on using the repository browser.