- Timestamp:
- 06/04/20 18:16:58 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Parameters/3.3/ParameterChangeHandler.cs
r17546 r17587 39 39 } 40 40 41 public class ParameterChangeHandler<TItem, TValue> : ParameterChangeHandler<TItem>41 public class ValueTypeValueParameterChangeHandler<TItem, TValue> : ParameterChangeHandler<TItem> 42 42 where TValue : struct 43 43 where TItem : ValueTypeValue<TValue> { 44 44 private ValueTypeValue<TValue> last; 45 45 46 protected ParameterChangeHandler(IValueParameter<TItem> parameter, Action handler)46 protected ValueTypeValueParameterChangeHandler(IValueParameter<TItem> parameter, Action handler) 47 47 : base(parameter, handler) { 48 48 last = parameter.Value; … … 63 63 } 64 64 65 public static ParameterChangeHandler<TItem, TValue> Create(IValueParameter<TItem> parameter, Action handler) 66 => new ParameterChangeHandler<TItem, TValue>(parameter, handler); 67 } 68 69 public class BoolValueParameterChangeHandler : ParameterChangeHandler<BoolValue, bool> { 65 public static ValueTypeValueParameterChangeHandler<TItem, TValue> Create(IValueParameter<TItem> parameter, Action handler) 66 => new ValueTypeValueParameterChangeHandler<TItem, TValue>(parameter, handler); 67 } 68 public class ValueTypeArrayParameterChangeHandler<TItem, TValue> : ParameterChangeHandler<TItem> 69 where TValue : struct 70 where TItem : ValueTypeArray<TValue> { 71 private ValueTypeArray<TValue> last; 72 73 protected ValueTypeArrayParameterChangeHandler(IValueParameter<TItem> parameter, Action handler) 74 : base(parameter, handler) { 75 last = parameter.Value; 76 if (last != null && !last.ReadOnly) 77 last.ToStringChanged += ParameterValueOnValueChanged; 78 } 79 80 protected override void ParameterOnValueChanged(object sender, EventArgs e) { 81 if (last != null) last.ToStringChanged -= ParameterValueOnValueChanged; 82 last = ((IValueParameter<TItem>)sender).Value; 83 if (last != null && !last.ReadOnly) 84 last.ToStringChanged += ParameterValueOnValueChanged; 85 base.ParameterOnValueChanged(sender, e); 86 } 87 88 protected void ParameterValueOnValueChanged(object sender, EventArgs e) { 89 handler(); 90 } 91 92 public static ValueTypeArrayParameterChangeHandler<TItem, TValue> Create(IValueParameter<TItem> parameter, Action handler) 93 => new ValueTypeArrayParameterChangeHandler<TItem, TValue>(parameter, handler); 94 } 95 96 public class ValueTypeMatrixParameterChangeHandler<TItem, TValue> : ParameterChangeHandler<TItem> 97 where TValue : struct 98 where TItem : ValueTypeMatrix<TValue> { 99 private ValueTypeMatrix<TValue> last; 100 101 protected ValueTypeMatrixParameterChangeHandler(IValueParameter<TItem> parameter, Action handler) 102 : base(parameter, handler) { 103 last = parameter.Value; 104 if (last != null && !last.ReadOnly) 105 last.ToStringChanged += ParameterValueOnValueChanged; 106 } 107 108 protected override void ParameterOnValueChanged(object sender, EventArgs e) { 109 if (last != null) last.ToStringChanged -= ParameterValueOnValueChanged; 110 last = ((IValueParameter<TItem>)sender).Value; 111 if (last != null && !last.ReadOnly) 112 last.ToStringChanged += ParameterValueOnValueChanged; 113 base.ParameterOnValueChanged(sender, e); 114 } 115 116 protected void ParameterValueOnValueChanged(object sender, EventArgs e) { 117 handler(); 118 } 119 120 public static ValueTypeMatrixParameterChangeHandler<TItem, TValue> Create(IValueParameter<TItem> parameter, Action handler) 121 => new ValueTypeMatrixParameterChangeHandler<TItem, TValue>(parameter, handler); 122 } 123 124 public class BoolValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<BoolValue, bool> { 70 125 private BoolValueParameterChangeHandler(IValueParameter<BoolValue> parameter, Action handler) : base(parameter, handler) { } 71 126 public static new BoolValueParameterChangeHandler Create(IValueParameter<BoolValue> parameter, Action handler) 72 127 => new BoolValueParameterChangeHandler(parameter, handler); 73 128 } 74 public class IntValueParameterChangeHandler : ParameterChangeHandler<IntValue, int> {129 public class IntValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<IntValue, int> { 75 130 private IntValueParameterChangeHandler(IValueParameter<IntValue> parameter, Action handler) : base(parameter, handler) { } 76 131 public static new IntValueParameterChangeHandler Create(IValueParameter<IntValue> parameter, Action handler) 77 132 => new IntValueParameterChangeHandler(parameter, handler); 78 133 } 79 public class DoubleValueParameterChangeHandler : ParameterChangeHandler<DoubleValue, double> {134 public class DoubleValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<DoubleValue, double> { 80 135 private DoubleValueParameterChangeHandler(IValueParameter<DoubleValue> parameter, Action handler) : base(parameter, handler) { } 81 136 public static new DoubleValueParameterChangeHandler Create(IValueParameter<DoubleValue> parameter, Action handler) 82 137 => new DoubleValueParameterChangeHandler(parameter, handler); 83 138 } 84 public class PercentValueParameterChangeHandler : ParameterChangeHandler<PercentValue, double> {139 public class PercentValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<PercentValue, double> { 85 140 private PercentValueParameterChangeHandler(IValueParameter<PercentValue> parameter, Action handler) : base(parameter, handler) { } 86 141 public static new PercentValueParameterChangeHandler Create(IValueParameter<PercentValue> parameter, Action handler) 87 142 => new PercentValueParameterChangeHandler(parameter, handler); 88 143 } 89 public class DateTimeValueParameterChangeHandler : ParameterChangeHandler<DateTimeValue, DateTime> {144 public class DateTimeValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<DateTimeValue, DateTime> { 90 145 private DateTimeValueParameterChangeHandler(IValueParameter<DateTimeValue> parameter, Action handler) : base(parameter, handler) { } 91 146 public static new DateTimeValueParameterChangeHandler Create(IValueParameter<DateTimeValue> parameter, Action handler) 92 147 => new DateTimeValueParameterChangeHandler(parameter, handler); 93 148 } 94 public class TimeSpanValueParameterChangeHandler : ParameterChangeHandler<TimeSpanValue, TimeSpan> {149 public class TimeSpanValueParameterChangeHandler : ValueTypeValueParameterChangeHandler<TimeSpanValue, TimeSpan> { 95 150 private TimeSpanValueParameterChangeHandler(IValueParameter<TimeSpanValue> parameter, Action handler) : base(parameter, handler) { } 96 151 public static new TimeSpanValueParameterChangeHandler Create(IValueParameter<TimeSpanValue> parameter, Action handler) 97 152 => new TimeSpanValueParameterChangeHandler(parameter, handler); 98 153 } 99 public class EnumValueParameterChangeHandler<TEnum> : ParameterChangeHandler<EnumValue<TEnum>, TEnum> where TEnum : struct, IComparable {154 public class EnumValueParameterChangeHandler<TEnum> : ValueTypeValueParameterChangeHandler<EnumValue<TEnum>, TEnum> where TEnum : struct, IComparable { 100 155 private EnumValueParameterChangeHandler(IValueParameter<EnumValue<TEnum>> parameter, Action handler) : base(parameter, handler) { } 101 156 public static new EnumValueParameterChangeHandler<TEnum> Create(IValueParameter<EnumValue<TEnum>> parameter, Action handler) 102 157 => new EnumValueParameterChangeHandler<TEnum>(parameter, handler); 103 158 } 159 public class BoolArrayParameterChangeHandler : ValueTypeArrayParameterChangeHandler<BoolArray, bool> { 160 private BoolArrayParameterChangeHandler(IValueParameter<BoolArray> parameter, Action handler) : base(parameter, handler) { } 161 public static new BoolArrayParameterChangeHandler Create(IValueParameter<BoolArray> parameter, Action handler) 162 => new BoolArrayParameterChangeHandler(parameter, handler); 163 } 164 public class IntArrayParameterChangeHandler : ValueTypeArrayParameterChangeHandler<IntArray, int> { 165 private IntArrayParameterChangeHandler(IValueParameter<IntArray> parameter, Action handler) : base(parameter, handler) { } 166 public static new IntArrayParameterChangeHandler Create(IValueParameter<IntArray> parameter, Action handler) 167 => new IntArrayParameterChangeHandler(parameter, handler); 168 } 169 public class DoubleArrayParameterChangeHandler : ValueTypeArrayParameterChangeHandler<DoubleArray, double> { 170 private DoubleArrayParameterChangeHandler(IValueParameter<DoubleArray> parameter, Action handler) : base(parameter, handler) { } 171 public static new DoubleArrayParameterChangeHandler Create(IValueParameter<DoubleArray> parameter, Action handler) 172 => new DoubleArrayParameterChangeHandler(parameter, handler); 173 } 174 public class BoolMatrixParameterChangeHandler : ValueTypeMatrixParameterChangeHandler<BoolMatrix, bool> { 175 private BoolMatrixParameterChangeHandler(IValueParameter<BoolMatrix> parameter, Action handler) : base(parameter, handler) { } 176 public static new BoolMatrixParameterChangeHandler Create(IValueParameter<BoolMatrix> parameter, Action handler) 177 => new BoolMatrixParameterChangeHandler(parameter, handler); 178 } 179 public class IntMatrixParameterChangeHandler : ValueTypeMatrixParameterChangeHandler<IntMatrix, int> { 180 private IntMatrixParameterChangeHandler(IValueParameter<IntMatrix> parameter, Action handler) : base(parameter, handler) { } 181 public static new IntMatrixParameterChangeHandler Create(IValueParameter<IntMatrix> parameter, Action handler) 182 => new IntMatrixParameterChangeHandler(parameter, handler); 183 } 184 public class DoubleMatrixParameterChangeHandler : ValueTypeMatrixParameterChangeHandler<DoubleMatrix, double> { 185 private DoubleMatrixParameterChangeHandler(IValueParameter<DoubleMatrix> parameter, Action handler) : base(parameter, handler) { } 186 public static new DoubleMatrixParameterChangeHandler Create(IValueParameter<DoubleMatrix> parameter, Action handler) 187 => new DoubleMatrixParameterChangeHandler(parameter, handler); 188 } 104 189 public class StringValueParameterChangeHandler : ParameterChangeHandler<StringValue> { // StringValue does not derive from ValueTypeValue 105 190 private StringValue last;
Note: See TracChangeset
for help on using the changeset viewer.