11// //////////////////////////////////////////////////////////
2- // EmgSettingsUI.pde //
2+ // EmgSettingsUI.pde //
33// Display the Emg Settings UI as a popup //
4+ // Note: This window is never resized. //
45// //
56// //////////////////////////////////////////////////////////
67
@@ -14,7 +15,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
1415 private ControlP5 emgCp5;
1516 private int x, y, w, h;
1617 private final int HEADER_HEIGHT = 55 ;
17- private final int FOOTER_PADDING = 80 ;
18+ private final int FOOTER_PADDING = 90 ;
1819 private final int PADDING_3 = 3 ;
1920 private final int PADDING_12 = 12 ;
2021 private final int NUM_CONTROL_BUTTONS = 3 ;
@@ -29,7 +30,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
2930 private final int NUM_FOOTER_OBJECTS = 3 ;
3031 private final int FOOTER_OBJECT_WIDTH = 45 ;
3132 private final int FOOTER_OBJECT_HEIGHT = 26 ;
32- private int footerObjY = 0 ;
33+ private int footerObjY;
3334 private int [] footerObjX = new int [NUM_FOOTER_OBJECTS ];
3435
3536 private final color HEADER_COLOR = OPENBCI_BLUE ;
@@ -42,14 +43,14 @@ class EmgSettingsUI extends PApplet implements Runnable {
4243 public EmgSettingsValues emgSettingsValues;
4344
4445 private TextBox channelColumnLabel;
45- private TextBox smoothLabel ;
46+ private TextBox windowLabel ;
4647 private TextBox uvLimitLabel;
4748 private TextBox creepIncLabel;
4849 private TextBox creepDecLabel;
4950 private TextBox minDeltaUvLabel;
5051 private TextBox lowLimitLabel;
5152
52- private ScrollableList [] smoothLists ;
53+ private ScrollableList [] windowLists ;
5354 private ScrollableList [] uvLimitLists;
5455 private ScrollableList [] creepIncLists;
5556 private ScrollableList [] creepDecLists;
@@ -118,9 +119,11 @@ class EmgSettingsUI extends PApplet implements Runnable {
118119 scene();
119120
120121 // Draw header
122+ pushStyle ();
121123 noStroke ();
122124 fill (HEADER_COLOR );
123125 rect (0 , 0 , width , HEADER_HEIGHT );
126+ popStyle ();
124127
125128 emgSettingsValues = dataProcessing. emgSettings. values;
126129
@@ -129,7 +132,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
129132
130133 // Draw column labels
131134 channelColumnLabel. draw();
132- smoothLabel . draw();
135+ windowLabel . draw();
133136 uvLimitLabel. draw();
134137 creepIncLabel. draw();
135138 creepDecLabel. draw();
@@ -139,56 +142,19 @@ class EmgSettingsUI extends PApplet implements Runnable {
139142 drawChannelLabels();
140143
141144 // 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+ }
165151 }
166152
167153 private void scene () {
168154 // Draw background
169155 background (BACKGROUND_COLOR );
170156 }
171157
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-
192158 @Override
193159 public void exit () {
194160 dispose();
@@ -229,23 +195,23 @@ class EmgSettingsUI extends PApplet implements Runnable {
229195
230196 for (int i = 0 ; i < channelCount; i++ ) {
231197 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 );
233199 }
234200
235201 popStyle ();
236202 }
237203
238204 private void resizeDropdowns () {
239205 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 ;
241207
242208 for (int i = 0 ; i < channelCount; i++ ) {
243209 int dropdownX = x + DROPDOWN_SPACER * 2 + dropdownWidth;
244210 dropdownYPositions[i] = HEADER_HEIGHT + int (y + ((ROW_HEIGHT ) * i) + (((ROW_HEIGHT ) - DROPDOWN_HEIGHT ) / 2 ));
245211 final int buttonXIncrement = DROPDOWN_SPACER + dropdownWidth;
246212
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 );
249215
250216 dropdownX += buttonXIncrement;
251217 uvLimitLists[i]. setPosition(dropdownX, dropdownYPositions[i]);
@@ -270,7 +236,8 @@ class EmgSettingsUI extends PApplet implements Runnable {
270236 }
271237
272238 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 );
274241 int middle = x + w / 2 ;
275242 int halfObjWidth = FOOTER_OBJECT_WIDTH / 2 ;
276243 footerObjX[0 ] = middle - halfObjWidth - PADDING_12 - FOOTER_OBJECT_WIDTH ;
@@ -291,13 +258,13 @@ class EmgSettingsUI extends PApplet implements Runnable {
291258 int colWidth = (w / NUM_COLUMNS );
292259 int colOffset = colWidth / 2 ;
293260 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 );
301268
302269 createAllDropdowns();
303270 }
@@ -306,7 +273,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
306273 // the size and space of these buttons are dependendant on the size of the screen and full ChannelController
307274 verbosePrint(" EmgChannelSettingsUI: Creating EMG channel setting UI objects..." );
308275
309- smoothLists = new ScrollableList [channelCount];
276+ windowLists = new ScrollableList [channelCount];
310277 uvLimitLists = new ScrollableList [channelCount];
311278 creepIncLists = new ScrollableList [channelCount];
312279 creepDecLists = new ScrollableList [channelCount];
@@ -318,7 +285,7 @@ class EmgSettingsUI extends PApplet implements Runnable {
318285 // Init dropdowns in reverse so that chan 1 draws on top of chan 2, etc.
319286 for (int i = channelCount - 1 ; i >= 0 ; i-- ) {
320287 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]);
322289 uvLimitLists[i] = createDropdown(exgChannel, " uvLimit_ch_" + (i+ 1 ), emgSettingsValues. uvLimit[exgChannel]. values(), emgSettingsValues. uvLimit[exgChannel]);
323290 creepIncLists[i] = createDropdown(exgChannel, " creep_inc_ch_" + (i+ 1 ), emgSettingsValues. creepIncreasing[exgChannel]. values(), emgSettingsValues. creepIncreasing[exgChannel]);
324291 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 {
386353 EmgSettingsEnum myEnum = (EmgSettingsEnum )bob. get(" value" );
387354 verbosePrint(" EmgSettings: " + (theEvent. getController()). getName() + " == " + myEnum. getString());
388355
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;
392358 } else if (myEnum instanceof EmgUVLimit ) {
393359 emgSettingsValues. uvLimit[channel] = (EmgUVLimit )myEnum;
394360 } else if (myEnum instanceof EmgCreepIncreasing ) {
@@ -437,15 +403,15 @@ class EmgSettingsUI extends PApplet implements Runnable {
437403 private void updateCp5Objects () {
438404 for (int i = 0 ; i < channelCount; i++ ) {
439405 // Fetch values from the EmgSettingsValues object
440- EmgSmoothing updateSmoothing = emgSettingsValues. smoothing [i];
406+ EmgWindow updateSmoothing = emgSettingsValues. window [i];
441407 EmgUVLimit updateUVLimit = emgSettingsValues. uvLimit[i];
442408 EmgCreepIncreasing updateCreepIncreasing = emgSettingsValues. creepIncreasing[i];
443409 EmgCreepDecreasing updateCreepDecreasing = emgSettingsValues. creepDecreasing[i];
444410 EmgMinimumDeltaUV updateMinimumDeltaUV = emgSettingsValues. minimumDeltaUV[i];
445411 EmgLowerThresholdMinimum updateLowerThresholdMinimum = emgSettingsValues. lowerThresholdMinimum[i];
446412
447413 // Update the ScrollableLists
448- smoothLists [i]. getCaptionLabel(). setText(updateSmoothing. getString());
414+ windowLists [i]. getCaptionLabel(). setText(updateSmoothing. getString());
449415 uvLimitLists[i]. getCaptionLabel(). setText(updateUVLimit. getString());
450416 creepIncLists[i]. getCaptionLabel(). setText(updateCreepIncreasing. getString());
451417 creepDecLists[i]. getCaptionLabel(). setText(updateCreepDecreasing. getString());
0 commit comments