Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/RangeVM.cs @ 17471

Last change on this file since 17471 was 17471, checked in by dpiringe, 4 years ago

#3026:

  • deleted INamedMatrixJsonItem and all corresponding classes/views, because of bad design
  • added ILookupJsonItem and IValueLookupJsonItem (incl. all corresponding implementations, VMs, Views)
  • added IResultJsonItem
  • changed type of property Control from JsonItemBaseControl to UserControl in IJsonItemVM (because the details control now builds up with linked user controls -> allows better construction of dynamic controls)
  • added all properties of INamedMatrixJsonItem in IMatrixJsonItem
  • refactored a lot of views for better usage (TableLayoutPanel is used a lot now -> for better item positioning)
  • property ActualName is now located in ILookupJsonItem instead of IJsonItem
File size: 1.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using System.Windows.Forms;
8
9namespace HeuristicLab.JsonInterface.OptimizerIntegration {
10
11  public class IntRangeVM : RangeVM<int> {
12    public override Type JsonItemType => typeof(IntRangeJsonItem);
13
14    protected override int MinTypeValue => int.MinValue;
15
16    protected override int MaxTypeValue => int.MaxValue;
17
18    public override UserControl Control =>
19      new JsonItemRangeControl(this);
20  }
21
22  public class DoubleRangeVM : RangeVM<double> {
23    public override Type JsonItemType => typeof(DoubleRangeJsonItem);
24
25    protected override double MinTypeValue => double.MinValue;
26
27    protected override double MaxTypeValue => double.MaxValue;
28
29    public override UserControl Control =>
30      new JsonItemRangeControl(this);
31  }
32
33  public abstract class RangeVM<T> : RangedValueBaseVM<T> {
34
35    public T MinValue {
36      get => Cast(((Array)Item.Value).GetValue(0));
37      set {
38        SetValue(value, (T)((Array)Item.Value).GetValue(1));
39        OnPropertyChange(this, nameof(MinValue));
40      }
41    }
42
43    public T MaxValue {
44      get => Cast(((Array)Item.Value).GetValue(1));
45      set {
46        SetValue((T)((Array)Item.Value).GetValue(0), value);
47        OnPropertyChange(this, nameof(MaxValue));
48      }
49    }
50
51    private void SetValue(T min, T max) =>
52      Item.Value = new T[] { min, max };
53  }
54}
Note: See TracBrowser for help on using the repository browser.