aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/NumericControl.cs
blob: c6d76bcd47795ea3dd53d85742bc12b8ba054e18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Xml.Serialization;
using System.ComponentModel;

namespace go
{
	public abstract class NumericControl : TemplatedControl
	{
		#region CTOR
		public NumericControl () : base()
		{
		}
		public NumericControl(double minimum, double maximum, double step)
			: base()
		{
			minValue = minimum;
			maxValue = maximum;
			smallStep = step;
			bigStep = step * 5;
		}
		#endregion

		#region event handlers
		public EventHandler<ValueChangeEventArgs> ValueChanged;

		public virtual void onValueChanged(object sender, ValueChangeEventArgs e)
		{			
			ValueChanged.Raise (sender, e);
		}
		#endregion

		#region private fields
		double _actualValue, minValue, maxValue, smallStep, bigStep;
		#endregion

		#region public properties
		[XmlAttributeAttribute()][DefaultValue(0.0)]
		public virtual double Minimum {
			get { return minValue; }
			set {
				if (minValue == value)
					return;

				minValue = value;

			}
		}
		[XmlAttributeAttribute()][DefaultValue(10.0)]
		public virtual double Maximum
		{
			get { return maxValue; }
			set {
				if (maxValue == value)
					return;

				maxValue = value;

			}
		}
		[XmlAttributeAttribute()][DefaultValue(0.5)]
		public virtual double SmallIncrement
		{
			get { return smallStep; }
			set {
				if (smallStep == value)
					return;

				smallStep = value;

			}
		}
		[XmlAttributeAttribute()][DefaultValue(2.0)]
		public virtual double LargeIncrement
		{
			get { return bigStep; }
			set {
				if (bigStep == value)
					return;

				bigStep = value;

			}
		}
		[XmlAttributeAttribute()][DefaultValue(0)]
		public double Value
		{
			get { return _actualValue; }
			set
			{
				if (value == _actualValue)
					return;

				if (value < minValue)
					_actualValue = minValue;
				else if (value > maxValue)
					_actualValue = maxValue;
				else                    
					_actualValue = value;

				onValueChanged(this,new ValueChangeEventArgs("Value", Convert.ToInt32( _actualValue)));
				registerForGraphicUpdate();
			}
		}
		#endregion

	}
}