2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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;
25 public class UserColourScheme
26 extends ResidueColourScheme
28 Color[] lowerCaseColours;
30 protected String schemeName;
32 public UserColourScheme()
35 public UserColourScheme(Color[] newColors)
40 public UserColourScheme(String colour)
42 Color col = getColourFromString(colour);
46 System.out.println("Unknown colour!! " + colour);
47 col = createColourFromName(colour);
50 colors = new Color[24];
51 for (int i = 0; i < 24; i++)
58 public Color[] getColours()
63 public Color[] getLowerCaseColours()
65 return lowerCaseColours;
68 public void setName(String name)
73 public String getName()
78 public Color getColourFromString(String colour)
80 colour = colour.trim();
85 int value = Integer.parseInt(colour, 16);
86 col = new Color(value);
88 catch (NumberFormatException ex)
93 col = ColourSchemeProperty.getAWTColorFromName(colour);
100 java.util.StringTokenizer st = new java.util.StringTokenizer(colour,
102 int r = Integer.parseInt(st.nextToken());
103 int g = Integer.parseInt(st.nextToken());
104 int b = Integer.parseInt(st.nextToken());
105 col = new Color(r, g, b);
115 public Color createColourFromName(String name)
119 int lsize = name.length();
120 int start = 0, end = lsize / 3;
122 int rgbOffset = Math.abs(name.hashCode() % 10) * 15;
124 r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
132 g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
134 b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
136 Color color = new Color(r, g, b);
141 public void parseAppletParameter(String paramValue)
143 StringTokenizer st = new StringTokenizer(paramValue, ";");
145 String token = null, colour, residues;
148 while (st.hasMoreElements())
150 token = st.nextToken().trim();
151 residues = token.substring(0, token.indexOf("="));
152 colour = token.substring(token.indexOf("=") + 1);
154 st2 = new StringTokenizer(residues, " ,");
155 while (st2.hasMoreTokens())
157 token = st2.nextToken();
159 if (ResidueProperties.aaIndex[token.charAt(0)] == -1)
164 int colIndex = ResidueProperties.aaIndex[token.charAt(0)];
166 if (token.equalsIgnoreCase("lowerCase"))
168 if (lowerCaseColours == null)
170 lowerCaseColours = new Color[23];
172 for (int i = 0; i < 23; i++)
174 if (lowerCaseColours[i] == null)
176 lowerCaseColours[i] = getColourFromString(colour);
183 if (token.equals(token.toLowerCase()))
185 if (lowerCaseColours == null)
187 lowerCaseColours = new Color[23];
189 lowerCaseColours[colIndex] = getColourFromString(colour);
193 colors[colIndex] = getColourFromString(colour);
200 System.out.println("Error parsing userDefinedColours:\n"
201 + token + "\n" + ex);
206 public Color findColour(char c, int j)
209 int index = ResidueProperties.aaIndex[c];
211 if ( (threshold == 0) || aboveThreshold(c, j))
213 if (lowerCaseColours != null && 'a' <= c && c <= 'z')
215 currentColour = lowerCaseColours[index];
219 currentColour = colors[index];
224 currentColour = Color.white;
227 if (conservationColouring)
229 currentColour = applyConservation(currentColour, j);
232 return currentColour;
235 public void setLowerCaseColours(Color[] lcolours)
237 lowerCaseColours = lcolours;