1
1
// //////////////////////////////////////////////////////////
2
- // EmgSettingsUI.pde //
2
+ // EmgSettingsUI.pde //
3
3
// Display the Emg Settings UI as a popup //
4
+ // Note: This window is never resized. //
4
5
// //
5
6
// //////////////////////////////////////////////////////////
6
7
@@ -14,7 +15,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
14
15
private ControlP5 emgCp5;
15
16
private int x, y, w, h;
16
17
private final int HEADER_HEIGHT = 55 ;
17
- private final int FOOTER_PADDING = 80 ;
18
+ private final int FOOTER_PADDING = 90 ;
18
19
private final int PADDING_3 = 3 ;
19
20
private final int PADDING_12 = 12 ;
20
21
private final int NUM_CONTROL_BUTTONS = 3 ;
@@ -29,7 +30,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
29
30
private final int NUM_FOOTER_OBJECTS = 3 ;
30
31
private final int FOOTER_OBJECT_WIDTH = 45 ;
31
32
private final int FOOTER_OBJECT_HEIGHT = 26 ;
32
- private int footerObjY = 0 ;
33
+ private int footerObjY;
33
34
private int [] footerObjX = new int [NUM_FOOTER_OBJECTS ];
34
35
35
36
private final color HEADER_COLOR = OPENBCI_BLUE ;
@@ -42,14 +43,14 @@ class EmgSettingsUI extends PApplet implements Runnable {
42
43
public EmgSettingsValues emgSettingsValues;
43
44
44
45
private TextBox channelColumnLabel;
45
- private TextBox smoothLabel ;
46
+ private TextBox windowLabel ;
46
47
private TextBox uvLimitLabel;
47
48
private TextBox creepIncLabel;
48
49
private TextBox creepDecLabel;
49
50
private TextBox minDeltaUvLabel;
50
51
private TextBox lowLimitLabel;
51
52
52
- private ScrollableList [] smoothLists ;
53
+ private ScrollableList [] windowLists ;
53
54
private ScrollableList [] uvLimitLists;
54
55
private ScrollableList [] creepIncLists;
55
56
private ScrollableList [] creepDecLists;
@@ -118,9 +119,11 @@ class EmgSettingsUI extends PApplet implements Runnable {
118
119
scene();
119
120
120
121
// Draw header
122
+ pushStyle ();
121
123
noStroke ();
122
124
fill (HEADER_COLOR );
123
125
rect (0 , 0 , width , HEADER_HEIGHT );
126
+ popStyle ();
124
127
125
128
emgSettingsValues = dataProcessing. emgSettings. values;
126
129
@@ -129,7 +132,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
129
132
130
133
// Draw column labels
131
134
channelColumnLabel. draw();
132
- smoothLabel . draw();
135
+ windowLabel . draw();
133
136
uvLimitLabel. draw();
134
137
creepIncLabel. draw();
135
138
creepDecLabel. draw();
@@ -139,56 +142,19 @@ class EmgSettingsUI extends PApplet implements Runnable {
139
142
drawChannelLabels();
140
143
141
144
// Draw cp5 objects on top of everything
142
- emgCp5. draw();
143
- }
144
-
145
- private void screenResized () {
146
- x = 0 ;
147
- y = 0 ;
148
- w = width ;
149
- h = height ;
150
-
151
- emgCp5. setGraphics(ourApplet, 0 , 0 );
152
-
153
- int colWidth = (width / NUM_COLUMNS );
154
- int colOffset = colWidth / 2 ;
155
- int labelY = y + HEADER_HEIGHT / 2 ;
156
- channelColumnLabel. setPosition(x + colOffset, labelY);
157
- smoothLabel. setPosition(x + colOffset + colWidth, labelY);
158
- uvLimitLabel. setPosition(x + colOffset + colWidth* 2 , labelY);
159
- creepIncLabel. setPosition(x + colOffset + colWidth* 3 , labelY);
160
- creepDecLabel. setPosition(x + colOffset + colWidth* 4 , labelY);
161
- minDeltaUvLabel. setPosition(x + colOffset + colWidth* 5 , labelY);
162
- lowLimitLabel. setPosition(x + colOffset + colWidth* 6 , labelY);
163
-
164
- resizeDropdowns();
145
+ try {
146
+ emgCp5. draw();
147
+ } catch (ConcurrentModificationException e) {
148
+ e. printStackTrace();
149
+ outputError(" EMG Settings UI: Unable to draw cp5 objects." );
150
+ }
165
151
}
166
152
167
153
private void scene () {
168
154
// Draw background
169
155
background (BACKGROUND_COLOR );
170
156
}
171
157
172
- @Override
173
- public void keyReleased () {
174
-
175
- }
176
-
177
- @Override
178
- public void keyPressed () {
179
-
180
- }
181
-
182
- @Override
183
- public void mousePressed () {
184
-
185
- }
186
-
187
- @Override
188
- public void mouseReleased () {
189
-
190
- }
191
-
192
158
@Override
193
159
public void exit () {
194
160
dispose();
@@ -229,23 +195,23 @@ class EmgSettingsUI extends PApplet implements Runnable {
229
195
230
196
for (int i = 0 ; i < channelCount; i++ ) {
231
197
String channelLabel = channelCount > channelLabels. length ? " Channel " + Integer . toString(i + 1 ) : channelLabels[i];
232
- text (channelLabel, x + colOffset, dropdownYPositions[i] + (DROPDOWN_HEIGHT / 2 ));
198
+ text (channelLabel, x + colOffset, dropdownYPositions[i] + (DROPDOWN_HEIGHT / 2 ) - 2 );
233
199
}
234
200
235
201
popStyle ();
236
202
}
237
203
238
204
private void resizeDropdowns () {
239
205
dropdownWidth = int ((w - (DROPDOWN_SPACER * (NUM_COLUMNS + 1 ))) / NUM_COLUMNS );
240
- final int MAX_HEIGHT_ITEMS = channelCount == 4 ? 8 : 5 ;
206
+ final int MAX_HEIGHT_ITEMS = 6 ;
241
207
242
208
for (int i = 0 ; i < channelCount; i++ ) {
243
209
int dropdownX = x + DROPDOWN_SPACER * 2 + dropdownWidth;
244
210
dropdownYPositions[i] = HEADER_HEIGHT + int (y + ((ROW_HEIGHT ) * i) + (((ROW_HEIGHT ) - DROPDOWN_HEIGHT ) / 2 ));
245
211
final int buttonXIncrement = DROPDOWN_SPACER + dropdownWidth;
246
212
247
- smoothLists [i]. setPosition(dropdownX, dropdownYPositions[i]);
248
- smoothLists [i]. setSize(dropdownWidth, MAX_HEIGHT_ITEMS * DROPDOWN_HEIGHT );
213
+ windowLists [i]. setPosition(dropdownX, dropdownYPositions[i]);
214
+ windowLists [i]. setSize(dropdownWidth, MAX_HEIGHT_ITEMS * DROPDOWN_HEIGHT );
249
215
250
216
dropdownX += buttonXIncrement;
251
217
uvLimitLists[i]. setPosition(dropdownX, dropdownYPositions[i]);
@@ -270,7 +236,8 @@ class EmgSettingsUI extends PApplet implements Runnable {
270
236
}
271
237
272
238
private void createAllUIObjects () {
273
- footerObjY = y + h - FOOTER_PADDING + PADDING_3 ;
239
+ final int HALF_FOOTER_HEIGHT = (FOOTER_PADDING + (DROPDOWN_SPACER * 2 )) / 2 ;
240
+ footerObjY = y + h - HALF_FOOTER_HEIGHT - (FOOTER_OBJECT_HEIGHT / 2 );
274
241
int middle = x + w / 2 ;
275
242
int halfObjWidth = FOOTER_OBJECT_WIDTH / 2 ;
276
243
footerObjX[0 ] = middle - halfObjWidth - PADDING_12 - FOOTER_OBJECT_WIDTH ;
@@ -291,13 +258,13 @@ class EmgSettingsUI extends PApplet implements Runnable {
291
258
int colWidth = (w / NUM_COLUMNS );
292
259
int colOffset = colWidth / 2 ;
293
260
int labelY = y + HEADER_HEIGHT / 2 ;
294
- channelColumnLabel = new TextBox (" Channel" , x + colOffset, labelY, labelTxt, labelBG, 12 , h3 , CENTER , TOP );
295
- smoothLabel = new TextBox (" Smooth " , x + colOffset + colWidth, labelY, labelTxt, labelBG, 12 , h3 , CENTER , TOP );
296
- uvLimitLabel = new TextBox (" uV Limit" , x + colOffset + colWidth* 2 , labelY, labelTxt, labelBG, 12 , h3 , CENTER , TOP );
297
- creepIncLabel = new TextBox (" Creep +" , x + colOffset + colWidth* 3 , labelY, labelTxt, labelBG, 12 , h3 , CENTER , TOP );
298
- creepDecLabel = new TextBox (" Creep -" , x + colOffset + colWidth* 4 , labelY, labelTxt, labelBG, 12 , h3 , CENTER , TOP );
299
- minDeltaUvLabel = new TextBox (" Min \u 0394uV" , x + colOffset + colWidth* 5 , labelY, labelTxt, labelBG, 12 , h3 , CENTER , TOP );
300
- lowLimitLabel = new TextBox (" Low Limit" , x + colOffset + colWidth* 6 , labelY, labelTxt, labelBG, 12 , h3 , CENTER , TOP );
261
+ channelColumnLabel = new TextBox (" Channel" , x + colOffset, labelY, labelTxt, labelBG, 14 , h4 , CENTER , CENTER );
262
+ windowLabel = new TextBox (" Window " , x + colOffset + colWidth, labelY, labelTxt, labelBG, 14 , h4 , CENTER , CENTER );
263
+ uvLimitLabel = new TextBox (" uV Limit" , x + colOffset + colWidth* 2 , labelY, labelTxt, labelBG, 14 , h4 , CENTER , CENTER );
264
+ creepIncLabel = new TextBox (" Creep +" , x + colOffset + colWidth* 3 , labelY, labelTxt, labelBG, 14 , h4 , CENTER , CENTER );
265
+ creepDecLabel = new TextBox (" Creep -" , x + colOffset + colWidth* 4 , labelY, labelTxt, labelBG, 14 , h4 , CENTER , CENTER );
266
+ minDeltaUvLabel = new TextBox (" Min \u 0394uV" , x + colOffset + colWidth* 5 , labelY, labelTxt, labelBG, 14 , h4 , CENTER , CENTER );
267
+ lowLimitLabel = new TextBox (" Low Limit" , x + colOffset + colWidth* 6 , labelY, labelTxt, labelBG, 14 , h4 , CENTER , CENTER );
301
268
302
269
createAllDropdowns();
303
270
}
@@ -306,7 +273,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
306
273
// the size and space of these buttons are dependendant on the size of the screen and full ChannelController
307
274
verbosePrint(" EmgChannelSettingsUI: Creating EMG channel setting UI objects..." );
308
275
309
- smoothLists = new ScrollableList [channelCount];
276
+ windowLists = new ScrollableList [channelCount];
310
277
uvLimitLists = new ScrollableList [channelCount];
311
278
creepIncLists = new ScrollableList [channelCount];
312
279
creepDecLists = new ScrollableList [channelCount];
@@ -318,7 +285,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
318
285
// Init dropdowns in reverse so that chan 1 draws on top of chan 2, etc.
319
286
for (int i = channelCount - 1 ; i >= 0 ; i-- ) {
320
287
int exgChannel = i;
321
- smoothLists [i] = createDropdown(exgChannel, " smooth_ch_" + (i+ 1 ), emgSettingsValues. smoothing [exgChannel]. values(), emgSettingsValues. smoothing [exgChannel]);
288
+ windowLists [i] = createDropdown(exgChannel, " smooth_ch_" + (i+ 1 ), emgSettingsValues. window [exgChannel]. values(), emgSettingsValues. window [exgChannel]);
322
289
uvLimitLists[i] = createDropdown(exgChannel, " uvLimit_ch_" + (i+ 1 ), emgSettingsValues. uvLimit[exgChannel]. values(), emgSettingsValues. uvLimit[exgChannel]);
323
290
creepIncLists[i] = createDropdown(exgChannel, " creep_inc_ch_" + (i+ 1 ), emgSettingsValues. creepIncreasing[exgChannel]. values(), emgSettingsValues. creepIncreasing[exgChannel]);
324
291
creepDecLists[i] = createDropdown(exgChannel, " creep_dec_ch_" + (i+ 1 ), emgSettingsValues. creepDecreasing[exgChannel]. values(), emgSettingsValues. creepDecreasing[exgChannel]);
@@ -386,9 +353,8 @@ class EmgSettingsUI extends PApplet implements Runnable {
386
353
EmgSettingsEnum myEnum = (EmgSettingsEnum )bob. get(" value" );
387
354
verbosePrint(" EmgSettings: " + (theEvent. getController()). getName() + " == " + myEnum. getString());
388
355
389
- if (myEnum instanceof EmgSmoothing ) {
390
- // verbosePrint("HardwareSettings: previousVal == " + emgSettingsValues.previousValues.gain[channel]);
391
- emgSettingsValues. smoothing[channel] = (EmgSmoothing )myEnum;
356
+ if (myEnum instanceof EmgWindow ) {
357
+ emgSettingsValues. window[channel] = (EmgWindow )myEnum;
392
358
} else if (myEnum instanceof EmgUVLimit ) {
393
359
emgSettingsValues. uvLimit[channel] = (EmgUVLimit )myEnum;
394
360
} else if (myEnum instanceof EmgCreepIncreasing ) {
@@ -437,15 +403,15 @@ class EmgSettingsUI extends PApplet implements Runnable {
437
403
private void updateCp5Objects () {
438
404
for (int i = 0 ; i < channelCount; i++ ) {
439
405
// Fetch values from the EmgSettingsValues object
440
- EmgSmoothing updateSmoothing = emgSettingsValues. smoothing [i];
406
+ EmgWindow updateSmoothing = emgSettingsValues. window [i];
441
407
EmgUVLimit updateUVLimit = emgSettingsValues. uvLimit[i];
442
408
EmgCreepIncreasing updateCreepIncreasing = emgSettingsValues. creepIncreasing[i];
443
409
EmgCreepDecreasing updateCreepDecreasing = emgSettingsValues. creepDecreasing[i];
444
410
EmgMinimumDeltaUV updateMinimumDeltaUV = emgSettingsValues. minimumDeltaUV[i];
445
411
EmgLowerThresholdMinimum updateLowerThresholdMinimum = emgSettingsValues. lowerThresholdMinimum[i];
446
412
447
413
// Update the ScrollableLists
448
- smoothLists [i]. getCaptionLabel(). setText(updateSmoothing. getString());
414
+ windowLists [i]. getCaptionLabel(). setText(updateSmoothing. getString());
449
415
uvLimitLists[i]. getCaptionLabel(). setText(updateUVLimit. getString());
450
416
creepIncLists[i]. getCaptionLabel(). setText(updateCreepIncreasing. getString());
451
417
creepDecLists[i]. getCaptionLabel(). setText(updateCreepDecreasing. getString());
0 commit comments