New files
[jalview.git] / src / jalview / schemes / AnnotationColourGradient.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */\r
19 package jalview.schemes;\r
20 \r
21 import java.awt.*;\r
22 \r
23 import jalview.datamodel.*;\r
24 \r
25 public class AnnotationColourGradient extends ResidueColourScheme\r
26 {\r
27     AlignmentAnnotation annotation;\r
28     float minCol, maxCol, minValue, maxValue;\r
29     boolean aboveAnnotationThreshold = false;\r
30 \r
31     float r1, g1, b1, rr, gg, bb, dr, dg, db;\r
32     float range;\r
33 \r
34     /**\r
35      * Creates a new AnnotationColourGradient object.\r
36      */\r
37     public AnnotationColourGradient(AlignmentAnnotation annotation,\r
38         Color minColour, Color maxColour, boolean aboveThreshold)\r
39     {\r
40       this.annotation = annotation;\r
41 \r
42       aboveAnnotationThreshold = aboveThreshold;\r
43 \r
44       r1 = minColour.getRed();\r
45       g1 = minColour.getGreen();\r
46       b1 = minColour.getBlue();\r
47 \r
48       rr = maxColour.getRed() - r1;\r
49       gg = maxColour.getGreen() - g1;\r
50       bb = maxColour.getBlue() - b1;\r
51 \r
52       range = annotation.graphMax - annotation.graphMin;\r
53 \r
54     }\r
55 \r
56     /**\r
57      * DOCUMENT ME!\r
58      *\r
59      * @param n DOCUMENT ME!\r
60      *\r
61      * @return DOCUMENT ME!\r
62      */\r
63     public Color findColour(String n)\r
64     {\r
65       System.out.println("AnnotationColourGradient findColour(string)");\r
66         return Color.RED;\r
67     }\r
68 \r
69     /**\r
70      * DOCUMENT ME!\r
71      *\r
72      * @param n DOCUMENT ME!\r
73      * @param j DOCUMENT ME!\r
74      *\r
75      * @return DOCUMENT ME!\r
76      */\r
77     public Color findColour(String n, int j)\r
78     {\r
79         if ((threshold == 0) || aboveThreshold(n, j))\r
80         {\r
81           if(annotation.annotations[j]==null)\r
82             currentColour = Color.white;\r
83           else\r
84           {\r
85             if(!aboveAnnotationThreshold || (annotation.graphLines!=null\r
86                && annotation.annotations[j].value>=annotation.getGraphLine(0).value))\r
87             {\r
88                 dr = rr *\r
89                      ((annotation.annotations[j].value-annotation.graphMin) / range )\r
90                      +r1;\r
91                 dg = gg *\r
92                      ((annotation.annotations[j].value-annotation.graphMin)  / range )\r
93                      +g1;\r
94                 db = bb *\r
95                      ((annotation.annotations[j].value-annotation.graphMin) / range )\r
96                      +b1;\r
97 \r
98                  currentColour = new Color( (int) dr, (int) dg, (int) db);\r
99             }\r
100             else\r
101               currentColour = Color.white;\r
102           }\r
103         }\r
104         else\r
105         {\r
106             return Color.white;\r
107         }\r
108 \r
109         if(conservationColouring)\r
110          applyConservation(j);\r
111 \r
112        return currentColour;\r
113     }\r
114 }\r