Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2719_HeuristicLab.DatastreamAnalysis/HeuristicLab.DatastreamAnalysis/3.4/DataBar.cs @ 18242

Last change on this file since 18242 was 17980, checked in by jzenisek, 3 years ago

#2719 merged head of HeuristicLab.Problems.DataAnalysis into branch; added several minor items

File size: 6.0 KB
Line 
1#region License Information
2
3/* HeuristicLab
4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#endregion
23
24using System;
25using System.ComponentModel;
26using System.Drawing;
27using System.Runtime.CompilerServices;
28using HeuristicLab.Common;
29using HeuristicLab.Core;
30using HEAL.Attic;
31
32namespace HeuristicLab.DatastreamAnalysis {
33  /// <summary>
34  /// Bar representation for a single value.
35  /// </summary>
36  [Item("DataBar", "Bar representation for a single value")]
37  [StorableType("57864A6E-CCC6-4D36-8504-729E149DBB60")]
38  public class DataBar : NamedItem, INotifyPropertyChanged {
39    private double value;
40    public static Color DefaultBarColor = Color.FromArgb(65, 140, 240);
41
42    public double Value {
43      get { return value; }
44      set {
45
46        if (this.value != value) {
47          this.value = value;
48          OnValuePropertyChanged("Value");
49        }
50      }
51    }
52
53    private double thresholdLowerBound;
54
55    public double ThresholdLowerBound {
56      get { return thresholdLowerBound; }
57      set {
58        if (this.value != value) {
59          this.value = value;
60          OnThresholdPropertyChanged("Threshold");
61        }
62      }
63    }
64
65    private double thresholdUpperBound;
66
67    public double ThresholdUpperBound
68    {
69      get { return thresholdUpperBound; }
70      set
71      {
72        if (this.value != value) {
73          this.value = value;
74          OnThresholdPropertyChanged("Threshold");
75        }
76      }
77    }
78
79    #region Persistence Properties
80    [Storable(Name = "Value")]
81    private double StorableValue {
82      get { return value; }
83      set { this.value = value; }
84    }
85    [Storable(Name = "ThresholdLowerBound")]
86    private double StorableThresholdLowerBound {
87      get { return thresholdLowerBound; }
88      set { this.thresholdLowerBound = value; }
89    }
90    [Storable(Name = "ThresholdUpperBound")]
91    private double StorableThresholdUpperBound
92    {
93      get { return thresholdUpperBound; }
94      set { this.thresholdUpperBound = value; }
95    }
96    #endregion
97
98    #region Visual Properties
99    private Color barColor;
100    public Color BarColor
101    {
102      get { return barColor; }
103      set
104      {
105        if (barColor != value) {
106          barColor = value;
107          OnValuePropertyChanged("BarColor");
108        }
109      }
110    }
111
112    private Color thresholdColor;
113    public Color ThresholdColor
114    {
115      get { return thresholdColor; }
116      set
117      {
118        if (thresholdColor != value) {
119          thresholdColor = value;
120          OnThresholdPropertyChanged("ThresholdColor");
121        }
122      }
123    }
124    #endregion
125
126    #region constructors, cloner ...
127    [StorableConstructor]
128    protected DataBar(StorableConstructorFlag _) : base(_) { }
129
130    protected DataBar(DataBar original, Cloner cloner) : base(original, cloner) {
131      this.value = original.value;
132      this.thresholdLowerBound = original.thresholdLowerBound;
133      this.barColor = original.barColor;
134      this.thresholdColor = original.thresholdColor;
135    }
136
137    public DataBar() : this("DataBar") {
138      barColor = DefaultBarColor;
139      thresholdColor = Color.Black;
140    }
141
142    public DataBar(string name) : base(name) {
143      if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataBar cannot be empty", name);
144      barColor = DefaultBarColor;
145      thresholdColor = Color.Black;
146    }
147
148    public DataBar(string name, double thresholdLowerBound, double thresholdUpperBound) : base(name) {
149      if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataBar cannot be empty", name);
150      this.thresholdLowerBound = thresholdLowerBound;
151      this.thresholdUpperBound = thresholdUpperBound;
152      barColor = DefaultBarColor;
153      thresholdColor = Color.Black;
154    }
155
156    public DataBar(string name, string description) : base(name, description) {
157      if (string.IsNullOrEmpty(name)) throw new ArgumentException("Name of a DataBar cannot be empty", name);
158      barColor = DefaultBarColor;
159      thresholdColor = Color.Black;
160    }
161
162    public override IDeepCloneable Clone(Cloner cloner) {
163      return new DataBar(this, cloner);
164    }
165    #endregion
166
167    protected override void OnNameChanged() {
168      base.OnNameChanged();
169    }
170
171    public event PropertyChangedEventHandler PropertyChanged;
172    public event PropertyChangedEventHandler ValuePropertyChanged;
173    public event PropertyChangedEventHandler ThresholdPropertyChanged;
174
175    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) {
176      PropertyChangedEventHandler handler = PropertyChanged;
177      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
178    }
179
180    protected virtual void OnValuePropertyChanged([CallerMemberName] string propertyName = null) {
181      PropertyChangedEventHandler handler = ValuePropertyChanged;
182      if(handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
183    }
184
185    protected virtual void OnThresholdPropertyChanged([CallerMemberName] string propertyName = null) {
186      PropertyChangedEventHandler handler = ThresholdPropertyChanged;
187      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
188    }
189  }
190}
Note: See TracBrowser for help on using the repository browser.