1 package jalview.schemes;
3 import jalview.api.AlignViewportI;
4 import jalview.datamodel.AnnotatedCollectionI;
6 import java.util.LinkedHashMap;
9 public class ColourSchemes
12 * singleton instance of this class
14 private static ColourSchemes instance = new ColourSchemes();
17 * a map from scheme name to an instance of it
19 private Map<String, ColourSchemeI> schemes;
22 * Returns the singleton instance of this class
26 public static ColourSchemes getInstance()
31 private ColourSchemes()
37 * Loads an instance of each standard or user-defined colour scheme
41 void loadColourSchemes()
44 * store in an order-preserving map, so items can be added to menus
45 * in the order in which they are 'discovered'
47 schemes = new LinkedHashMap<String, ColourSchemeI>();
49 for (JalviewColourScheme cs : JalviewColourScheme.values())
53 registerColourScheme(cs.getSchemeClass().newInstance());
54 } catch (InstantiationException | IllegalAccessException e)
56 System.err.println("Error instantiating colour scheme for "
57 + cs.toString() + " " + e.getMessage());
63 * Registers a colour scheme
67 public void registerColourScheme(ColourSchemeI cs)
69 String name = cs.getSchemeName();
72 System.err.println("ColourScheme name may not be null");
77 * name is lower-case for non-case-sensitive lookup
78 * (name in the colour keeps its true case)
80 String lower = name.toLowerCase();
81 if (schemes.containsKey(lower))
84 .println("Warning: overwriting colour scheme named " + name);
86 schemes.put(lower, cs);
90 * Removes a colour scheme by name
94 public void removeColourScheme(String name)
100 * Returns an instance of the colour scheme with which the given view may be
104 * name of the colour scheme
108 public ColourSchemeI getColourScheme(String name, AlignViewportI viewport)
114 ColourSchemeI cs = schemes.get(name.toLowerCase());
115 return cs == null ? null : cs.getInstance(viewport.getAlignment(),
116 viewport.getHiddenRepSequences());
120 * Returns an instance of the colour scheme with which the given data may be
127 public ColourSchemeI getColourScheme(String name,
128 AnnotatedCollectionI forData)
130 ColourSchemeI cs = schemes.get(name.toLowerCase());
131 return cs == null ? null : cs.getInstance(forData, null);
135 * Returns an iterable set of the colour schemes, in the order in which they
140 public Iterable<ColourSchemeI> getColourSchemes()
142 return schemes.values();