-
Notifications
You must be signed in to change notification settings - Fork 0
/
Property.java
executable file
·338 lines (273 loc) · 6.09 KB
/
Property.java
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
package peter;
/**
* This is a property interface.
*
* @author Peter Ehrlich
*
*/
public interface Property {
public abstract String getName();
public abstract String getStrVal();
public abstract void setVal(String val);
public abstract void plus();
public abstract void minus();
public abstract void bigPlus();
public abstract void bigMinus();
// TODO: make string property
// TODO: add to view instead?
public class FloatProperty implements Property {
private float val, inc;
private String name;
private Float max = null, min = null;
/**
* Will have a default inc of 0.1
* @param name
* @param _val
*/
public FloatProperty(String _name, float _val){
name = _name;
val = _val;
inc = 0.1f;
}
/**
* Make a new property
*
* @param _name
* This will be displayed in the menu as the name you're adjusting, as well as saved to the
* properties file. Advised same as variable name. (Spaces ok.)
* @param _val
* This is the default value, and will be used if this property cannot be loaded from the
* file.
* @param _inc
* This is the increment when user press up/down on the nxt.
*/
public FloatProperty(String _name, float _val, float _inc) {
val = _val;
inc = _inc;
name = _name;
}
public String getName() {
return name;
}
//
public float getVal() {
return val;
}
public String getStrVal() {
return Float.toString(val);
}
public void setVal(String val) {
this.val = Float.parseFloat(val);
}
public void plus() {
val += inc;
if (max != null && val > max) {
val = max;
}
}
public void minus() {
val -= inc;
if (min != null && val < min) {
val = min;
}
}
public void bigPlus() {
val += inc * 2;
if (max != null && val > max) {
val = max;
}
}
public void bigMinus() {
val -= inc * 2;
if (min != null && val < min) {
val = min;
}
}
public void setMax(float max) {
this.max = max;
}
public void setMin(float min) {
this.min = min;
}
}
public class IntProperty implements Property {
private int val, inc;
private Integer max = null, min = null;
private String name;
/**
* Will have a default increment of 1.
* @param _name
* @param _val
*/
public IntProperty(String _name, int _val) {
val = _val;
inc = 1;
name = _name;
}
/**
* Make a new property
*
* @param _name
* This will be displayed in the menu as the name you're adjusting, as well as saved to the
* properties file. Advised same as variable name. (Spaces ok.)
* @param _val
* This is the default value, and will be used if this property cannot be loaded from the
* file.
* @param _inc
* This is the increment when user press up/down on the nxt.
*/
public IntProperty(String _name, int _val, int _inc) {
val = _val;
inc = _inc;
name = _name;
}
public String getName() {
return name;
}
public int getVal() {
return val;
}
public String getStrVal() {
return Float.toString(val);
}
public void setVal(String val) {
this.val = (int) Math.round(Float.parseFloat(val));
}
public void plus() {
val += inc;
if (max != null && val > max)
val = max;
}
public void minus() {
val -= inc;
if (min != null && val < min)
val = min;
}
public void bigPlus() {
val += inc * 2;
if (max != null && val > max)
val = max;
}
public void bigMinus() {
val -= inc * 2;
if (min != null && val < min)
val = min;
}
public void setMax(int max) {
this.max = max;
}
public void setMin(int min) {
this.min = min;
}
}
public class BoolProperty implements Property {
private boolean value;
private String name;
public BoolProperty(String name, boolean value) {
super();
this.value = value;
this.name = name;
}
public void bigMinus() {
value = !value;
}
public void bigPlus() {
value = !value;
}
public String getName() {
return name;
}
public String getStrVal() {
if (value)
return "true";
return "false";
}
public void minus() {
value = !value;
}
public void plus() {
value = !value;
}
public void setVal(String val) {
value = Boolean.parseBoolean(val);
}
public boolean getVal() {
return value;
}
}
public class StringProperty implements Property {
private String[] options;
private String name;
private int value;
private Integer max = null, min = null;
/**
* Properties constructed with this can only be viewed, and have no way of being set.
* @param name
*/
public StringProperty(String name) {
super();
this.name = name;
}
public StringProperty(String name, String[] options, int value) {
super();
this.options = options;
this.name = name;
this.value = value;
}
public void bigMinus() {
if (min != null && value > min)
value--;
if (min != null && value > min)
value--;
if (value == -1)
value = options.length - 1;
if (value == -2)
value = options.length - 2; // TODO: unchecked
if (max != null && value > max)
value = max;
}
public void bigPlus() { //shoulda just called plus twice
if (max != null && value < max)
value++;
if (max != null && value < max)
value++;
if (value == options.length)
value = 0;
if (value == options.length + 1)
value = 1;
if (min != null && value < min)
value = min;
}
public String getName() {
return name;
}
public String getStrVal() {
return name;
}
public void minus() {
if (min != null && value > min)
value--;
if (value == -1)
value = options.length - 1;
if (max != null && value > max)
value = max;
}
public void plus() {
if (max != null && value < max)
value++;
if (value == options.length)
value = 0;
if (min!=null && value < min)
value = min;
}
public void setMax(int max) {
this.max = max;
}
public void setMin(int min) {
this.min = min;
}
public void setVal(String val) {
value = Integer.parseInt(val);
}
}
}