355d717f15fc08e29b8a4676fd3a7e20813dc765
[jalview.git] / src / jalview / schemes / ColourSchemeProperty.java
1 /*
2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18 */
19 package jalview.schemes;
20
21 import java.awt.*;
22 /**
23  * DOCUMENT ME!
24  *
25  * @author $author$
26  * @version $Revision$
27  */
28 public class ColourSchemeProperty
29 {
30     /** DOCUMENT ME!! */
31     public static final int CLUSTAL = 0;
32
33     /** DOCUMENT ME!! */
34     public static final int BLOSUM = 1;
35
36     /** DOCUMENT ME!! */
37     public static final int PID = 2;
38
39     /** DOCUMENT ME!! */
40     public static final int ZAPPO = 3;
41
42     /** DOCUMENT ME!! */
43     public static final int TAYLOR = 4;
44
45     /** DOCUMENT ME!! */
46     public static final int HYDROPHOBIC = 5;
47
48     /** DOCUMENT ME!! */
49     public static final int HELIX = 6;
50
51     /** DOCUMENT ME!! */
52     public static final int STRAND = 7;
53
54     /** DOCUMENT ME!! */
55     public static final int TURN = 8;
56
57     /** DOCUMENT ME!! */
58     public static final int BURIED = 9;
59
60     /** DOCUMENT ME!! */
61     public static final int NUCLEOTIDE = 10;
62
63     /** DOCUMENT ME!! */
64     public static final int USER_DEFINED = 11;
65
66
67     /** DOCUMENT ME!! */
68     public static final int NONE = 12;
69
70     /**
71      * DOCUMENT ME!
72      *
73      * @param name DOCUMENT ME!
74      *
75      * @return DOCUMENT ME!
76      */
77     public static int getColourIndexFromName(String name)
78     {
79         int ret = 12;
80
81         if (name.equalsIgnoreCase("Clustal"))
82         {
83             ret = CLUSTAL;
84         }
85         else if (name.equalsIgnoreCase("Blosum62"))
86         {
87             ret = BLOSUM;
88         }
89         else if (name.equalsIgnoreCase("% Identity"))
90         {
91             ret = PID;
92         }
93         else if (name.equalsIgnoreCase("Zappo"))
94         {
95             ret = ZAPPO;
96         }
97         else if (name.equalsIgnoreCase("Taylor"))
98         {
99           ret = TAYLOR;
100         }
101         else if (name.equalsIgnoreCase("Hydrophobic"))
102         {
103             ret = HYDROPHOBIC;
104         }
105         else if (name.equalsIgnoreCase("Helix Propensity"))
106         {
107             ret = HELIX;
108         }
109         else if (name.equalsIgnoreCase("Strand Propensity"))
110         {
111             ret = STRAND;
112         }
113         else if (name.equalsIgnoreCase("Turn Propensity"))
114         {
115             ret = TURN;
116         }
117         else if (name.equalsIgnoreCase("Buried Index"))
118         {
119             ret = BURIED;
120         }
121         else if (name.equalsIgnoreCase("Nucleotide"))
122         {
123             ret = NUCLEOTIDE;
124         }
125         else if (name.equalsIgnoreCase("User Defined"))
126         {
127             ret = USER_DEFINED;
128         }
129
130         return ret;
131     }
132
133     /**
134      * DOCUMENT ME!
135      *
136      * @param cs DOCUMENT ME!
137      *
138      * @return DOCUMENT ME!
139      */
140     public static String getColourName(ColourSchemeI cs)
141     {
142
143         int index = 12;
144
145         if (cs instanceof ClustalxColourScheme)
146         {
147             index = CLUSTAL;
148         }
149         else if (cs instanceof Blosum62ColourScheme)
150         {
151             index = BLOSUM;
152         }
153         else if (cs instanceof PIDColourScheme)
154         {
155             index = PID;
156         }
157         else if (cs instanceof ZappoColourScheme)
158         {
159             index = ZAPPO;
160         }
161         else if (cs instanceof TaylorColourScheme)
162         {
163             index = TAYLOR;
164         }
165         else if (cs instanceof HydrophobicColourScheme)
166         {
167             index = HYDROPHOBIC;
168         }
169         else if (cs instanceof HelixColourScheme)
170         {
171             index = HELIX;
172         }
173         else if (cs instanceof StrandColourScheme)
174         {
175             index = STRAND;
176         }
177         else if (cs instanceof TurnColourScheme)
178         {
179             index = TURN;
180         }
181         else if (cs instanceof BuriedColourScheme)
182         {
183             index = BURIED;
184         }
185         else if (cs instanceof NucleotideColourScheme)
186         {
187             index = NUCLEOTIDE;
188         }
189         else if (cs instanceof UserColourScheme)
190         {
191             index = USER_DEFINED;
192         }
193
194         return getColourName(index);
195     }
196
197     /**
198      * DOCUMENT ME!
199      *
200      * @param index DOCUMENT ME!
201      *
202      * @return DOCUMENT ME!
203      */
204     public static String getColourName(int index)
205     {
206         String ret = null;
207
208         switch (index)
209         {
210         case CLUSTAL:
211             ret = "Clustal";
212
213             break;
214
215         case BLOSUM:
216             ret = "Blosum62";
217
218             break;
219
220         case PID:
221             ret = "% Identity";
222
223             break;
224
225         case ZAPPO:
226             ret = "Zappo";
227
228             break;
229
230         case TAYLOR:
231             ret = "Taylor";
232             break;
233
234         case HYDROPHOBIC:
235             ret = "Hydrophobic";
236
237             break;
238
239         case HELIX:
240             ret = "Helix Propensity";
241
242             break;
243
244         case STRAND:
245             ret = "Strand Propensity";
246
247             break;
248
249         case TURN:
250             ret = "Turn Propensity";
251
252             break;
253
254         case BURIED:
255             ret = "Buried Index";
256
257             break;
258
259         case NUCLEOTIDE:
260             ret = "Nucleotide";
261
262             break;
263
264         case USER_DEFINED:
265             ret = "User Defined";
266
267             break;
268
269         default:
270             ret = "None";
271
272             break;
273         }
274
275         return ret;
276     }
277
278     /**
279      * DOCUMENT ME!
280      *
281      * @param al DOCUMENT ME!
282      * @param name DOCUMENT ME!
283      *
284      * @return DOCUMENT ME!
285      */
286     public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al,
287         String name)
288     {
289         return getColour(al.getSequences(), al.getWidth(), name);
290     }
291
292     /**
293      * DOCUMENT ME!
294      *
295      * @param seqs DOCUMENT ME!
296      * @param width DOCUMENT ME!
297      * @param name DOCUMENT ME!
298      *
299      * @return DOCUMENT ME!
300      */
301     public static ColourSchemeI getColour(java.util.Vector seqs, int width,
302         String name)
303     {
304         return getColour(seqs, width, getColourIndexFromName(name));
305     }
306
307     /**
308      * DOCUMENT ME!
309      *
310      * @param seqs DOCUMENT ME!
311      * @param width DOCUMENT ME!
312      * @param index DOCUMENT ME!
313      *
314      * @return DOCUMENT ME!
315      */
316     public static ColourSchemeI getColour(java.util.Vector seqs, int width,
317         int index)
318     {
319         ColourSchemeI cs = null;
320
321         switch (index)
322         {
323         case CLUSTAL:
324             cs = new ClustalxColourScheme(seqs, width);
325
326             break;
327
328         case BLOSUM:
329             cs = new Blosum62ColourScheme();
330
331             break;
332
333         case PID:
334             cs = new PIDColourScheme();
335
336             break;
337
338         case ZAPPO:
339             cs = new ZappoColourScheme();
340
341             break;
342
343         case TAYLOR:
344             cs = new TaylorColourScheme();
345             break;
346
347         case HYDROPHOBIC:
348             cs = new HydrophobicColourScheme();
349
350             break;
351
352         case HELIX:
353             cs = new HelixColourScheme();
354
355             break;
356
357         case STRAND:
358             cs = new StrandColourScheme();
359
360             break;
361
362         case TURN:
363             cs = new TurnColourScheme();
364
365             break;
366
367         case BURIED:
368             cs = new BuriedColourScheme();
369
370             break;
371
372         case NUCLEOTIDE:
373             cs = new NucleotideColourScheme();
374
375             break;
376
377         case USER_DEFINED:
378           Color[] col = new Color[24];
379           for (int i = 0; i < 24; i++)
380             col[i] = Color.white;
381           cs = new UserColourScheme(col);
382             break;
383
384         default:
385             break;
386         }
387
388         return cs;
389     }
390
391     public static Color getAWTColorFromName(String name)
392     {
393       Color col = null;
394       name = name.toLowerCase();
395       if(name.equals("black"))
396         col = Color.black;
397       else if(name.equals("blue"))
398         col = Color.blue;
399       else if(name.equals("cyan"))
400         col = Color.cyan;
401       else if(name.equals("darkGray"))
402         col = Color.darkGray;
403       else if(name.equals("gray"))
404         col = Color.gray;
405       else if(name.equals("green"))
406         col = Color.green;
407       else if(name.equals("lightGray"))
408         col = Color.lightGray;
409       else if(name.equals("magenta"))
410         col = Color.magenta;
411       else if(name.equals("orange"))
412         col = Color.orange;
413       else if(name.equals("pink"))
414         col = Color.pink;
415       else if(name.equals("red"))
416         col = Color.red;
417       else if(name.equals("white"))
418         col = Color.white;
419       else if(name.equals("yellow"))
420         col = Color.yellow;
421
422       return col;
423     }
424 }