summaryrefslogtreecommitdiff
path: root/grapher/Models/Options/Cap/CapTypeOptions.cs
blob: 6447feb32b9c616da5efde3d6b98407964305121 (plain) (blame)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace grapher.Models.Options.Cap
{
    public class CapTypeOptions : ComboBoxOptionsBase
    {
        #region Enum

        public enum CapType
        {
            Input,
            Output,
            Both,
        }

        #endregion Enum

        #region Classes

        public class CapTypeOption
        {
            public CapType Type { get; set; }

            public string Name => Type.ToString();

            public override string ToString() => Name;
        }

        #endregion Classes

        #region Static

        public static readonly CapTypeOption InCap = new CapTypeOption
        {
            Type = CapType.Input,
        };

        public static readonly CapTypeOption OutCap = new CapTypeOption
        {
            Type = CapType.Output,
        };

        public static readonly CapTypeOption BothCap = new CapTypeOption
        {
            Type = CapType.Both,
        };

        public static readonly CapTypeOption[] AllCapTypeOptions = new CapTypeOption[]
        {
            InCap,
            OutCap,
            BothCap
        };

        #endregion Static

        #region Constructors

        public CapTypeOptions(
            Label label,
            ComboBox dropdown,
            ActiveValueLabel activeValueLabel,
            int left)
            : base(
                  label,
                  dropdown,
                  activeValueLabel)
        {
            OptionsDropdown.Items.AddRange(
                new CapTypeOption[]
                {
                    InCap,
                    OutCap,
                    BothCap
                });

            Default = OutCap;

            label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            label.Left = left;
            label.Width = OptionsDropdown.Left - left - Constants.OptionLabelBoxSeperation;
            label.Height = OptionsDropdown.Height;
        }

        #endregion Constructors

        #region Properties

        public CapType SelectedCapType => SelectedCapOption.Type;

        public CapTypeOption SelectedCapOption
        {
            get
            {
                return OptionsDropdown.SelectedItem as CapTypeOption;
            }
            set
            {
                OptionsDropdown.SelectedItem = value;
            }
        }

        private CapTypeOption Default { get; set; }

        public CapMode GetSelectedCapMode()
        {
            switch(SelectedCapType)
            {
                case CapType.Output: return CapMode.output;
                case CapType.Both: return CapMode.in_out;
                case CapType.Input:
                default: return CapMode.input;
            }
        }

        #endregion Properties

        #region Methods

        public static CapTypeOption CapTypeOptionFromSettings(CapMode capMode)
        {
            switch (capMode)
            {
                case CapMode.output:
                    return OutCap;
                case CapMode.in_out:
                    return BothCap;
                case CapMode.input:
                default:
                    return InCap;
            }
        }

        public void SetActiveValue(CapMode capMode)
        {
            Default = CapTypeOptionFromSettings(capMode);
            SelectedCapOption = Default;
            ActiveValueLabel.SetValue(SelectedCapOption.Name);
        }

        public void CheckIfDefault()
        {
            if (SelectedCapOption.Equals(Default))
            {
                OptionsDropdown.ForeColor = System.Drawing.Color.Gray;
            }
            else
            {
                OptionsDropdown.ForeColor = System.Drawing.Color.Black;
            }
        }

        #endregion Methods
    }
}