2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.schemes;
24 public class UserColourScheme extends ResidueColourScheme
26 Color[] lowerCaseColours;
28 protected String schemeName;
30 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++)
57 public Color[] getColours()
62 public Color[] getLowerCaseColours()
64 return lowerCaseColours;
67 public void setName(String name)
72 public String getName()
77 public Color getColourFromString(String colour)
79 colour = colour.trim();
84 int value = Integer.parseInt(colour, 16);
85 col = new Color(value);
86 } catch (NumberFormatException ex)
92 col = ColourSchemeProperty.getAWTColorFromName(colour);
99 java.util.StringTokenizer st = new java.util.StringTokenizer(
101 int r = Integer.parseInt(st.nextToken());
102 int g = Integer.parseInt(st.nextToken());
103 int b = Integer.parseInt(st.nextToken());
104 col = new Color(r, g, b);
105 } catch (Exception ex)
114 public Color createColourFromName(String name)
118 int lsize = name.length();
119 int start = 0, end = lsize / 3;
121 int rgbOffset = Math.abs(name.hashCode() % 10) * 15;
123 r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
131 g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
133 b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
135 Color color = new Color(r, g, b);
140 public void parseAppletParameter(String paramValue)
142 StringTokenizer st = new StringTokenizer(paramValue, ";");
144 String token = null, colour, residues;
147 while (st.hasMoreElements())
149 token = st.nextToken().trim();
150 residues = token.substring(0, token.indexOf("="));
151 colour = token.substring(token.indexOf("=") + 1);
153 st2 = new StringTokenizer(residues, " ,");
154 while (st2.hasMoreTokens())
156 token = st2.nextToken();
158 if (ResidueProperties.aaIndex[token.charAt(0)] == -1)
163 int colIndex = ResidueProperties.aaIndex[token.charAt(0)];
165 if (token.equalsIgnoreCase("lowerCase"))
167 if (lowerCaseColours == null)
169 lowerCaseColours = new Color[23];
171 for (int i = 0; i < 23; i++)
173 if (lowerCaseColours[i] == null)
175 lowerCaseColours[i] = getColourFromString(colour);
182 if (token.equals(token.toLowerCase()))
184 if (lowerCaseColours == null)
186 lowerCaseColours = new Color[23];
188 lowerCaseColours[colIndex] = getColourFromString(colour);
192 colors[colIndex] = getColourFromString(colour);
196 } catch (Exception ex)
198 System.out.println("Error parsing userDefinedColours:\n" + token
204 public Color findColour(char c, int j)
207 int index = ResidueProperties.aaIndex[c];
209 if ((threshold == 0) || aboveThreshold(c, j))
211 if (lowerCaseColours != null && 'a' <= c && c <= 'z')
213 currentColour = lowerCaseColours[index];
217 currentColour = colors[index];
222 currentColour = Color.white;
225 if (conservationColouring)
227 currentColour = applyConservation(currentColour, j);
230 return currentColour;
233 public void setLowerCaseColours(Color[] lcolours)
235 lowerCaseColours = lcolours;