1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.JsonInterface.OptimizerIntegration {
|
---|
9 |
|
---|
10 | public class IntRangeVM : RangeVM<int> {
|
---|
11 | public override Type JsonItemType => typeof(IntArrayJsonItem);
|
---|
12 | }
|
---|
13 |
|
---|
14 | public class DoubleRangeVM : RangeVM<double> {
|
---|
15 | public override Type JsonItemType => typeof(DoubleArrayJsonItem);
|
---|
16 | public override JsonItemBaseControl GetControl() =>
|
---|
17 | new JsonItemRangeControl(this);
|
---|
18 | }
|
---|
19 |
|
---|
20 | public abstract class RangeVM<T> : JsonItemVMBase {
|
---|
21 |
|
---|
22 | public T MinValue {
|
---|
23 | get => Cast(((Array)Item.Value).GetValue(0));
|
---|
24 | set {
|
---|
25 | SetValue(value, ((Array)Item.Value).GetValue(1));
|
---|
26 | OnPropertyChange(this, nameof(MinValue));
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | public T MaxValue {
|
---|
31 | get => Cast(((Array)Item.Value).GetValue(1));
|
---|
32 | set {
|
---|
33 | SetValue(((Array)Item.Value).GetValue(0), value);
|
---|
34 | OnPropertyChange(this, nameof(MaxValue));
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public T MinRange {
|
---|
39 | get => Cast(Item.Range.First());
|
---|
40 | set {
|
---|
41 | SetRange(value, Item.Range.Last());
|
---|
42 | OnPropertyChange(this, nameof(MinRange));
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public T MaxRange {
|
---|
47 | get => Cast(Item.Range.Last());
|
---|
48 | set {
|
---|
49 | SetRange(Item.Range.First(), value);
|
---|
50 | OnPropertyChange(this, nameof(MaxRange));
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | private T Cast(object obj) => (T)Convert.ChangeType(obj, typeof(T));
|
---|
55 |
|
---|
56 | private void SetValue(object min, object max) =>
|
---|
57 | Item.Value = new object[] { min, max };
|
---|
58 |
|
---|
59 | private void SetRange(object min, object max) =>
|
---|
60 | Item.Range = new object[] { min, max };
|
---|
61 | }
|
---|
62 | }
|
---|