2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.schemes;
23 import jalview.datamodel.AnnotatedCollectionI;
24 import jalview.util.ColorUtils;
26 import java.awt.Color;
29 * ColourSchemeProperty binds names to hardwired colourschemes and tries to deal
30 * intelligently with mapping unknown names to user defined colourschemes (that
31 * exist or can be created from the string representation of the colourscheme
32 * name - either a hex RGB triplet or a named colour under java.awt.color ). The
33 * values of the colourscheme constants is important for callers of
34 * getColourName(int i), since it can be used to enumerate the set of built in
35 * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
40 public class ColourSchemeProperty
44 * Returns a colour scheme for the given name, with which the given data may
45 * be coloured. The name is not case-sensitive, and may be one of
47 * <li>any currently registered colour scheme; Jalview by default provides</li>
52 * <li>Hydrophobic</li>
55 * <li>Helix Propensity</li>
56 * <li>Strand Propensity</li>
57 * <li>Turn Propensity</li>
58 * <li>Buried Index</li>
60 * <li>Purine/Pyrimidine</li>
61 * <li>T-Coffee Scores</li>
62 * <li>RNA Helices</li>
64 * <li>the name of a programmatically added colour scheme</li> <li>an AWT
65 * colour name e.g. red</li> <li>an AWT hex rgb colour e.g. ff2288</li> <li>
66 * residue colours list e.g. D,E=red;K,R,H=0022FF;c=yellow</li> </ul>
68 * If none of these formats is matched, the string is converted to a colour
69 * using a hashing algorithm. For name "None", returns null.
75 public static ColourSchemeI getColourScheme(AnnotatedCollectionI forData,
78 if (ResidueColourScheme.NONE.equalsIgnoreCase(name))
85 * if this is the name of a registered colour scheme, just
86 * create a new instance of it
88 ColourSchemeI scheme = ColourSchemes.getInstance().getColourScheme(
96 * try to parse the string as a residues colour scheme
97 * e.g. A=red;T,G=blue etc
98 * else parse the name as a colour specification
99 * e.g. "red" or "ff00ed",
100 * or failing that hash the name to a colour
102 UserColourScheme ucs = new UserColourScheme(name);
106 public static Color rnaHelices[] = null;
108 public static void initRnaHelicesShading(int n)
111 if (rnaHelices == null)
113 rnaHelices = new Color[n + 1];
115 else if (rnaHelices != null && rnaHelices.length <= n)
117 Color[] t = new Color[n + 1];
118 System.arraycopy(rnaHelices, 0, t, 0, rnaHelices.length);
119 j = rnaHelices.length;
126 // Generate random colors and store
129 rnaHelices[j] = ColorUtils.generateRandomColor(Color.white);
134 * delete the existing cached RNA helices colours
136 public static void resetRnaHelicesShading()
142 * Returns the name of the colour scheme (or "None" if it is null)
147 public static String getColourName(ColourSchemeI cs)
149 return cs == null ? ResidueColourScheme.NONE : cs