2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
22 import java.util.StringTokenizer;
\r
24 public class UserColourScheme
\r
25 extends ResidueColourScheme
\r
27 Color [] lowerCaseColours;
\r
29 protected String schemeName;
\r
31 public UserColourScheme()
\r
34 public UserColourScheme(Color[] newColors)
\r
39 public UserColourScheme(String colour)
\r
41 Color col = getColourFromString(colour);
\r
45 System.out.println("Unknown colour!! "+colour);
\r
46 col = createColourFromName(colour);
\r
49 colors = new Color[24];
\r
50 for(int i=0; i<24; i++)
\r
54 public Color[] getColours()
\r
59 public Color[] getLowerCaseColours()
\r
61 return lowerCaseColours;
\r
64 public void setName(String name)
\r
69 public String getName()
\r
74 public Color getColourFromString(String colour)
\r
76 colour = colour.trim();
\r
81 int value = Integer.parseInt(colour, 16);
\r
82 col = new Color(value);
\r
84 catch (NumberFormatException ex)
\r
88 col = ColourSchemeProperty.getAWTColorFromName(colour);
\r
94 java.util.StringTokenizer st = new java.util.StringTokenizer(colour,
\r
96 int r = Integer.parseInt(st.nextToken());
\r
97 int g = Integer.parseInt(st.nextToken());
\r
98 int b = Integer.parseInt(st.nextToken());
\r
99 col = new Color(r, g, b);
\r
101 catch (Exception ex)
\r
109 public Color createColourFromName(String name)
\r
113 int lsize = name.length();
\r
114 int start = 0, end = lsize / 3;
\r
116 int rgbOffset = Math.abs(name.hashCode() % 10) * 15;
\r
118 r = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
\r
124 g = Math.abs(name.substring(start, end).hashCode() + rgbOffset) % 210 + 20;
\r
126 b = Math.abs(name.substring(end).hashCode() + rgbOffset) % 210 + 20;
\r
128 Color color = new Color(r, g, b);
\r
133 public void parseAppletParameter(String paramValue)
\r
135 StringTokenizer st = new StringTokenizer(paramValue, ";");
\r
136 StringTokenizer st2;
\r
137 String token=null, colour, residues;
\r
139 while (st.hasMoreElements())
\r
141 token = st.nextToken().trim();
\r
142 residues = token.substring(0, token.indexOf("="));
\r
143 colour = token.substring(token.indexOf("=") + 1);
\r
145 st2 = new StringTokenizer(residues, " ,");
\r
146 while (st2.hasMoreTokens())
\r
148 token = st2.nextToken();
\r
150 if (ResidueProperties.aaIndex[token.charAt(0)]==-1)
\r
153 int colIndex = ResidueProperties.aaIndex[token.charAt(0)];
\r
155 if(token.equalsIgnoreCase("lowerCase"))
\r
157 if (lowerCaseColours == null)
\r
158 lowerCaseColours = new Color[23];
\r
159 for (int i = 0; i < 23; i++)
\r
160 if (lowerCaseColours[i] == null)
\r
161 lowerCaseColours[i] = getColourFromString(colour);
\r
166 if(token.equals(token.toLowerCase()))
\r
168 if(lowerCaseColours==null)
\r
170 lowerCaseColours = new Color[23];
\r
172 lowerCaseColours[colIndex] = getColourFromString(colour);
\r
175 colors[colIndex] = getColourFromString(colour);
\r
179 catch(Exception ex)
\r
181 System.out.println("Error parsing userDefinedColours:\n"
\r
189 public Color findColour(char c, int j)
\r
191 Color currentColour;
\r
192 int index = ResidueProperties.aaIndex[c];
\r
194 if ((threshold == 0) || aboveThreshold(c, j))
\r
196 if(lowerCaseColours!=null && 'a' <= c && c <= 'z')
\r
197 currentColour = lowerCaseColours[index];
\r
199 currentColour = colors[index];
\r
203 currentColour = Color.white;
\r
206 if(conservationColouring)
\r
207 currentColour = applyConservation(currentColour, j);
\r
210 return currentColour;
\r
213 public void setLowerCaseColours(Color [] lcolours)
\r
215 lowerCaseColours = lcolours;
\r