JAL-3253 jalview.bin.Instance streamlining
[jalview.git] / src / jalview / structure / StructureSelectionManager.java
index f0665de..e890dce 100644 (file)
@@ -64,6 +64,50 @@ import mc_view.PDBfile;
 public class StructureSelectionManager
 {
 
+  public static StructureSelectionManager getStructureSelectionManager(
+          StructureSelectionManagerProvider context)
+  {
+    IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> map = Instance
+            .getInstance().structureSelections;
+
+    if (map == null)
+    {
+      map = Instance
+              .getInstance().structureSelections = new IdentityHashMap<>();
+    }
+    StructureSelectionManager instance = map.get(context);
+    if (instance == null)
+    {
+      // BH: actually, not possible except for coding error; this is an attempt
+      // to discover that.
+      if (context == null && !map.isEmpty())
+      {
+        throw new Error(MessageManager.getString(
+                "error.implementation_error_structure_selection_manager_null"),
+                new NullPointerException(MessageManager
+                        .getString("exception.ssm_context_is_null")));
+      }
+      map.put(context, instance = new StructureSelectionManager());
+    }
+    return instance;
+  }
+
+  /**
+   * release all references associated with this manager provider
+   * 
+   * @param provider
+   */
+
+  public static void release(StructureSelectionManagerProvider provider)
+  {
+    IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> map = Instance
+            .getInstance().structureSelections;
+    if (map != null)
+    {
+      map.remove(provider);
+    }
+  }
+
   public StructureSelectionManager()
   {
   }
@@ -271,6 +315,8 @@ public class StructureSelectionManager
    * Import structure data and register a structure mapping for broadcasting
    * colouring, mouseovers and selection events (convenience wrapper).
    * 
+   * This is the standard entry point.
+   * 
    * @param sequence
    *          - one or more sequences to be mapped to pdbFile
    * @param targetChains
@@ -295,8 +341,11 @@ public class StructureSelectionManager
    * broadcasting colouring, mouseovers and selection events (convenience
    * wrapper).
    * 
+   * 
+   * 
    * @param forStructureView
-   *          when true, record the mapping for use in mouseOvers
+   *          when true (testng only), record the mapping for use in mouseOvers
+   *          (testng only)
    * @param sequence
    *          - one or more sequences to be mapped to pdbFile
    * @param targetChains
@@ -340,7 +389,7 @@ public class StructureSelectionManager
    *          mapping operation
    * @return null or the structure data parsed as a pdb file
    */
-  synchronized public StructureFile computeMapping(
+  synchronized private StructureFile computeMapping(
           boolean forStructureView, SequenceI[] sequenceArray,
           String[] targetChainIds, String pdbFile, DataSourceType sourceType,
           IProgressIndicator progress)
@@ -1196,43 +1245,22 @@ public class StructureSelectionManager
   }
 
   /**
-   * Resets this object to its initial state by removing all registered
-   * listeners, codon mappings, PDB file mappings
+   * Reset this object to its initial state by removing all registered
+   * listeners, codon mappings, PDB file mappings.
+   * 
+   * Called only by Desktop and testng.
+   * 
    */
   public void resetAll()
   {
-    if (mappings != null)
-    {
-      mappings.clear();
-    }
-    if (seqmappings != null)
-    {
-      seqmappings.clear();
-    }
-    if (sel_listeners != null)
-    {
-      sel_listeners.clear();
-    }
-    if (listeners != null)
-    {
-      listeners.clear();
-    }
-    if (commandListeners != null)
-    {
-      commandListeners.clear();
-    }
-    if (view_listeners != null)
-    {
-      view_listeners.clear();
-    }
-    if (pdbFileNameId != null)
-    {
-      pdbFileNameId.clear();
-    }
-    if (pdbIdFileName != null)
-    {
-      pdbIdFileName.clear();
-    }
+    mappings.clear();
+    seqmappings.clear();
+    sel_listeners.clear();
+    listeners.clear();
+    commandListeners.clear();
+    view_listeners.clear();
+    pdbFileNameId.clear();
+    pdbIdFileName.clear();
   }
 
   public void addSelectionListener(SelectionListener selecter)
@@ -1366,49 +1394,4 @@ public class StructureSelectionManager
     return seqmappings;
   }
 
-  public static StructureSelectionManager getStructureSelectionManager(
-          StructureSelectionManagerProvider context)
-  {
-    IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> map = Instance
-            .getInstance().structureSelections;
-
-    if (map == null)
-    {
-      map = Instance
-              .getInstance().structureSelections = new IdentityHashMap<>();
-    }
-    StructureSelectionManager instance = map.get(context);
-    if (instance == null)
-    {
-      // BH: actually, not possible except for coding error; this is an attempt
-      // to discover that.
-      if (context == null && !map.isEmpty())
-      {
-        throw new Error(MessageManager.getString(
-                "error.implementation_error_structure_selection_manager_null"),
-                new NullPointerException(MessageManager
-                        .getString("exception.ssm_context_is_null")));
-      }
-      map.put(context,
-              instance = new StructureSelectionManager());
-    }
-    return instance;
-  }
-
-  /**
-   * release all references associated with this manager provider
-   * 
-   * @param provider
-   */
-
-  public static void release(StructureSelectionManagerProvider provider)
-  {
-    IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> map = Instance
-            .getInstance().structureSelections;
-    if (map != null)
-    {
-      map.remove(provider);
-    }
-  }
-
 }