1414// //
1515// //////////////////////////////////////////////////////////////////////////////////////////////////////
1616
17- class W_BandPower extends Widget {
17+ class W_BandPower extends WidgetWithSettings {
1818 // indexes
1919 private final int DELTA = 0 ; // 1-4 Hz
2020 private final int THETA = 1 ; // 4-8 Hz
@@ -30,11 +30,7 @@ class W_BandPower extends Widget {
3030 public ExGChannelSelect bpChanSelect;
3131 private boolean prevChanSelectIsVisible = false ;
3232
33- private List<controlP5. Controller > cp5ElementsToCheck = new ArrayList<controlP5. Controller > ();
34-
35- BPAutoClean autoClean = BPAutoClean . OFF ;
36- BPAutoCleanThreshold autoCleanThreshold = BPAutoCleanThreshold . FIFTY ;
37- BPAutoCleanTimer autoCleanTimer = BPAutoCleanTimer . THREE_SECONDS ;
33+ private List<controlP5. Controller > cp5ElementsToCheck;
3834
3935 int [] autoCleanTimers;
4036 boolean [] previousThresholdCrossed;
@@ -46,28 +42,6 @@ class W_BandPower extends Widget {
4642 autoCleanTimers = new int [currentBoard. getNumEXGChannels()];
4743 previousThresholdCrossed = new boolean [currentBoard. getNumEXGChannels()];
4844
49- // Add channel select dropdown to this widget
50- bpChanSelect = new ExGChannelSelect (ourApplet, x, y, w, navH);
51- bpChanSelect. activateAllButtons();
52-
53- cp5ElementsToCheck. addAll(bpChanSelect. getCp5ElementsForOverlapCheck());
54-
55- List<String > autoCleanList = EnumHelper . getEnumStrings(BPAutoClean . class);
56- List<String > autoCleanThresholdList = EnumHelper . getEnumStrings(BPAutoCleanThreshold . class);
57- List<String > autoCleanTimerList = EnumHelper . getEnumStrings(BPAutoCleanTimer . class);
58- List<String > smoothingFactorList = EnumHelper . getEnumStrings(FFTSmoothingFactor . class);
59- List<String > filteredEnumList = EnumHelper . getEnumStrings(FFTFilteredEnum . class);
60-
61- // Add settings dropdowns
62- addDropdown(" bandPowerAutoCleanDropdown" , " AutoClean" , autoCleanList, autoClean. getIndex());
63- addDropdown(" bandPowerAutoCleanThresholdDropdown" , " Threshold" , autoCleanThresholdList, autoCleanThreshold. getIndex());
64- addDropdown(" bandPowerAutoCleanTimerDropdown" , " Timer" , autoCleanTimerList, autoCleanTimer. getIndex());
65- // These two dropdowns also have to mirror the settings in the FFT widget
66- FFTSmoothingFactor smoothingFactor = globalFFTSettings. getSmoothingFactor();
67- FFTFilteredEnum filteredEnum = globalFFTSettings. getFilteredEnum();
68- addDropdown(" bandPowerSmoothingDropdown" , " Smooth" , smoothingFactorList, smoothingFactor. getIndex());
69- addDropdown(" bandPowerDataFilteringDropdown" , " Filtered?" , filteredEnumList, filteredEnum. getIndex());
70-
7145 // Setup for the BandPower plot
7246 bp_plot = new GPlot (ourApplet, x, y- NAV_HEIGHT , w, h+ NAV_HEIGHT );
7347 // bp_plot.setPos(x, y+NAV_HEIGHT);
@@ -110,6 +84,46 @@ class W_BandPower extends Widget {
11084 bp_plot. getHistogram(). setFontColor(OPENBCI_DARKBLUE );
11185 }
11286
87+ @Override
88+ protected void initWidgetSettings () {
89+ super . initWidgetSettings();
90+ widgetSettings. set(BPAutoClean . class, BPAutoClean . OFF )
91+ .set(BPAutoCleanThreshold . class, BPAutoCleanThreshold . FIFTY )
92+ .set(BPAutoCleanTimer . class, BPAutoCleanTimer . THREE_SECONDS )
93+ .set(FFTSmoothingFactor . class, globalFFTSettings. getSmoothingFactor())
94+ .set(FFTFilteredEnum . class, globalFFTSettings. getFilteredEnum());
95+
96+ initDropdown(BPAutoClean . class, " bandPowerAutoCleanDropdown" , " Auto Clean" );
97+ initDropdown(BPAutoCleanThreshold . class, " bandPowerAutoCleanThresholdDropdown" , " Threshold" );
98+ initDropdown(BPAutoCleanTimer . class, " bandPowerAutoCleanTimerDropdown" , " Timer" );
99+ initDropdown(FFTSmoothingFactor . class, " bandPowerSmoothingDropdown" , " Smooth" );
100+ initDropdown(FFTFilteredEnum . class, " bandPowerDataFilteringDropdown" , " Filtered?" );
101+
102+ bpChanSelect = new ExGChannelSelect (ourApplet, x, y, w, navH);
103+ bpChanSelect. activateAllButtons();
104+ cp5ElementsToCheck = new ArrayList<controlP5. Controller > ();
105+ cp5ElementsToCheck. addAll(bpChanSelect. getCp5ElementsForOverlapCheck());
106+ saveActiveChannels(bpChanSelect. getActiveChannels());
107+ widgetSettings. saveDefaults();
108+ }
109+
110+ @Override
111+ protected void applySettings () {
112+ updateDropdownLabel(BPAutoClean . class, " bandPowerAutoCleanDropdown" );
113+ updateDropdownLabel(BPAutoCleanThreshold . class, " bandPowerAutoCleanThresholdDropdown" );
114+ updateDropdownLabel(BPAutoCleanTimer . class, " bandPowerAutoCleanTimerDropdown" );
115+ updateDropdownLabel(FFTSmoothingFactor . class, " bandPowerSmoothingDropdown" );
116+ updateDropdownLabel(FFTFilteredEnum . class, " bandPowerDataFilteringDropdown" );
117+ applyActiveChannels(bpChanSelect);
118+ }
119+
120+ @Override
121+ protected void updateChannelSettings () {
122+ if (bpChanSelect != null ) {
123+ saveActiveChannels(bpChanSelect. getActiveChannels());
124+ }
125+ }
126+
113127 public void update () {
114128 super . update();
115129
@@ -189,6 +203,9 @@ class W_BandPower extends Widget {
189203 }
190204
191205 private void autoCleanByEnableDisableChannels () {
206+ BPAutoClean autoClean = widgetSettings. get(BPAutoClean . class);
207+ BPAutoCleanThreshold autoCleanThreshold = widgetSettings. get(BPAutoCleanThreshold . class);
208+ BPAutoCleanTimer autoCleanTimer = widgetSettings. get(BPAutoCleanTimer . class);
192209 if (autoClean == BPAutoClean . OFF ) {
193210 return ;
194211 }
@@ -215,30 +232,18 @@ class W_BandPower extends Widget {
215232 }
216233 }
217234
218- public BPAutoClean getAutoClean () {
219- return autoClean;
220- }
221-
222- public BPAutoCleanThreshold getAutoCleanThreshold () {
223- return autoCleanThreshold;
224- }
225-
226- public BPAutoCleanTimer getAutoCleanTimer () {
227- return autoCleanTimer;
228- }
229-
230235 public void setAutoClean (int n ) {
231- autoClean = autoClean . values()[n] ;
236+ widgetSettings . setByIndex( BPAutoClean . class, n) ;
232237 Arrays . fill(previousThresholdCrossed, false );
233238 Arrays . fill(autoCleanTimers, 0 );
234239 }
235240
236241 public void setAutoCleanThreshold (int n ) {
237- autoCleanThreshold = autoCleanThreshold . values()[n] ;
242+ widgetSettings . setByIndex( BPAutoCleanThreshold . class, n) ;
238243 }
239244
240245 public void setAutoCleanTimer (int n ) {
241- autoCleanTimer = autoCleanTimer . values()[n] ;
246+ widgetSettings . setByIndex( BPAutoCleanTimer . class, n) ;
242247 }
243248
244249 // Called in DataProcessing.pde to update data even if widget is closed
@@ -261,13 +266,13 @@ class W_BandPower extends Widget {
261266 }
262267
263268 public void setSmoothingDropdownFrontend (FFTSmoothingFactor _smoothingFactor ) {
264- String s = _smoothingFactor . getString( );
265- cp5_widget . getController( " bandPowerSmoothingDropdown" ) . getCaptionLabel() . setText(s );
269+ widgetSettings . set( FFTSmoothingFactor . class, _smoothingFactor );
270+ updateDropdownLabel( FFTSmoothingFactor . class, " bandPowerSmoothingDropdown" );
266271 }
267272
268273 public void setFilteringDropdownFrontend (FFTFilteredEnum _filteredEnum ) {
269- String s = _filteredEnum . getString( );
270- cp5_widget . getController( " bandPowerDataFilteringDropdown" ) . getCaptionLabel() . setText(s );
274+ widgetSettings . set( FFTFilteredEnum . class, _filteredEnum );
275+ updateDropdownLabel( FFTFilteredEnum . class, " bandPowerDataFilteringDropdown" );
271276 }
272277};
273278
@@ -286,11 +291,13 @@ public void bandPowerAutoCleanTimerDropdown(int n) {
286291public void bandPowerSmoothingDropdown (int n ) {
287292 globalFFTSettings. setSmoothingFactor(FFTSmoothingFactor . values()[n]);
288293 FFTSmoothingFactor smoothingFactor = globalFFTSettings. getSmoothingFactor();
294+ ((W_BandPower ) widgetManager. getWidget(" W_BandPower" )). setSmoothingDropdownFrontend(smoothingFactor);
289295 ((W_Fft ) widgetManager. getWidget(" W_Fft" )). setSmoothingDropdownFrontend(smoothingFactor);
290296}
291297
292298public void bandPowerDataFilteringDropdown (int n ) {
293299 globalFFTSettings. setFilteredEnum(FFTFilteredEnum . values()[n]);
294300 FFTFilteredEnum filteredEnum = globalFFTSettings. getFilteredEnum();
301+ ((W_BandPower ) widgetManager. getWidget(" W_BandPower" )). setFilteringDropdownFrontend(filteredEnum);
295302 ((W_Fft ) widgetManager. getWidget(" W_Fft" )). setFilteringDropdownFrontend(filteredEnum);
296303}
0 commit comments