2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.schemes;
23 * ColourSchemeProperty Binds names to hardwired colourschemes and tries to deal
24 * intelligently with mapping unknown names to user defined colourschemes (that
25 * exist or can be created from the string representation of the colourscheme
26 * name - either a hex RGB triplet or a named colour under java.awt.color )
31 public class ColourSchemeProperty
34 public static final int CLUSTAL = 0;
37 public static final int BLOSUM = 1;
40 public static final int PID = 2;
43 public static final int ZAPPO = 3;
46 public static final int TAYLOR = 4;
49 public static final int HYDROPHOBIC = 5;
52 public static final int HELIX = 6;
55 public static final int STRAND = 7;
58 public static final int TURN = 8;
61 public static final int BURIED = 9;
64 public static final int NUCLEOTIDE = 10;
67 public static final int USER_DEFINED = 11;
69 /** No Colourscheme Index */
70 public static final int NONE = 12;
72 /** Undefined Colourscheme Index */
73 public static final int UNDEFINED = 13;
81 * @return DOCUMENT ME!
83 public static int getColourIndexFromName(String name)
87 if (name.equalsIgnoreCase("Clustal"))
91 else if (name.equalsIgnoreCase("Blosum62"))
95 else if (name.equalsIgnoreCase("% Identity"))
99 else if (name.equalsIgnoreCase("Zappo"))
103 else if (name.equalsIgnoreCase("Taylor"))
107 else if (name.equalsIgnoreCase("Hydrophobic"))
111 else if (name.equalsIgnoreCase("Helix Propensity"))
115 else if (name.equalsIgnoreCase("Strand Propensity"))
119 else if (name.equalsIgnoreCase("Turn Propensity"))
123 else if (name.equalsIgnoreCase("Buried Index"))
127 else if (name.equalsIgnoreCase("Nucleotide"))
131 else if (name.equalsIgnoreCase("User Defined"))
135 else if (name.equalsIgnoreCase("None"))
149 * @return DOCUMENT ME!
151 public static String getColourName(ColourSchemeI cs)
156 if (cs instanceof ClustalxColourScheme)
160 else if (cs instanceof Blosum62ColourScheme)
164 else if (cs instanceof PIDColourScheme)
168 else if (cs instanceof ZappoColourScheme)
172 else if (cs instanceof TaylorColourScheme)
176 else if (cs instanceof HydrophobicColourScheme)
180 else if (cs instanceof HelixColourScheme)
184 else if (cs instanceof StrandColourScheme)
188 else if (cs instanceof TurnColourScheme)
192 else if (cs instanceof BuriedColourScheme)
196 else if (cs instanceof NucleotideColourScheme)
200 else if (cs instanceof UserColourScheme)
202 if ((((UserColourScheme) cs).getName() != null)
203 && (((UserColourScheme) cs).getName().length() > 0))
205 return ((UserColourScheme) cs).getName();
207 // get default colourscheme name
208 index = USER_DEFINED;
211 return getColourName(index);
220 * @return DOCUMENT ME!
222 public static String getColourName(int index)
258 ret = "Helix Propensity";
263 ret = "Strand Propensity";
268 ret = "Turn Propensity";
273 ret = "Buried Index";
283 ret = "User Defined";
304 * @return DOCUMENT ME!
306 public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al,
309 return getColour(al.getSequences(), al.getWidth(), name);
313 * retrieve or create colourscheme associated with name
316 * sequences to colour
318 * range of sequences to colour
320 * colourscheme name, applet colour parameter specification, or
321 * string to parse as colour for new coloursheme
322 * @return Valid Colourscheme
324 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
327 int colindex = getColourIndexFromName(name);
328 if (colindex == UNDEFINED)
330 if (name.indexOf('=') == -1)
332 // try to build a colour from the string directly
335 return new UserColourScheme(name);
336 } catch (Exception e)
338 // System.err.println("Ignoring unknown colourscheme name");
343 // try to parse the string as a residue colourscheme
346 // fix the launchApp user defined coloursheme transfer bug
347 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
349 ucs.parseAppletParameter(name);
351 } catch (Exception e)
353 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
357 return getColour(seqs, width, getColourIndexFromName(name));
370 * @return DOCUMENT ME!
372 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
375 ColourSchemeI cs = null;
380 cs = new ClustalxColourScheme(seqs, width);
385 cs = new Blosum62ColourScheme();
390 cs = new PIDColourScheme();
395 cs = new ZappoColourScheme();
400 cs = new TaylorColourScheme();
404 cs = new HydrophobicColourScheme();
409 cs = new HelixColourScheme();
414 cs = new StrandColourScheme();
419 cs = new TurnColourScheme();
424 cs = new BuriedColourScheme();
429 cs = new NucleotideColourScheme();
434 Color[] col = new Color[24];
435 for (int i = 0; i < 24; i++)
437 col[i] = Color.white;
439 cs = new UserColourScheme(col);
449 public static Color getAWTColorFromName(String name)
452 name = name.toLowerCase();
453 if (name.equals("black"))
457 else if (name.equals("blue"))
461 else if (name.equals("cyan"))
465 else if (name.equals("darkGray"))
467 col = Color.darkGray;
469 else if (name.equals("gray"))
473 else if (name.equals("green"))
477 else if (name.equals("lightGray"))
479 col = Color.lightGray;
481 else if (name.equals("magenta"))
485 else if (name.equals("orange"))
489 else if (name.equals("pink"))
493 else if (name.equals("red"))
497 else if (name.equals("white"))
501 else if (name.equals("yellow"))