JAL-2360 ColourSchemes holds configured schemes, AlignFrame colour menu
[jalview.git] / src / jalview / schemes / UserColourScheme.java
index 7bf02c1..09cef92 100755 (executable)
@@ -24,9 +24,11 @@ import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceI;
 import jalview.util.ColorUtils;
+import jalview.util.StringUtils;
 
 import java.awt.Color;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -54,7 +56,7 @@ public class UserColourScheme extends ResidueColourScheme
   }
 
   @Override
-  public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+  public ColourSchemeI getInstance(AnnotatedCollectionI sg,
           Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
   {
     UserColourScheme usc = new UserColourScheme(colors);
@@ -292,7 +294,7 @@ public class UserColourScheme extends ResidueColourScheme
     {
       return schemeName;
     }
-    return JalviewColourScheme.UserDefined.toString();
+    return "User Defined";
   }
 
   /**
@@ -302,6 +304,9 @@ public class UserColourScheme extends ResidueColourScheme
    */
   public String toAppletParameter()
   {
+    /*
+     * step 1: build a map from colours to the symbol(s) that have the colour
+     */
     Map<Color, List<String>> colours = new HashMap<Color, List<String>>();
 
     for (char symbol = 'A'; symbol <= 'Z'; symbol++)
@@ -331,14 +336,15 @@ public class UserColourScheme extends ResidueColourScheme
         }
       }
     }
-    StringBuilder sb = new StringBuilder();
+
+    /*
+     * step 2: make a list of { A,G,R=12f9d6 } residues/colour specs
+     */
+    List<String> residueColours = new ArrayList<String>();
     for (Entry<Color, List<String>> cols : colours.entrySet())
     {
-      if (sb.length() > 0)
-      {
-        sb.append(";");
-      }
       boolean first = true;
+      StringBuilder sb = new StringBuilder();
       for (String residue : cols.getValue())
       {
         if (!first)
@@ -355,8 +361,13 @@ public class UserColourScheme extends ResidueColourScheme
       String hexString = Integer.toHexString(cols.getKey().getRGB())
               .substring(2);
       sb.append(hexString);
+      residueColours.add(sb.toString());
     }
 
-    return sb.toString();
+    /*
+     * sort and output
+     */
+    Collections.sort(residueColours);
+    return StringUtils.listToDelimitedString(residueColours, ";");
   }
 }