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 ). The
27 * values of the colourscheme constants is important for callers of
28 * getColourName(int i), since it can be used to enumerate the set of built in
29 * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
34 public class ColourSchemeProperty
36 /** Undefined Colourscheme Index */
37 public static final int UNDEFINED = -1;
39 /** for schemes defined on the fly */
40 public static final int USER_DEFINED = 0;
42 /** No Colourscheme Index */
43 public static final int NONE = 1;
46 public static final int CLUSTAL = 2;
49 public static final int BLOSUM = 3;
52 public static final int PID = 4;
55 public static final int ZAPPO = 5;
58 public static final int TAYLOR = 6;
61 public static final int HYDROPHOBIC = 7;
64 public static final int HELIX = 8;
67 public static final int STRAND = 9;
70 public static final int TURN = 10;
73 public static final int BURIED = 11;
76 public static final int NUCLEOTIDE = 12;
81 public static final int PURINEPYRIMIDINE = 13;
83 public static final int COVARIATION = 14;
86 * index of first colourscheme (includes 'None')
88 public static final int FIRST_COLOUR = NONE;
90 public static final int LAST_COLOUR = NUCLEOTIDE;
98 * @return DOCUMENT ME!
100 public static int getColourIndexFromName(String name)
104 if (name.equalsIgnoreCase("Clustal"))
108 else if (name.equalsIgnoreCase("Blosum62"))
112 else if (name.equalsIgnoreCase("% Identity"))
116 else if (name.equalsIgnoreCase("Zappo"))
120 else if (name.equalsIgnoreCase("Taylor"))
124 else if (name.equalsIgnoreCase("Hydrophobic"))
128 else if (name.equalsIgnoreCase("Helix Propensity"))
132 else if (name.equalsIgnoreCase("Strand Propensity"))
136 else if (name.equalsIgnoreCase("Turn Propensity"))
140 else if (name.equalsIgnoreCase("Buried Index"))
144 else if (name.equalsIgnoreCase("Nucleotide"))
148 else if (name.equalsIgnoreCase("User Defined"))
152 else if (name.equalsIgnoreCase("None"))
166 * @return DOCUMENT ME!
168 public static String getColourName(ColourSchemeI cs)
173 if (cs instanceof ClustalxColourScheme)
177 else if (cs instanceof Blosum62ColourScheme)
181 else if (cs instanceof PIDColourScheme)
185 else if (cs instanceof ZappoColourScheme)
189 else if (cs instanceof TaylorColourScheme)
193 else if (cs instanceof HydrophobicColourScheme)
197 else if (cs instanceof HelixColourScheme)
201 else if (cs instanceof StrandColourScheme)
205 else if (cs instanceof TurnColourScheme)
209 else if (cs instanceof BuriedColourScheme)
213 else if (cs instanceof NucleotideColourScheme)
217 else if (cs instanceof UserColourScheme)
219 if ((((UserColourScheme) cs).getName() != null)
220 && (((UserColourScheme) cs).getName().length() > 0))
222 return ((UserColourScheme) cs).getName();
224 // get default colourscheme name
225 index = USER_DEFINED;
228 return getColourName(index);
237 * @return DOCUMENT ME!
239 public static String getColourName(int index)
275 ret = "Helix Propensity";
280 ret = "Strand Propensity";
285 ret = "Turn Propensity";
290 ret = "Buried Index";
300 ret = "User Defined";
321 * @return DOCUMENT ME!
323 public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al,
326 return getColour(al.getSequences(), al.getWidth(), name);
330 * retrieve or create colourscheme associated with name
333 * sequences to colour
335 * range of sequences to colour
337 * colourscheme name, applet colour parameter specification, or
338 * string to parse as colour for new coloursheme
339 * @return Valid Colourscheme
341 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
344 int colindex = getColourIndexFromName(name);
345 if (colindex == UNDEFINED)
347 if (name.indexOf('=') == -1)
349 // try to build a colour from the string directly
352 return new UserColourScheme(name);
353 } catch (Exception e)
355 // System.err.println("Ignoring unknown colourscheme name");
360 // try to parse the string as a residue colourscheme
363 // fix the launchApp user defined coloursheme transfer bug
364 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
366 ucs.parseAppletParameter(name);
368 } catch (Exception e)
370 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
374 return getColour(seqs, width, getColourIndexFromName(name));
387 * @return DOCUMENT ME!
389 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
392 ColourSchemeI cs = null;
397 cs = new ClustalxColourScheme(seqs, width);
402 cs = new Blosum62ColourScheme();
407 cs = new PIDColourScheme();
412 cs = new ZappoColourScheme();
417 cs = new TaylorColourScheme();
421 cs = new HydrophobicColourScheme();
426 cs = new HelixColourScheme();
431 cs = new StrandColourScheme();
436 cs = new TurnColourScheme();
441 cs = new BuriedColourScheme();
446 cs = new NucleotideColourScheme();
451 Color[] col = new Color[24];
452 for (int i = 0; i < 24; i++)
454 col[i] = Color.white;
456 cs = new UserColourScheme(col);
466 public static Color getAWTColorFromName(String name)
469 name = name.toLowerCase();
470 if (name.equals("black"))
474 else if (name.equals("blue"))
478 else if (name.equals("cyan"))
482 else if (name.equals("darkGray"))
484 col = Color.darkGray;
486 else if (name.equals("gray"))
490 else if (name.equals("green"))
494 else if (name.equals("lightGray"))
496 col = Color.lightGray;
498 else if (name.equals("magenta"))
502 else if (name.equals("orange"))
506 else if (name.equals("pink"))
510 else if (name.equals("red"))
514 else if (name.equals("white"))
518 else if (name.equals("yellow"))