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;
}
@Override
- public ColourSchemeI applyTo(AnnotatedCollectionI sg,
+ public ColourSchemeI getInstance(AnnotatedCollectionI sg,
Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
- UserColourScheme usc = new UserColourScheme(colors);
- if (lowerCaseColours != null)
+ return new UserColourScheme(this);
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @return
+ */
+ protected UserColourScheme(UserColourScheme from)
+ {
+ this(from.colors);
+ schemeName = from.schemeName;
+ if (from.lowerCaseColours != null)
{
- usc.schemeName = schemeName;
- usc.lowerCaseColours = new Color[lowerCaseColours.length];
- System.arraycopy(lowerCaseColours, 0, usc.lowerCaseColours, 0,
- lowerCaseColours.length);
+ lowerCaseColours = new Color[from.lowerCaseColours.length];
+ System.arraycopy(from.lowerCaseColours, 0, lowerCaseColours, 0,
+ from.lowerCaseColours.length);
}
- return usc;
}
/**
{
lowerCaseColours = new Color[colors.length];
}
- lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour);
+ lowerCaseColours[colIndex] = ColorUtils
+ .parseColourString(colour);
}
else
{
}
} catch (Exception ex)
{
- System.out.println("Error parsing userDefinedColours:\n" + token
- + "\n" + ex);
+ System.out.println(
+ "Error parsing userDefinedColours:\n" + token + "\n" + ex);
}
}
- @Override
- public Color findColour(char c, int j, SequenceI seq)
- {
- Color currentColour;
- int index = ResidueProperties.aaIndex[c];
-
- if ((threshold == 0) || aboveThreshold(c, j))
- {
- if (lowerCaseColours != null && 'a' <= c && c <= 'z')
- {
- currentColour = lowerCaseColours[index];
- }
- else
- {
- currentColour = colors[index];
- }
- }
- else
- {
- currentColour = Color.white;
- }
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
-
- return currentColour;
- }
-
public void setLowerCaseColours(Color[] lcolours)
{
lowerCaseColours = lcolours;
}
/**
- * Answers the customised name of the colour scheme, if it has one, else
- * "User Defined"
+ * Answers the customised name of the colour scheme, if it has one, else "User
+ * Defined"
*/
@Override
public String getSchemeName()
{
return schemeName;
}
- return JalviewColourScheme.UserDefined.toString();
+ return ResidueColourScheme.USER_DEFINED;
}
/**
*/
public String toAppletParameter()
{
- Map<Color, List<String>> colours = new HashMap<Color, List<String>>();
+ /*
+ * 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++)
{
}
}
}
- StringBuilder sb = new StringBuilder();
+
+ /*
+ * 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())
{
- 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, ";");
+ }
+
+ @Override
+ public boolean hasGapColour()
+ {
+ return (findColour(' ') != null);
}
}