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;
*/
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++)
}
}
}
- 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)
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, ";");
}
}
UserColourScheme cs = new UserColourScheme(
"E,D=red; K,R,H=0022FF; c=10 , 20,30");
String param = cs.toAppletParameter();
- assertEquals("H,K,R=0022ff;c=0a141e;D,E=ff0000", param);
+ assertEquals("D,E=ff0000;H,K,R=0022ff;c=0a141e", param);
}
}