2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.schemes;
22 import java.util.StringTokenizer;
24 public class UserColourScheme
25 extends ResidueColourScheme
27 Color [] lowerCaseColours;
29 protected String schemeName;
31 public UserColourScheme()
34 public UserColourScheme(Color[] newColors)
39 public UserColourScheme(String colour)
41 Color col = getColourFromString(colour);
45 System.out.println("Unknown colour!! "+colour);
46 col = createColourFromName(colour);
49 colors = new Color[24];
50 for(int i=0; i<24; i++)
54 public Color[] getColours()
59 public Color[] getLowerCaseColours()
61 return lowerCaseColours;
64 public void setName(String name)
69 public String getName()
74 public Color getColourFromString(String colour)
76 colour = colour.trim();
81 int value = Integer.parseInt(colour, 16);
82 col = new Color(value);
84 catch (NumberFormatException ex)
88 col = ColourSchemeProperty.getAWTColorFromName(colour);
94 java.util.StringTokenizer st = new java.util.StringTokenizer(colour,
96 int r = Integer.parseInt(st.nextToken());
97 int g = Integer.parseInt(st.nextToken());
98 int b = Integer.parseInt(st.nextToken());
99 col = new Color(r, g, b);
109 public Color createColourFromName(String name)
113 int lsize = name.length();
114 int start = 0, end = lsize / 3;
116 int rgbOffset = Math.abs(name.hashCode() % 10) * 15;
118 r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
124 g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
126 b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
128 Color color = new Color(r, g, b);
133 public void parseAppletParameter(String paramValue)
135 StringTokenizer st = new StringTokenizer(paramValue, ";");
137 String token=null, colour, residues, residue;
139 while (st.hasMoreElements())
141 token = st.nextToken().trim();
142 residues = token.substring(0, token.indexOf("="));
143 colour = token.substring(token.indexOf("=") + 1);
145 st2 = new StringTokenizer(residues, " ,");
146 while (st2.hasMoreTokens())
148 token = st2.nextToken();
149 if(token.equalsIgnoreCase("lowerCase"))
151 if (lowerCaseColours == null)
152 lowerCaseColours = new Color[23];
153 for (int i = 0; i < 23; i++)
154 if (lowerCaseColours[i] == null)
155 lowerCaseColours[i] = getColourFromString(colour);
161 ( (Integer) ResidueProperties.aaHash.
162 get(token)).intValue();
164 if(token.equals(token.toLowerCase()))
166 if(lowerCaseColours==null)
168 lowerCaseColours = new Color[23];
170 lowerCaseColours[colIndex] = getColourFromString(colour);
173 colors[colIndex] = getColourFromString(colour);
179 System.out.println("Error parsing userDefinedColours:\n"
187 public Color findColour(String s, int j)
189 int index = ((Integer) (ResidueProperties.aaHash.get(s))).intValue();
191 if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))
193 if(lowerCaseColours!=null && 'a' <= s.charAt(0) && s.charAt(0) <= 'z')
194 currentColour = lowerCaseColours[index];
196 currentColour = colors[index];
200 currentColour = Color.white;
203 if(conservationColouring)
204 applyConservation(j);
207 return currentColour;
210 public void setLowerCaseColours(Color [] lcolours)
212 lowerCaseColours = lcolours;