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
316 * @param seqs sequences to colour
317 * @param width range of sequences to colour
318 * @param name colourscheme name, applet colour parameter specification, or string to parse as colour for new coloursheme
319 * @return Valid Colourscheme
321 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
324 int colindex = getColourIndexFromName(name);
325 if (colindex == UNDEFINED) // USER_DEFINED)
329 return new UserColourScheme(name);
330 } catch (Exception e)
332 // System.err.println("Ignoring unknown colourscheme name");
335 // fix the launchApp user defined coloursheme transfer bug
336 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
338 ucs.parseAppletParameter(name);
340 } catch (Exception e)
342 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
345 return getColour(seqs, width, getColourIndexFromName(name));
358 * @return DOCUMENT ME!
360 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
363 ColourSchemeI cs = null;
368 cs = new ClustalxColourScheme(seqs, width);
373 cs = new Blosum62ColourScheme();
378 cs = new PIDColourScheme();
383 cs = new ZappoColourScheme();
388 cs = new TaylorColourScheme();
392 cs = new HydrophobicColourScheme();
397 cs = new HelixColourScheme();
402 cs = new StrandColourScheme();
407 cs = new TurnColourScheme();
412 cs = new BuriedColourScheme();
417 cs = new NucleotideColourScheme();
422 Color[] col = new Color[24];
423 for (int i = 0; i < 24; i++)
425 col[i] = Color.white;
427 cs = new UserColourScheme(col);
437 public static Color getAWTColorFromName(String name)
440 name = name.toLowerCase();
441 if (name.equals("black"))
445 else if (name.equals("blue"))
449 else if (name.equals("cyan"))
453 else if (name.equals("darkGray"))
455 col = Color.darkGray;
457 else if (name.equals("gray"))
461 else if (name.equals("green"))
465 else if (name.equals("lightGray"))
467 col = Color.lightGray;
469 else if (name.equals("magenta"))
473 else if (name.equals("orange"))
477 else if (name.equals("pink"))
481 else if (name.equals("red"))
485 else if (name.equals("white"))
489 else if (name.equals("yellow"))