+ /**
+ * Answers the customised name of the colour scheme, if it has one, else "User
+ * Defined"
+ */
+ @Override
+ public String getSchemeName()
+ {
+ if (schemeName != null && schemeName.length() > 0)
+ {
+ return schemeName;
+ }
+ return ResidueColourScheme.USER_DEFINED;
+ }
+
+ /**
+ * Generate an applet colour parameter like A,C,D=12ffe9;Q,W=2393fd;w=9178dd
+ *
+ * @return
+ */
+ 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<>();
+
+ for (char symbol = 'A'; symbol <= 'Z'; symbol++)
+ {
+ String residue = String.valueOf(symbol);
+ int index = symbolIndex[symbol];
+ Color c = colors[index];
+ if (c != null && !c.equals(Color.white))
+ {
+ if (colours.get(c) == null)
+ {
+ colours.put(c, new ArrayList<String>());
+ }
+ colours.get(c).add(residue);
+ }
+ if (lowerCaseColours != null)
+ {
+ c = lowerCaseColours[index];
+ if (c != null && !c.equals(Color.white))
+ {
+ residue = residue.toLowerCase(Locale.ROOT);
+ if (colours.get(c) == null)
+ {
+ colours.put(c, new ArrayList<String>());
+ }
+ colours.get(c).add(residue);
+ }
+ }
+ }
+
+ /*
+ * step 2: make a list of { A,G,R=12f9d6 } residues/colour specs
+ */
+ List<String> residueColours = new ArrayList<>();
+ for (Entry<Color, List<String>> cols : colours.entrySet())
+ {
+ boolean first = true;
+ StringBuilder sb = new StringBuilder();
+ for (String residue : cols.getValue())
+ {
+ if (!first)
+ {
+ sb.append(",");
+ }
+ sb.append(residue);
+ first = false;
+ }
+ sb.append("=");
+ /*
+ * get color as hex value, dropping the alpha (ff) part
+ */
+ String hexString = Integer.toHexString(cols.getKey().getRGB())
+ .substring(2);
+ sb.append(hexString);
+ residueColours.add(sb.toString());
+ }
+
+ /*
+ * sort and output
+ */
+ Collections.sort(residueColours);
+ return StringUtils.listToDelimitedString(residueColours, ";");
+ }
+
+ @Override
+ public boolean hasGapColour()
+ {
+ return (findColour(' ') != null);
+ }