JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / analysis / scoremodels / ScoreModels.java
index fd579dc..8700ec0 100644 (file)
@@ -22,10 +22,11 @@ package jalview.analysis.scoremodels;
 
 import jalview.api.AlignmentViewPanel;
 import jalview.api.analysis.ScoreModelI;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
 import jalview.io.DataSourceType;
 import jalview.io.FileParse;
 import jalview.io.ScoreMatrixFile;
-import jalview.util.Platform;
 
 import java.io.IOException;
 import java.util.LinkedHashMap;
@@ -34,16 +35,8 @@ import java.util.Map;
 /**
  * A class that can register and serve instances of ScoreModelI
  */
-public class ScoreModels
+public class ScoreModels implements ApplicationSingletonI
 {
-  private final ScoreMatrix BLOSUM62;
-
-  private final ScoreMatrix PAM250;
-
-  private final ScoreMatrix DNA;
-
-  private static ScoreModels instance;
-
   /**
    * Answers the singleton instance of this class, with lazy initialisation
    * (built-in score models are loaded on the first call to this method)
@@ -52,37 +45,9 @@ public class ScoreModels
    */
   public static ScoreModels getInstance()
   {
-    ScoreModels m = instance;
-    @SuppressWarnings("unused")
-    ThreadGroup g = null;
-    if (Platform.isJS())
-    {
-      g = Thread.currentThread().getThreadGroup();
-      /**
-       * @j2sNative m = g._jalviewScoreModelsInstance;
-       * 
-       */
-    }
-    if (m == null)
-    {
-      m = new ScoreModels();
-      if (Platform.isJS())
-      {
-        /**
-         * @j2sNative g._jalviewScoreModelsInstance = m;
-         * 
-         */
-      }
-      else
-      {
-        instance = m;
-      }
-    }
-    return m;
+    return (ScoreModels) ApplicationSingletonProvider.getInstance(ScoreModels.class);
   }
 
-  private Map<String, ScoreModelI> models;
-
   /**
    * Private constructor to enforce use of singleton. Registers Jalview's
    * "built-in" score models:
@@ -107,6 +72,14 @@ public class ScoreModels
     registerScoreModel(new FeatureDistanceModel());
   }
 
+  private final ScoreMatrix BLOSUM62;
+
+  private final ScoreMatrix PAM250;
+
+  private final ScoreMatrix DNA;
+
+  private Map<String, ScoreModelI> models;
+
   /**
    * Tries to load a score matrix from the given resource file, and if
    * successful, registers it.
@@ -176,7 +149,7 @@ public class ScoreModels
    */
   public void reset()
   {
-    instance = new ScoreModels();
+    ApplicationSingletonProvider.removeInstance(this.getClass());
   }
 
   /**