1 package jalview.schemes;
3 import jalview.datamodel.AnnotatedCollectionI;
4 import jalview.datamodel.SequenceCollectionI;
5 import jalview.datamodel.SequenceI;
7 import java.util.LinkedHashMap;
10 public class ColourSchemes
13 * singleton instance of this class
15 private static ColourSchemes instance = new ColourSchemes();
18 * a map from scheme name (lower-cased) to an instance of it
20 private Map<String, ColourSchemeI> schemes;
23 * Returns the singleton instance of this class
27 public static ColourSchemes getInstance()
32 private ColourSchemes()
38 * Loads an instance of each standard or user-defined colour scheme
42 void loadColourSchemes()
45 * store in an order-preserving map, so items can be added to menus
46 * in the order in which they are 'discovered'
48 schemes = new LinkedHashMap<String, ColourSchemeI>();
50 for (JalviewColourScheme cs : JalviewColourScheme.values())
54 registerColourScheme(cs.getSchemeClass().newInstance());
55 } catch (InstantiationException | IllegalAccessException e)
57 System.err.println("Error instantiating colour scheme for "
58 + cs.toString() + " " + e.getMessage());
64 * Registers a colour scheme
68 public void registerColourScheme(ColourSchemeI cs)
70 String name = cs.getSchemeName();
73 System.err.println("ColourScheme name may not be null");
78 * name is lower-case for non-case-sensitive lookup
79 * (name in the colour keeps its true case)
81 String lower = name.toLowerCase();
82 if (schemes.containsKey(lower))
85 .println("Warning: overwriting colour scheme named " + name);
87 schemes.put(lower, cs);
91 * Removes a colour scheme by name
95 public void removeColourScheme(String name)
99 schemes.remove(name.toLowerCase());
104 * Returns an instance of the colour scheme with which the given view may be
108 * name of the colour scheme
110 * the data to be coloured
112 * map from hidden representative sequences to the sequences they
116 public ColourSchemeI getColourScheme(String name,
117 AnnotatedCollectionI forData,
118 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
124 ColourSchemeI cs = schemes.get(name.toLowerCase());
125 return cs == null ? null : cs.getInstance(forData, hiddenRepSequences);
129 * Returns an instance of the colour scheme with which the given view may be
133 * name of the colour scheme
135 * the data to be coloured
138 public ColourSchemeI getColourScheme(String name,
139 AnnotatedCollectionI forData)
141 return getColourScheme(name, forData, null);
145 * Returns an iterable set of the colour schemes, in the order in which they
150 public Iterable<ColourSchemeI> getColourSchemes()
152 return schemes.values();
156 * Answers true if there is a scheme with the given name, else false. The test
157 * is not case-sensitive.
162 public boolean nameExists(String name)
168 return schemes.containsKey(name.toLowerCase());