X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FUserColourScheme.java;h=ec0f008a12e8e15a07986362e317e7167a92f60b;hb=cd669a0e8c7b91b379bca8fe6e702cf0fcbd1ce0;hp=7bf02c1364363b671c1240fe0afaaf79431d6921;hpb=a09d6f5c16b0e222806e035cd38bfb4c4eb92c75;p=jalview.git diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index 7bf02c1..ec0f008 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -20,13 +20,16 @@ */ package jalview.schemes; +import java.util.Locale; + +import jalview.api.AlignViewportI; 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,18 +57,27 @@ public class UserColourScheme extends ResidueColourScheme } @Override - public ColourSchemeI applyTo(AnnotatedCollectionI sg, - Map hiddenRepSequences) + public ColourSchemeI getInstance(AlignViewportI view, + AnnotatedCollectionI sg) + { + return new UserColourScheme(this); + } + + /** + * Copy constructor + * + * @return + */ + protected UserColourScheme(UserColourScheme from) { - UserColourScheme usc = new UserColourScheme(colors); - if (lowerCaseColours != null) + 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; } /** @@ -96,7 +108,7 @@ public class UserColourScheme extends ResidueColourScheme if (col == null) { - System.out.println("Making colour from name: " + colour); + jalview.bin.Console.outPrintln("Making colour from name: " + colour); col = ColorUtils.createColourFromName(colour); } @@ -205,13 +217,14 @@ public class UserColourScheme extends ResidueColourScheme continue; } - if (residue.equals(residue.toLowerCase())) + if (residue.equals(residue.toLowerCase(Locale.ROOT))) { if (lowerCaseColours == null) { lowerCaseColours = new Color[colors.length]; } - lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour); + lowerCaseColours[colIndex] = ColorUtils + .parseColourString(colour); } else { @@ -221,40 +234,10 @@ public class UserColourScheme extends ResidueColourScheme } } catch (Exception 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); + jalview.bin.Console.outPrintln( + "Error parsing userDefinedColours:\n" + token + "\n" + ex); } - return currentColour; } public void setLowerCaseColours(Color[] lcolours) @@ -282,8 +265,8 @@ public class UserColourScheme extends ResidueColourScheme } /** - * 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() @@ -292,7 +275,7 @@ public class UserColourScheme extends ResidueColourScheme { return schemeName; } - return JalviewColourScheme.UserDefined.toString(); + return ResidueColourScheme.USER_DEFINED; } /** @@ -302,7 +285,10 @@ public class UserColourScheme extends ResidueColourScheme */ public String toAppletParameter() { - Map> colours = new HashMap>(); + /* + * step 1: build a map from colours to the symbol(s) that have the colour + */ + Map> colours = new HashMap<>(); for (char symbol = 'A'; symbol <= 'Z'; symbol++) { @@ -322,7 +308,7 @@ public class UserColourScheme extends ResidueColourScheme c = lowerCaseColours[index]; if (c != null && !c.equals(Color.white)) { - residue = residue.toLowerCase(); + residue = residue.toLowerCase(Locale.ROOT); if (colours.get(c) == null) { colours.put(c, new ArrayList()); @@ -331,14 +317,15 @@ public class UserColourScheme extends ResidueColourScheme } } } - StringBuilder sb = new StringBuilder(); + + /* + * step 2: make a list of { A,G,R=12f9d6 } residues/colour specs + */ + List residueColours = new ArrayList<>(); for (Entry> 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 +342,19 @@ 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, ";"); + } + + @Override + public boolean hasGapColour() + { + return (findColour(' ') != null); } }