2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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;
24 * ColourSchemeProperty Binds names to hardwired colourschemes and tries to deal
25 * intelligently with mapping unknown names to user defined colourschemes (that
26 * exist or can be created from the string representation of the colourscheme
27 * name - either a hex RGB triplet or a named colour under java.awt.color )
32 public class ColourSchemeProperty
35 public static final int CLUSTAL = 0;
38 public static final int BLOSUM = 1;
41 public static final int PID = 2;
44 public static final int ZAPPO = 3;
47 public static final int TAYLOR = 4;
50 public static final int HYDROPHOBIC = 5;
53 public static final int HELIX = 6;
56 public static final int STRAND = 7;
59 public static final int TURN = 8;
62 public static final int BURIED = 9;
65 public static final int NUCLEOTIDE = 10;
68 public static final int USER_DEFINED = 11;
70 /** No Colourscheme Index */
71 public static final int NONE = 12;
73 /** Undefined Colourscheme Index */
74 public static final int UNDEFINED = 13;
82 * @return DOCUMENT ME!
84 public static int getColourIndexFromName(String name)
88 if (name.equalsIgnoreCase("Clustal"))
92 else if (name.equalsIgnoreCase("Blosum62"))
96 else if (name.equalsIgnoreCase("% Identity"))
100 else if (name.equalsIgnoreCase("Zappo"))
104 else if (name.equalsIgnoreCase("Taylor"))
108 else if (name.equalsIgnoreCase("Hydrophobic"))
112 else if (name.equalsIgnoreCase("Helix Propensity"))
116 else if (name.equalsIgnoreCase("Strand Propensity"))
120 else if (name.equalsIgnoreCase("Turn Propensity"))
124 else if (name.equalsIgnoreCase("Buried Index"))
128 else if (name.equalsIgnoreCase("Nucleotide"))
132 else if (name.equalsIgnoreCase("User Defined"))
136 else if (name.equalsIgnoreCase("None"))
150 * @return DOCUMENT ME!
152 public static String getColourName(ColourSchemeI cs)
157 if (cs instanceof ClustalxColourScheme)
161 else if (cs instanceof Blosum62ColourScheme)
165 else if (cs instanceof PIDColourScheme)
169 else if (cs instanceof ZappoColourScheme)
173 else if (cs instanceof TaylorColourScheme)
177 else if (cs instanceof HydrophobicColourScheme)
181 else if (cs instanceof HelixColourScheme)
185 else if (cs instanceof StrandColourScheme)
189 else if (cs instanceof TurnColourScheme)
193 else if (cs instanceof BuriedColourScheme)
197 else if (cs instanceof NucleotideColourScheme)
201 else if (cs instanceof UserColourScheme)
203 if ((((UserColourScheme) cs).getName() != null)
204 && (((UserColourScheme) cs).getName().length() > 0))
206 return ((UserColourScheme) cs).getName();
208 // get default colourscheme name
209 index = USER_DEFINED;
212 return getColourName(index);
221 * @return DOCUMENT ME!
223 public static String getColourName(int index)
259 ret = "Helix Propensity";
264 ret = "Strand Propensity";
269 ret = "Turn Propensity";
274 ret = "Buried Index";
284 ret = "User Defined";
305 * @return DOCUMENT ME!
307 public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al,
310 return getColour(al.getSequences(), al.getWidth(), name);
314 * retrieve or create colourscheme associated with name
317 * sequences to colour
319 * range of sequences to colour
321 * colourscheme name, applet colour parameter specification, or
322 * string to parse as colour for new coloursheme
323 * @return Valid Colourscheme
325 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
328 int colindex = getColourIndexFromName(name);
329 if (colindex == UNDEFINED)
331 if (name.indexOf('=') == -1)
333 // try to build a colour from the string directly
336 return new UserColourScheme(name);
337 } catch (Exception e)
339 // System.err.println("Ignoring unknown colourscheme name");
344 // try to parse the string as a residue colourscheme
347 // fix the launchApp user defined coloursheme transfer bug
348 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
350 ucs.parseAppletParameter(name);
352 } catch (Exception e)
354 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
358 return getColour(seqs, width, getColourIndexFromName(name));
371 * @return DOCUMENT ME!
373 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
376 ColourSchemeI cs = null;
381 cs = new ClustalxColourScheme(seqs, width);
386 cs = new Blosum62ColourScheme();
391 cs = new PIDColourScheme();
396 cs = new ZappoColourScheme();
401 cs = new TaylorColourScheme();
405 cs = new HydrophobicColourScheme();
410 cs = new HelixColourScheme();
415 cs = new StrandColourScheme();
420 cs = new TurnColourScheme();
425 cs = new BuriedColourScheme();
430 cs = new NucleotideColourScheme();
435 Color[] col = new Color[24];
436 for (int i = 0; i < 24; i++)
438 col[i] = Color.white;
440 cs = new UserColourScheme(col);
450 public static Color getAWTColorFromName(String name)
453 name = name.toLowerCase();
454 if (name.equals("black"))
458 else if (name.equals("blue"))
462 else if (name.equals("cyan"))
466 else if (name.equals("darkGray"))
468 col = Color.darkGray;
470 else if (name.equals("gray"))
474 else if (name.equals("green"))
478 else if (name.equals("lightGray"))
480 col = Color.lightGray;
482 else if (name.equals("magenta"))
486 else if (name.equals("orange"))
490 else if (name.equals("pink"))
494 else if (name.equals("red"))
498 else if (name.equals("white"))
502 else if (name.equals("yellow"))