JAL-3762 syntax error typo
[jalview.git] / src / jalview / ext / jmol / JmolCommands.java
index 6bf7010..603202a 100644 (file)
@@ -68,7 +68,7 @@ public class JmolCommands
     for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
     {
       StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
-      StringBuffer command = new StringBuffer();
+      StringBuilder command = new StringBuilder();
       StructureMappingcommandSet smc;
       ArrayList<String> str = new ArrayList<String>();
 
@@ -77,7 +77,6 @@ public class JmolCommands
         continue;
       }
 
-      int lastPos = -1;
       for (int s = 0; s < sequence[pdbfnum].length; s++)
       {
         for (int sp, m = 0; m < mapping.length; m++)
@@ -85,6 +84,7 @@ public class JmolCommands
           if (mapping[m].getSequence() == sequence[pdbfnum][s]
                   && (sp = al.findIndex(sequence[pdbfnum][s])) > -1)
           {
+            int lastPos = StructureMapping.UNASSIGNED_VALUE;
             SequenceI asp = al.getSequenceAt(sp);
             for (int r = 0; r < asp.getLength(); r++)
             {
@@ -95,10 +95,22 @@ public class JmolCommands
               }
               int pos = mapping[m].getPDBResNum(asp.findPosition(r));
 
-              if (pos < 1 || pos == lastPos)
+              if (pos == lastPos)
               {
                 continue;
               }
+              if (pos == StructureMapping.UNASSIGNED_VALUE)
+              {
+                // terminate current colour op
+                if (command.length() > 0
+                        && command.charAt(command.length() - 1) != ';')
+                {
+                  command.append(";");
+                }
+                // reset lastPos
+                lastPos = StructureMapping.UNASSIGNED_VALUE;
+                continue;
+              }
 
               lastPos = pos;
 
@@ -113,9 +125,12 @@ public class JmolCommands
                 col = Color.GRAY;
               }
 
-              String newSelcom = (mapping[m].getChain() != " "
+              // todo JAL-3152 handle 'no chain' case without errors
+              boolean hasChain = true || mapping[m].getChain() != " ";
+                         String chainSpec = hasChain
                       ? ":" + mapping[m].getChain()
-                      : "") + "/" + (pdbfnum + 1) + ".1" + ";color["
+                      : "";
+                         String newSelcom = chainSpec + "/" + (pdbfnum + 1) + ".1" + ";color["
                       + col.getRed() + "," + col.getGreen() + ","
                       + col.getBlue() + "]";
               if (command.length() > newSelcom.length() && command
@@ -128,7 +143,12 @@ public class JmolCommands
               // TODO: deal with case when buffer is too large for Jmol to parse
               // - execute command and flush
 
-              command.append(";");
+              if (command.length() > 0
+                      && command.charAt(command.length() - 1) != ';')
+              {
+                command.append(";");
+              }
+
               if (command.length() > 51200)
               {
                 // add another chunk
@@ -155,7 +175,7 @@ public class JmolCommands
     return cset.toArray(new StructureMappingcommandSet[cset.size()]);
   }
 
-  public static StringBuffer condenseCommand(StringBuffer command, int pos)
+  public static StringBuilder condenseCommand(StringBuilder command, int pos)
   {
 
     // work back to last 'select'
@@ -170,7 +190,7 @@ public class JmolCommands
       ;
     } while ((q = command.indexOf("select", p)) == -1 && p > 0);
 
-    StringBuffer sb = new StringBuffer(command.substring(0, q + 7));
+    StringBuilder sb = new StringBuilder(command.substring(0, q + 7));
 
     command = command.delete(0, q + 7);