/*\r
* Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
*\r
* This program is free software; you can redistribute it and/or\r
* modify it under the terms of the GNU General Public License\r
package jalview.schemes;\r
\r
import java.awt.*;\r
+import java.util.StringTokenizer;\r
\r
public class UserColourScheme\r
extends ResidueColourScheme\r
{\r
+ Color [] lowerCaseColours;\r
+\r
protected String schemeName;\r
\r
- public UserColourScheme(String colour)\r
+ public UserColourScheme()\r
+ { }\r
+\r
+ public UserColourScheme(Color[] newColors)\r
{\r
- Color col = null;\r
- try{\r
- int value = Integer.parseInt(colour, 16);\r
- col = new Color(value);\r
- }\r
- catch(NumberFormatException ex){}\r
+ colors = newColors;\r
+ }\r
\r
- if(col==null)\r
- col = ColourSchemeProperty.getAWTColorFromName(colour);\r
+ public UserColourScheme(String colour)\r
+ {\r
+ Color col = getColourFromString(colour);\r
\r
if(col==null)\r
{\r
System.out.println("Unknown colour!! "+colour);\r
+ col = createColourFromName(colour);\r
}\r
\r
colors = new Color[24];\r
colors[i] = col;\r
}\r
\r
- public UserColourScheme(Color[] newColors)\r
+ public Color[] getColours()\r
{\r
- colors = newColors;\r
+ return colors;\r
}\r
\r
- public Color[] getColours()\r
+ public Color[] getLowerCaseColours()\r
{\r
- return colors;\r
+ return lowerCaseColours;\r
}\r
\r
public void setName(String name)\r
{\r
schemeName = name;\r
}\r
+\r
public String getName()\r
{\r
return schemeName;\r
}\r
+\r
+ public Color getColourFromString(String colour)\r
+ {\r
+ colour = colour.trim();\r
+\r
+ Color col = null;\r
+ try\r
+ {\r
+ int value = Integer.parseInt(colour, 16);\r
+ col = new Color(value);\r
+ }\r
+ catch (NumberFormatException ex)\r
+ {}\r
+\r
+ if (col == null)\r
+ col = ColourSchemeProperty.getAWTColorFromName(colour);\r
+\r
+ if (col == null)\r
+ {\r
+ try\r
+ {\r
+ java.util.StringTokenizer st = new java.util.StringTokenizer(colour,\r
+ ",");\r
+ int r = Integer.parseInt(st.nextToken());\r
+ int g = Integer.parseInt(st.nextToken());\r
+ int b = Integer.parseInt(st.nextToken());\r
+ col = new Color(r, g, b);\r
+ }\r
+ catch (Exception ex)\r
+ {}\r
+ }\r
+\r
+ return col;\r
+\r
+ }\r
+\r
+ public Color createColourFromName(String name)\r
+ {\r
+ int r, g, b;\r
+\r
+ int lsize = name.length();\r
+ int start = 0, end = lsize / 3;\r
+\r
+ int rgbOffset = Math.abs(name.hashCode() % 10) * 15;\r
+\r
+ r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;\r
+ start = end;\r
+ end += lsize / 3;\r
+ if (end > lsize)\r
+ end = lsize;\r
+\r
+ g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;\r
+\r
+ b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;\r
+\r
+ Color color = new Color(r, g, b);\r
+\r
+ return color;\r
+ }\r
+\r
+ public void parseAppletParameter(String paramValue)\r
+ {\r
+ StringTokenizer st = new StringTokenizer(paramValue, ";");\r
+ StringTokenizer st2;\r
+ String token=null, colour, residues;\r
+ try{\r
+ while (st.hasMoreElements())\r
+ {\r
+ token = st.nextToken().trim();\r
+ residues = token.substring(0, token.indexOf("="));\r
+ colour = token.substring(token.indexOf("=") + 1);\r
+\r
+ st2 = new StringTokenizer(residues, " ,");\r
+ while (st2.hasMoreTokens())\r
+ {\r
+ token = st2.nextToken();\r
+\r
+ if (ResidueProperties.aaIndex[token.charAt(0)]==-1)\r
+ continue;\r
+\r
+ int colIndex = ResidueProperties.aaIndex[token.charAt(0)];\r
+\r
+ //AW - LOWER CASE DISABLED IN 2.1.01 bug fix release\r
+\r
+ if(token.equalsIgnoreCase("lowerCase"))\r
+ {\r
+ if (lowerCaseColours == null)\r
+ lowerCaseColours = new Color[23];\r
+ for (int i = 0; i < 23; i++)\r
+ if (lowerCaseColours[i] == null)\r
+ lowerCaseColours[i] = getColourFromString(colour);\r
+\r
+ continue;\r
+ }\r
+\r
+ if(token.equals(token.toLowerCase()))\r
+ {\r
+ if(lowerCaseColours==null)\r
+ {\r
+ lowerCaseColours = new Color[23];\r
+ }\r
+ lowerCaseColours[colIndex] = getColourFromString(colour);\r
+ }\r
+ else\r
+ colors[colIndex] = getColourFromString(colour);\r
+ }\r
+ }\r
+ }\r
+ catch(Exception ex)\r
+ {\r
+ System.out.println("Error parsing userDefinedColours:\n"\r
+ +token+"\n"+ex);\r
+ }\r
+\r
+ }\r
+\r
+\r
+\r
+ public Color findColour(String s, int j)\r
+ {\r
+ int index = ResidueProperties.aaIndex[s.charAt(0)];\r
+\r
+ if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))\r
+ {\r
+ //AW - LOWER CASE DISABLED IN 2.1.01 bug fix release\r
+ if(lowerCaseColours!=null && 'a' <= s.charAt(0) && s.charAt(0) <= 'z')\r
+ currentColour = lowerCaseColours[index];\r
+ else\r
+ currentColour = colors[index];\r
+ }\r
+ else\r
+ {\r
+ currentColour = Color.white;\r
+ }\r
+\r
+ if(conservationColouring)\r
+ applyConservation(j);\r
+\r
+\r
+ return currentColour;\r
+ }\r
+\r
+ public void setLowerCaseColours(Color [] lcolours)\r
+ {\r
+ lowerCaseColours = lcolours;\r
+ }\r
+\r
}\r