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 //AW - LOWER CASE DISABLED IN 2.1.01 bug fix release
\r
157 if(token.equalsIgnoreCase("lowerCase"))
\r
159 if (lowerCaseColours == null)
\r
160 lowerCaseColours = new Color[23];
\r
161 for (int i = 0; i < 23; i++)
\r
162 if (lowerCaseColours[i] == null)
\r
163 lowerCaseColours[i] = getColourFromString(colour);
\r
168 if(token.equals(token.toLowerCase()))
\r
170 if(lowerCaseColours==null)
\r
172 lowerCaseColours = new Color[23];
\r
174 lowerCaseColours[colIndex] = getColourFromString(colour);
\r
177 colors[colIndex] = getColourFromString(colour);
\r
181 catch(Exception ex)
\r
183 System.out.println("Error parsing userDefinedColours:\n"
\r
191 public Color findColour(String s, int j)
\r
193 int index = ResidueProperties.aaIndex[s.charAt(0)];
\r
195 if ((threshold == 0) || aboveThreshold(ResidueProperties.aa[index], j))
\r
197 //AW - LOWER CASE DISABLED IN 2.1.01 bug fix release
\r
198 if(lowerCaseColours!=null && 'a' <= s.charAt(0) && s.charAt(0) <= 'z')
\r
199 currentColour = lowerCaseColours[index];
\r
201 currentColour = colors[index];
\r
205 currentColour = Color.white;
\r
208 if(conservationColouring)
\r
209 applyConservation(j);
\r
212 return currentColour;
\r
215 public void setLowerCaseColours(Color [] lcolours)
\r
217 lowerCaseColours = lcolours;
\r