JAL-3551 concatenate colour by sequence commands for all except PyMOL
[jalview.git] / src / jalview / structure / StructureCommandsBase.java
index 8c6ea4e..e688b64 100644 (file)
@@ -1,14 +1,14 @@
 package jalview.structure;
 
-import jalview.api.AlignmentViewPanel;
-import jalview.datamodel.SequenceI;
-
 import java.awt.Color;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import jalview.api.AlignmentViewPanel;
+import jalview.datamodel.SequenceI;
+
 /**
  * A base class holding methods useful to all classes that implement commands
  * for structure viewers
@@ -87,6 +87,9 @@ public abstract class StructureCommandsBase implements StructureCommandsI
    * Traverse the map of colours/models/chains/positions to construct a list of
    * 'color' commands (one per distinct colour used). The format of each command
    * is specific to the structure viewer.
+   * <p>
+   * The default implementation returns a single command containing one command
+   * per colour, concatenated.
    * 
    * @param colourMap
    * @return
@@ -95,18 +98,23 @@ public abstract class StructureCommandsBase implements StructureCommandsI
   public List<StructureCommandI> colourBySequence(
           Map<Object, AtomSpecModel> colourMap)
   {
-    /*
-     * default implementation creates one command per colour;
-     * override to concatenate colour commands if wanted
-     */
     List<StructureCommandI> commands = new ArrayList<>();
+    StringBuilder sb = new StringBuilder(colourMap.size() * 20);
+    boolean first = true;
     for (Object key : colourMap.keySet())
     {
       Color colour = (Color) key;
       final AtomSpecModel colourData = colourMap.get(colour);
-      commands.add(getColourCommand(colourData, colour));
+      StructureCommandI command = getColourCommand(colourData, colour);
+      if (!first)
+      {
+        sb.append(getCommandSeparator());
+      }
+      first = false;
+      sb.append(command.getCommand());
     }
 
+    commands.add(new StructureCommand(sb.toString()));
     return commands;
   }