X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fschemes%2FUserColourScheme.java;h=7bf02c1364363b671c1240fe0afaaf79431d6921;hb=a09d6f5c16b0e222806e035cd38bfb4c4eb92c75;hp=1865518d45ce34ba1892e14c30e7b26e3c744e2e;hpb=320c96aed11f5c396a9efd9ea83b0e35f05e21e4;p=jalview.git diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java index 1865518..7bf02c1 100755 --- a/src/jalview/schemes/UserColourScheme.java +++ b/src/jalview/schemes/UserColourScheme.java @@ -26,11 +26,18 @@ import jalview.datamodel.SequenceI; import jalview.util.ColorUtils; import java.awt.Color; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.StringTokenizer; public class UserColourScheme extends ResidueColourScheme { + /* + * lookup (by symbol index) of lower case colours (if configured) + */ Color[] lowerCaseColours; protected String schemeName; @@ -53,7 +60,7 @@ public class UserColourScheme extends ResidueColourScheme UserColourScheme usc = new UserColourScheme(colors); if (lowerCaseColours != null) { - usc.schemeName = new String(schemeName); + usc.schemeName = schemeName; usc.lowerCaseColours = new Color[lowerCaseColours.length]; System.arraycopy(lowerCaseColours, 0, usc.lowerCaseColours, 0, lowerCaseColours.length); @@ -61,9 +68,30 @@ public class UserColourScheme extends ResidueColourScheme return usc; } + /** + * Constructor for an animino acid colour scheme. The colour specification may + * be one of + * + * + * @param colour + */ public UserColourScheme(String colour) { super(ResidueProperties.aaIndex); + + if (colour.contains("=")) + { + /* + * a list of colours per residue(s) + */ + parseAppletParameter(colour); + return; + } + Color col = ColorUtils.parseColourString(colour); if (col == null) @@ -72,12 +100,31 @@ public class UserColourScheme extends ResidueColourScheme col = ColorUtils.createColourFromName(colour); } - colors = new Color[24]; - for (int i = 0; i < 24; i++) + setAll(col); + schemeName = colour; + } + + /** + * Sets all symbols to the specified colour + * + * @param col + */ + protected void setAll(Color col) + { + if (symbolIndex == null) + { + return; + } + int max = 0; + for (int index : symbolIndex) + { + max = Math.max(max, index); + } + colors = new Color[max + 1]; + for (int i = 0; i <= max; i++) { colors[i] = col; } - schemeName = colour; } public Color[] getColours() @@ -115,10 +162,10 @@ public class UserColourScheme extends ResidueColourScheme * * @param paramValue */ - public void parseAppletParameter(String paramValue) + void parseAppletParameter(String paramValue) { - // TODO: need a function to generate appletParameter colour string from a - // UCS + setAll(Color.white); + StringTokenizer st = new StringTokenizer(paramValue, ";"); StringTokenizer st2; String token = null, colour, residues; @@ -145,9 +192,9 @@ public class UserColourScheme extends ResidueColourScheme { if (lowerCaseColours == null) { - lowerCaseColours = new Color[23]; + lowerCaseColours = new Color[colors.length]; } - for (int i = 0; i < 23; i++) + for (int i = 0; i < lowerCaseColours.length; i++) { if (lowerCaseColours[i] == null) { @@ -162,7 +209,7 @@ public class UserColourScheme extends ResidueColourScheme { if (lowerCaseColours == null) { - lowerCaseColours = new Color[23]; + lowerCaseColours = new Color[colors.length]; } lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour); } @@ -248,4 +295,68 @@ public class UserColourScheme extends ResidueColourScheme return JalviewColourScheme.UserDefined.toString(); } + /** + * Generate an applet colour parameter like A,C,D=12ffe9;Q,W=2393fd;w=9178dd + * + * @return + */ + public String toAppletParameter() + { + Map> 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()); + } + colours.get(c).add(residue); + } + if (lowerCaseColours != null) + { + c = lowerCaseColours[index]; + if (c != null && !c.equals(Color.white)) + { + residue = residue.toLowerCase(); + if (colours.get(c) == null) + { + colours.put(c, new ArrayList()); + } + colours.get(c).add(residue); + } + } + } + StringBuilder sb = new StringBuilder(); + for (Entry> cols : colours.entrySet()) + { + if (sb.length() > 0) + { + sb.append(";"); + } + boolean first = true; + 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); + } + + return sb.toString(); + } }