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.datamodel.SequenceCollectionI;
25 import jalview.datamodel.SequenceI;
27 import java.util.LinkedHashMap;
30 public class ColourSchemes
33 * singleton instance of this class
35 private static ColourSchemes instance = new ColourSchemes();
38 * a map from scheme name (lower-cased) to an instance of it
40 private Map<String, ColourSchemeI> schemes;
43 * Returns the singleton instance of this class
47 public static ColourSchemes getInstance()
52 private ColourSchemes()
58 * Loads an instance of each standard or user-defined colour scheme
62 void loadColourSchemes()
65 * store in an order-preserving map, so items can be added to menus
66 * in the order in which they are 'discovered'
68 schemes = new LinkedHashMap<String, ColourSchemeI>();
70 for (JalviewColourScheme cs : JalviewColourScheme.values())
74 registerColourScheme(cs.getSchemeClass().newInstance());
75 } catch (InstantiationException | IllegalAccessException e)
77 System.err.println("Error instantiating colour scheme for "
78 + cs.toString() + " " + e.getMessage());
84 * Registers a colour scheme
88 public void registerColourScheme(ColourSchemeI cs)
90 String name = cs.getSchemeName();
93 System.err.println("ColourScheme name may not be null");
98 * name is lower-case for non-case-sensitive lookup
99 * (name in the colour keeps its true case)
101 String lower = name.toLowerCase();
102 if (schemes.containsKey(lower))
105 .println("Warning: overwriting colour scheme named " + name);
107 schemes.put(lower, cs);
111 * Removes a colour scheme by name
115 public void removeColourScheme(String name)
119 schemes.remove(name.toLowerCase());
124 * Returns an instance of the colour scheme with which the given view may be
128 * name of the colour scheme
130 * the data to be coloured
132 * map from hidden representative sequences to the sequences they
136 public ColourSchemeI getColourScheme(String name,
137 AnnotatedCollectionI forData,
138 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
144 ColourSchemeI cs = schemes.get(name.toLowerCase());
145 return cs == null ? null : cs.getInstance(forData, hiddenRepSequences);
149 * Returns an instance of the colour scheme with which the given view may be
153 * name of the colour scheme
155 * the data to be coloured
158 public ColourSchemeI getColourScheme(String name,
159 AnnotatedCollectionI forData)
161 return getColourScheme(name, forData, null);
165 * Returns an iterable set of the colour schemes, in the order in which they
170 public Iterable<ColourSchemeI> getColourSchemes()
172 return schemes.values();
176 * Answers true if there is a scheme with the given name, else false. The test
177 * is not case-sensitive.
182 public boolean nameExists(String name)
188 return schemes.containsKey(name.toLowerCase());