JAL-2360 added UserColourScheme.toAppletParameter+test, hid
[jalview.git] / src / jalview / schemes / JalviewColourScheme.java
1 package jalview.schemes;
2
3 import jalview.datamodel.AnnotatedCollectionI;
4
5 import java.util.HashMap;
6 import java.util.Map;
7
8 /**
9  * An enum with the colour schemes supported by Jalview.
10  */
11 public enum JalviewColourScheme
12 {
13   Clustal("Clustal")
14   {
15     @Override
16     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
17     {
18       return new ClustalxColourScheme(coll, null);
19     }
20   },
21   Blosum62("Blosum62")
22   {
23     @Override
24     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
25     {
26       return new Blosum62ColourScheme();
27     }
28   },
29   PID("% Identity")
30   {
31     @Override
32     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
33     {
34       return new PIDColourScheme();
35     }
36   },
37   Zappo("Zappo")
38   {
39     @Override
40     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
41     {
42       return new ZappoColourScheme();
43     }
44   },
45   Taylor("Taylor")
46   {
47     @Override
48     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
49     {
50       return new TaylorColourScheme();
51     }
52   },
53   Hydrophobic("Hydrophobic")
54   {
55     @Override
56     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
57     {
58       return new HydrophobicColourScheme();
59     }
60   },
61   Helix("Helix Propensity")
62   {
63     @Override
64     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
65     {
66       return new HelixColourScheme();
67     }
68   },
69   Strand("Strand Propensity")
70   {
71     @Override
72     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
73     {
74       return new StrandColourScheme();
75     }
76   },
77   Turn("Turn Propensity")
78   {
79     @Override
80     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
81     {
82       return new TurnColourScheme();
83     }
84   },
85   Buried("Buried Index")
86   {
87     @Override
88     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
89     {
90       return new BuriedColourScheme();
91     }
92   },
93   Nucleotide("Nucleotide")
94   {
95     @Override
96     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
97     {
98       return new NucleotideColourScheme();
99     }
100   },
101   PurinePyrimidine("Purine/Pyrimidine")
102   {
103     @Override
104     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
105     {
106       return new PurinePyrimidineColourScheme();
107     }
108   },
109   TCoffee("T-Coffee Scores")
110   {
111     @Override
112     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
113     {
114       return new TCoffeeColourScheme(coll);
115     }
116   },
117   RNAHelices("RNA Helices")
118   {
119     @Override
120     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
121     {
122       return new RNAHelicesColour(coll);
123     }
124   },
125   // RNAInteraction("RNA Interaction type")
126   // {
127   // @Override
128   // public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
129   // {
130   // return new RNAInteractionColourScheme();
131   // }
132   // },
133   UserDefined("User Defined")
134   {
135     @Override
136     public ColourSchemeI getColourScheme(AnnotatedCollectionI coll)
137     {
138       return new UserColourScheme("white");
139     }
140   };
141
142   static Map<String, JalviewColourScheme> names = new HashMap<String, JalviewColourScheme>();
143
144   private String name;
145
146   static
147   {
148     for (JalviewColourScheme scheme : values())
149     {
150       names.put(scheme.name.toLowerCase(), scheme);
151     }
152   }
153
154   /**
155    * Answers the colour scheme with the 'given name', or null if name is invalid
156    * or null. The name is not case-sensitive.
157    * 
158    * @param name
159    * @return
160    */
161   public static JalviewColourScheme forName(String name)
162   {
163     return name == null ? null : names.get(name.toLowerCase());
164   }
165
166   /**
167    * Constructor given the name of the colour scheme (as used in Jalview
168    * parameters). Note this is not necessarily the same as the 'display name'
169    * used in menu options (as this may be language-dependent).
170    * 
171    * @param s
172    */
173   JalviewColourScheme(String s)
174   {
175     name = s;
176   }
177
178   /**
179    * Returns an instance of the colour scheme with which to colour the given
180    * data
181    * 
182    * @param coll
183    * @return
184    */
185   public abstract ColourSchemeI getColourScheme(AnnotatedCollectionI coll);
186
187   /**
188    * Returns the 'official' name of this colour scheme. This is the name that
189    * identifies the colour scheme as a start-up parameter for the Jalview
190    * application or applet. Note that it may not be the name shown in menu
191    * options, as these may be internationalised.
192    */
193   @Override
194   public String toString()
195   {
196     return name;
197   }
198 }