JAL-1750 View Mapping scoped to that viewer's mappings only
[jalview.git] / src / jalview / structure / StructureSelectionManager.java
index 156fc35..9702159 100644 (file)
@@ -53,6 +53,8 @@ import jalview.util.MessageManager;
 
 public class StructureSelectionManager
 {
+  public final static String NEWLINE = System.lineSeparator();
+
   static IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> instances;
 
   private List<StructureMapping> mappings = new ArrayList<StructureMapping>();
@@ -495,7 +497,7 @@ public class StructureSelectionManager
 
       do
       {
-        Atom tmp = (Atom) maxChain.atoms.elementAt(index);
+        Atom tmp = maxChain.atoms.elementAt(index);
         if (resNum != tmp.resNumber && tmp.alignmentMapping != -1)
         {
           resNum = tmp.resNumber;
@@ -853,16 +855,34 @@ public class StructureSelectionManager
     return tmp.toArray(new StructureMapping[tmp.size()]);
   }
 
-  public String printMapping(String pdbfile)
+  /**
+   * Returns a readable description of all mappings for the given pdbfile to any
+   * of the given sequences
+   * 
+   * @param pdbfile
+   * @param seqs
+   * @return
+   */
+  public String printMappings(String pdbfile, List<SequenceI> seqs)
   {
+    if (pdbfile == null || seqs == null || seqs.isEmpty())
+    {
+      return "";
+    }
+
     StringBuilder sb = new StringBuilder(64);
     for (StructureMapping sm : mappings)
     {
-      if (sm.pdbfile.equals(pdbfile))
+      if (sm.pdbfile.equals(pdbfile) && seqs.contains(sm.sequence))
       {
         sb.append(sm.mappingDetails);
+        sb.append(NEWLINE);
+        // separator makes it easier to read multiple mappings
+        sb.append("=====================");
+        sb.append(NEWLINE);
       }
     }
+    sb.append(NEWLINE);
 
     return sb.toString();
   }