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