X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fschemes%2FUserColourScheme.java;h=d77f2f53d4d663e1e0ead2b883960d688f4dea72;hb=72943d968f678ca4e34f1b701823d6dab51ff3a2;hp=9d61279ffdf679deb1643f7b6f2c9ad6b0aa8aa7;hpb=3d941a02a998676a12f8ff43fa98d9e1f4c27142;p=jalview.git
diff --git a/src/jalview/schemes/UserColourScheme.java b/src/jalview/schemes/UserColourScheme.java
index 9d61279..d77f2f5 100755
--- a/src/jalview/schemes/UserColourScheme.java
+++ b/src/jalview/schemes/UserColourScheme.java
@@ -1,218 +1,358 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
- */
-package jalview.schemes;
-
-import java.awt.*;
-import java.util.StringTokenizer;
-
-public class UserColourScheme
- extends ResidueColourScheme
-{
- Color [] lowerCaseColours;
-
- protected String schemeName;
-
- public UserColourScheme()
- { }
-
- public UserColourScheme(Color[] newColors)
- {
- colors = newColors;
- }
-
- public UserColourScheme(String colour)
- {
- Color col = getColourFromString(colour);
-
- if(col==null)
- {
- System.out.println("Unknown colour!! "+colour);
- col = createColourFromName(colour);
- }
-
- colors = new Color[24];
- for(int i=0; i<24; i++)
- colors[i] = col;
- }
-
- public Color[] getColours()
- {
- return colors;
- }
-
- public Color[] getLowerCaseColours()
- {
- return lowerCaseColours;
- }
-
- public void setName(String name)
- {
- schemeName = name;
- }
-
- public String getName()
- {
- return schemeName;
- }
-
- public Color getColourFromString(String colour)
- {
- colour = colour.trim();
-
- Color col = null;
- try
- {
- int value = Integer.parseInt(colour, 16);
- col = new Color(value);
- }
- catch (NumberFormatException ex)
- {}
-
- if (col == null)
- col = ColourSchemeProperty.getAWTColorFromName(colour);
-
- if (col == null)
- {
- try
- {
- java.util.StringTokenizer st = new java.util.StringTokenizer(colour,
- ",");
- int r = Integer.parseInt(st.nextToken());
- int g = Integer.parseInt(st.nextToken());
- int b = Integer.parseInt(st.nextToken());
- col = new Color(r, g, b);
- }
- catch (Exception ex)
- {}
- }
-
- return col;
-
- }
-
- public Color createColourFromName(String name)
- {
- int r, g, b;
-
- int lsize = name.length();
- int start = 0, end = lsize / 3;
-
- int rgbOffset = Math.abs(name.hashCode() % 10) * 15;
-
- r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
- start = end;
- end += lsize / 3;
- if (end > lsize)
- end = lsize;
-
- g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
-
- b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
-
- Color color = new Color(r, g, b);
-
- return color;
- }
-
- public void parseAppletParameter(String paramValue)
- {
- StringTokenizer st = new StringTokenizer(paramValue, ";");
- StringTokenizer st2;
- String token=null, colour, residues;
- try{
- while (st.hasMoreElements())
- {
- token = st.nextToken().trim();
- residues = token.substring(0, token.indexOf("="));
- colour = token.substring(token.indexOf("=") + 1);
-
- st2 = new StringTokenizer(residues, " ,");
- while (st2.hasMoreTokens())
- {
- token = st2.nextToken();
-
- if (ResidueProperties.aaIndex[token.charAt(0)]==-1)
- continue;
-
- int colIndex = ResidueProperties.aaIndex[token.charAt(0)];
-
- if(token.equalsIgnoreCase("lowerCase"))
- {
- if (lowerCaseColours == null)
- lowerCaseColours = new Color[23];
- for (int i = 0; i < 23; i++)
- if (lowerCaseColours[i] == null)
- lowerCaseColours[i] = getColourFromString(colour);
-
- continue;
- }
-
- if(token.equals(token.toLowerCase()))
- {
- if(lowerCaseColours==null)
- {
- lowerCaseColours = new Color[23];
- }
- lowerCaseColours[colIndex] = getColourFromString(colour);
- }
- else
- colors[colIndex] = getColourFromString(colour);
- }
- }
- }
- catch(Exception ex)
- {
- System.out.println("Error parsing userDefinedColours:\n"
- +token+"\n"+ex);
- }
-
- }
-
-
-
- public Color findColour(String s, int j)
- {
- Color currentColour;
- int index = ResidueProperties.aaIndex[s.charAt(0)];
-
- if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))
- {
- if(lowerCaseColours!=null && 'a' <= s.charAt(0) && s.charAt(0) <= 'z')
- currentColour = lowerCaseColours[index];
- else
- currentColour = colors[index];
- }
- else
- {
- currentColour = Color.white;
- }
-
- if(conservationColouring)
- applyConservation(currentColour, j);
-
-
- return currentColour;
- }
-
- public void setLowerCaseColours(Color [] lcolours)
- {
- lowerCaseColours = lcolours;
- }
-
-}
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see
+ * D,E=red; K,R,H=0022FF; c=100,50,75 + *+ * + * This should be a semi-colon separated list of colours, which may be defined + * by colour name, hex value or comma-separated RGB triple. Each colour is + * defined for a comma-separated list of amino acid single letter codes. (Note + * that this also allows a colour scheme to be defined for ACGT, but not for + * U.) + * + * @param paramValue + */ + void parseAppletParameter(String paramValue) + { + setAll(Color.white); + + StringTokenizer st = new StringTokenizer(paramValue, ";"); + StringTokenizer st2; + String token = null, colour, residues; + try + { + while (st.hasMoreElements()) + { + token = st.nextToken().trim(); + residues = token.substring(0, token.indexOf("=")); + colour = token.substring(token.indexOf("=") + 1); + + st2 = new StringTokenizer(residues, " ,"); + while (st2.hasMoreTokens()) + { + String residue = st2.nextToken(); + + int colIndex = ResidueProperties.aaIndex[residue.charAt(0)]; + if (colIndex == -1) + { + continue; + } + + if (residue.equalsIgnoreCase("lowerCase")) + { + if (lowerCaseColours == null) + { + lowerCaseColours = new Color[colors.length]; + } + for (int i = 0; i < lowerCaseColours.length; i++) + { + if (lowerCaseColours[i] == null) + { + lowerCaseColours[i] = ColorUtils.parseColourString(colour); + } + } + + continue; + } + + if (residue.equals(residue.toLowerCase())) + { + if (lowerCaseColours == null) + { + lowerCaseColours = new Color[colors.length]; + } + lowerCaseColours[colIndex] = ColorUtils + .parseColourString(colour); + } + else + { + colors[colIndex] = ColorUtils.parseColourString(colour); + } + } + } + } catch (Exception ex) + { + System.out.println( + "Error parsing userDefinedColours:\n" + token + "\n" + ex); + } + + } + + public void setLowerCaseColours(Color[] lcolours) + { + lowerCaseColours = lcolours; + } + + /** + * Returns the colour for the given residue character. If the residue is + * lower-case, and there is a specific colour defined for lower case, that + * colour is returned, else the colour for the upper case residue. + */ + @Override + public Color findColour(char c) + { + if ('a' <= c && c <= 'z' && lowerCaseColours != null) + { + Color colour = lowerCaseColours[symbolIndex[c]]; + if (colour != null) + { + return colour; + } + } + return super.findColour(c); + } + + /** + * 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