2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.schemes;
\r
25 public class UserColourScheme
\r
26 extends ResidueColourScheme
\r
28 Color[] lowerCaseColours;
\r
30 protected String schemeName;
\r
32 public UserColourScheme()
\r
35 public UserColourScheme(Color[] newColors)
\r
40 public UserColourScheme(String colour)
\r
42 Color col = getColourFromString(colour);
\r
46 System.out.println("Unknown colour!! " + colour);
\r
47 col = createColourFromName(colour);
\r
50 colors = new Color[24];
\r
51 for (int i = 0; i < 24; i++)
\r
57 public Color[] getColours()
\r
62 public Color[] getLowerCaseColours()
\r
64 return lowerCaseColours;
\r
67 public void setName(String name)
\r
72 public String getName()
\r
77 public Color getColourFromString(String colour)
\r
79 colour = colour.trim();
\r
84 int value = Integer.parseInt(colour, 16);
\r
85 col = new Color(value);
\r
87 catch (NumberFormatException ex)
\r
92 col = ColourSchemeProperty.getAWTColorFromName(colour);
\r
99 java.util.StringTokenizer st = new java.util.StringTokenizer(colour,
\r
101 int r = Integer.parseInt(st.nextToken());
\r
102 int g = Integer.parseInt(st.nextToken());
\r
103 int b = Integer.parseInt(st.nextToken());
\r
104 col = new Color(r, g, b);
\r
106 catch (Exception ex)
\r
114 public Color createColourFromName(String name)
\r
118 int lsize = name.length();
\r
119 int start = 0, end = lsize / 3;
\r
121 int rgbOffset = Math.abs(name.hashCode() % 10) * 15;
\r
123 r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
\r
131 g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
\r
133 b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
\r
135 Color color = new Color(r, g, b);
\r
140 public void parseAppletParameter(String paramValue)
\r
142 StringTokenizer st = new StringTokenizer(paramValue, ";");
\r
143 StringTokenizer st2;
\r
144 String token = null, colour, residues;
\r
147 while (st.hasMoreElements())
\r
149 token = st.nextToken().trim();
\r
150 residues = token.substring(0, token.indexOf("="));
\r
151 colour = token.substring(token.indexOf("=") + 1);
\r
153 st2 = new StringTokenizer(residues, " ,");
\r
154 while (st2.hasMoreTokens())
\r
156 token = st2.nextToken();
\r
158 if (ResidueProperties.aaIndex[token.charAt(0)] == -1)
\r
163 int colIndex = ResidueProperties.aaIndex[token.charAt(0)];
\r
165 if (token.equalsIgnoreCase("lowerCase"))
\r
167 if (lowerCaseColours == null)
\r
169 lowerCaseColours = new Color[23];
\r
171 for (int i = 0; i < 23; i++)
\r
173 if (lowerCaseColours[i] == null)
\r
175 lowerCaseColours[i] = getColourFromString(colour);
\r
182 if (token.equals(token.toLowerCase()))
\r
184 if (lowerCaseColours == null)
\r
186 lowerCaseColours = new Color[23];
\r
188 lowerCaseColours[colIndex] = getColourFromString(colour);
\r
192 colors[colIndex] = getColourFromString(colour);
\r
197 catch (Exception ex)
\r
199 System.out.println("Error parsing userDefinedColours:\n"
\r
200 + token + "\n" + ex);
\r
205 public Color findColour(char c, int j)
\r
207 Color currentColour;
\r
208 int index = ResidueProperties.aaIndex[c];
\r
210 if ( (threshold == 0) || aboveThreshold(c, j))
\r
212 if (lowerCaseColours != null && 'a' <= c && c <= 'z')
\r
214 currentColour = lowerCaseColours[index];
\r
218 currentColour = colors[index];
\r
223 currentColour = Color.white;
\r
226 if (conservationColouring)
\r
228 currentColour = applyConservation(currentColour, j);
\r
231 return currentColour;
\r
234 public void setLowerCaseColours(Color[] lcolours)
\r
236 lowerCaseColours = lcolours;
\r