2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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 extends ResidueColourScheme
27 Color[] lowerCaseColours;
29 protected String schemeName;
31 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);
87 } catch (NumberFormatException ex)
93 col = ColourSchemeProperty.getAWTColorFromName(colour);
100 java.util.StringTokenizer st = new java.util.StringTokenizer(
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);
106 } catch (Exception ex)
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);
197 } catch (Exception ex)
199 System.out.println("Error parsing userDefinedColours:\n" + token
205 public Color findColour(char c, int j)
208 int index = ResidueProperties.aaIndex[c];
210 if ((threshold == 0) || aboveThreshold(c, j))
212 if (lowerCaseColours != null && 'a' <= c && c <= 'z')
214 currentColour = lowerCaseColours[index];
218 currentColour = colors[index];
223 currentColour = Color.white;
226 if (conservationColouring)
228 currentColour = applyConservation(currentColour, j);
231 return currentColour;
234 public void setLowerCaseColours(Color[] lcolours)
236 lowerCaseColours = lcolours;