Get min and max colour added
[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     boolean aboveAnnotationThreshold = false;\r
29 \r
30     float r1, g1, b1, rr, gg, bb, dr, dg, db;\r
31     float range;\r
32 \r
33     /**\r
34      * Creates a new AnnotationColourGradient object.\r
35      */\r
36     public AnnotationColourGradient(AlignmentAnnotation annotation,\r
37         Color minColour, Color maxColour, boolean aboveThreshold)\r
38     {\r
39       this.annotation = annotation;\r
40 \r
41       aboveAnnotationThreshold = aboveThreshold;\r
42 \r
43       r1 = minColour.getRed();\r
44       g1 = minColour.getGreen();\r
45       b1 = minColour.getBlue();\r
46 \r
47       rr = maxColour.getRed() - r1;\r
48       gg = maxColour.getGreen() - g1;\r
49       bb = maxColour.getBlue() - b1;\r
50 \r
51       range = annotation.graphMax - annotation.graphMin;\r
52 \r
53     }\r
54 \r
55     public Color getMinColour()\r
56     {\r
57       return new Color( (int) r1, (int) g1, (int) b1);\r
58     }\r
59 \r
60     public Color getMaxColour()\r
61     {\r
62       return new Color( (int) (r1 + rr), (int) (g1 + gg), (int) (b1 + bb));\r
63     }\r
64 \r
65     /**\r
66      * DOCUMENT ME!\r
67      *\r
68      * @param n DOCUMENT ME!\r
69      *\r
70      * @return DOCUMENT ME!\r
71      */\r
72     public Color findColour(String n)\r
73     {\r
74       System.out.println("AnnotationColourGradient findColour(string)");\r
75         return Color.RED;\r
76     }\r
77 \r
78     /**\r
79      * DOCUMENT ME!\r
80      *\r
81      * @param n DOCUMENT ME!\r
82      * @param j DOCUMENT ME!\r
83      *\r
84      * @return DOCUMENT ME!\r
85      */\r
86     public Color findColour(String n, int j)\r
87     {\r
88         if ((threshold == 0) || aboveThreshold(n, j))\r
89         {\r
90           if(annotation.annotations[j]==null)\r
91             currentColour = Color.white;\r
92           else\r
93           {\r
94             if(!aboveAnnotationThreshold || (annotation.graphLines!=null\r
95                && annotation.annotations[j].value>=annotation.getGraphLine(0).value))\r
96             {\r
97                 dr = rr *\r
98                      ((annotation.annotations[j].value-annotation.graphMin) / range )\r
99                      +r1;\r
100                 dg = gg *\r
101                      ((annotation.annotations[j].value-annotation.graphMin)  / range )\r
102                      +g1;\r
103                 db = bb *\r
104                      ((annotation.annotations[j].value-annotation.graphMin) / range )\r
105                      +b1;\r
106 \r
107                  currentColour = new Color( (int) dr, (int) dg, (int) db);\r
108             }\r
109             else\r
110               currentColour = Color.white;\r
111           }\r
112         }\r
113         else\r
114         {\r
115             return Color.white;\r
116         }\r
117 \r
118         if(conservationColouring)\r
119          applyConservation(j);\r
120 \r
121        return currentColour;\r
122     }\r
123 }\r