Merge remote-tracking branch 'remotes/origin/2_5_1_rna_merge' into develop (JAL-826)
[jalview.git] / src / jalview / structure / StructureSelectionManager.java
index d1bccd8..e1aa9dc 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * 
@@ -152,16 +152,32 @@ public class StructureSelectionManager
       ex.printStackTrace();
       return null;
     }
-
+    
     String targetChain;
     for (int s = 0; s < sequence.length; s++)
     {
+      boolean infChain = true;
       if (targetChains != null && targetChains[s] != null)
+      {
+        infChain = false;
         targetChain = targetChains[s];
+      }
       else if (sequence[s].getName().indexOf("|") > -1)
       {
         targetChain = sequence[s].getName().substring(
                 sequence[s].getName().lastIndexOf("|") + 1);
+        if (targetChain.length() > 1)
+        {
+          if (targetChain.trim().length() == 0)
+          {
+            targetChain = " ";
+          }
+          else
+          {
+            // not a valid chain identifier
+            targetChain = "";
+          }
+        }
       }
       else
         targetChain = "";
@@ -173,14 +189,11 @@ public class StructureSelectionManager
       boolean first = true;
       for (int i = 0; i < pdb.chains.size(); i++)
       {
-        // TODO: re http://issues.jalview.org/browse/JAL-583 : this patch may
-        // need to be revoked
         PDBChain chain = ((PDBChain) pdb.chains.elementAt(i));
-        if (targetChain.length() > 0 && !targetChain.equals(chain.id))
+        if (targetChain.length() > 0 && !targetChain.equals(chain.id) && !infChain)
         {
           continue; // don't try to map chains don't match.
         }
-        // end of patch for limiting computed mappings
         // TODO: correctly determine sequence type for mixed na/peptide
         // structures
         AlignSeq as = new AlignSeq(sequence[s],
@@ -336,6 +349,11 @@ public class StructureSelectionManager
 
   public void mouseOverStructure(int pdbResNum, String chain, String pdbfile)
   {
+    if (listeners==null)
+    {
+      // old or prematurely sent event
+      return;
+    }
     boolean hasSequenceListeners = handlingVamsasMo || seqmappings != null;
     SearchResults results = null;
     SequenceI lastseq = null;
@@ -491,6 +509,9 @@ public class StructureSelectionManager
           ((VamsasListener) listeners.elementAt(i)).mouseOver(seq,
                   indexpos, source);
         }
+        else if(listeners.elementAt(i) instanceof SecondaryStructureListener){
+               ((SecondaryStructureListener) listeners.elementAt(i)).mouseOverSequence(seq,indexpos);
+        }
       }
     }
   }
@@ -771,13 +792,24 @@ public class StructureSelectionManager
    */
   public static void release(StructureSelectionManagerProvider jalviewLite)
   {
-    StructureSelectionManager mnger=(instances.get(jalviewLite));
-    if (mnger!=null)
+//    synchronized (instances)
     {
-      instances.remove(jalviewLite);
-      try {
-        mnger.finalize();
-      } catch (Throwable x){};
+      if (instances == null)
+      {
+        return;
+      }
+      StructureSelectionManager mnger = (instances.get(jalviewLite));
+      if (mnger != null)
+      {
+        instances.remove(jalviewLite);
+        try
+        {
+          mnger.finalize();
+        } catch (Throwable x)
+        {
+        }
+        ;
+      }
     }
   }