88 * it under the terms of the GNU General Public License as
99 * published by the Free Software Foundation, either version 3 of the
1010 * License, or (at your option) any later version.
11- *
11+ *
1212 * This program is distributed in the hope that it will be useful,
1313 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1414 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515 * GNU General Public License for more details.
16- *
16+ *
1717 * You should have received a copy of the GNU General Public
1818 * License along with this program. If not, see
1919 * <http://www.gnu.org/licenses/gpl-3.0.html>.
4848public class ParameterSweepModel
4949{
5050
51- private final transient Listeners .List < ModelListener > modelListeners ;
51+ private final transient Listeners .List < ModelListener > modelListeners = new Listeners . SynchronizedList <>() ;
5252
5353 private final Map < String , DetectorSweepModel > detectorModels ;
5454
@@ -62,8 +62,6 @@ public class ParameterSweepModel
6262
6363 public ParameterSweepModel ()
6464 {
65- modelListeners = new Listeners .SynchronizedList <>();
66-
6765 // Auto-detect detectors & trackers.
6866 detectorModels = autoDetect ( DetectorSweepModel .class );
6967 trackerModels = autoDetect ( TrackerSweepModel .class );
@@ -78,18 +76,34 @@ public ParameterSweepModel()
7876 this .spotFilterModels = new ArrayList <>();
7977 this .trackFilterModels = new ArrayList <>();
8078
81- registerListeners ();
82- }
83-
84- public void registerListeners ()
85- {
86- // Forward component changes to listeners.
79+ // Register models.
8780 detectorModels ().forEach ( model -> model .listeners ().add ( () -> notifyListeners () ) );
8881 trackerModels ().forEach ( model -> model .listeners ().add ( () -> notifyListeners () ) );
8982 spotFilterModels ().forEach ( model -> model .listeners ().add ( () -> notifyListeners () ) );
9083 trackFilterModels ().forEach ( model -> model .listeners ().add ( () -> notifyListeners () ) );
9184 }
9285
86+ /**
87+ * This is used <b>only</b> for deserizalisation, to re-register listeners
88+ * in the model components of the main models.
89+ */
90+ void reRegisterListeners ()
91+ {
92+ final ModelListener notifier = () -> notifyListeners ();
93+ reRegisterListeners ( detectorModels .values (), notifier );
94+ reRegisterListeners ( trackerModels .values (), notifier );
95+ reRegisterListeners ( spotFilterModels , notifier );
96+ reRegisterListeners ( spotFilterModels , notifier );
97+ }
98+
99+ private void reRegisterListeners ( final Collection < ? extends AbstractSweepModelBase > models , final ModelListener notifier )
100+ {
101+ models .forEach ( m -> {
102+ m .listeners ().add ( notifier );
103+ m .models .values ().forEach ( sm -> sm .listeners ().add ( notifier ) );
104+ } );
105+ }
106+
93107 public Collection < DetectorSweepModel > detectorModels ()
94108 {
95109 return detectorModels .values ();
@@ -179,7 +193,7 @@ public List< TrackerSweepModel > getActiveTracker()
179193 /**
180194 * Returns the count of the different settings that will be generated from
181195 * this model.
182- *
196+ *
183197 * @return the count of settings.
184198 */
185199 public int count ()
@@ -190,7 +204,7 @@ public int count()
190204 /**
191205 * Returns the count of the different tracker settings that will be
192206 * generated from this model.
193- *
207+ *
194208 * @return the count of settings.
195209 */
196210 public int countTrackerSettings ()
@@ -213,7 +227,7 @@ public int countTrackerSettings()
213227 /**
214228 * Returns the count of the different detector settings that will be
215229 * generated from this model.
216- *
230+ *
217231 * @return the count of settings.
218232 */
219233 public int countDetectorSettings ()
@@ -236,7 +250,7 @@ public int countDetectorSettings()
236250 /**
237251 * Returns the count of the different spot filter settings that will be
238252 * generated from this model.
239- *
253+ *
240254 * @return the count of settings.
241255 */
242256 public int countSpotFilterSettings ()
@@ -260,7 +274,7 @@ public int countSpotFilterSettings()
260274 /**
261275 * Returns the count of the different track filter settings that will be
262276 * generated from this model.
263- *
277+ *
264278 * @return the count of settings.
265279 */
266280 public int countTrackFilterSettings ()
0 commit comments