2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\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
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
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
19 package jalview.schemes;
\r
23 import jalview.datamodel.*;
\r
25 public class AnnotationColourGradient extends ResidueColourScheme
\r
27 public static int NO_THRESHOLD = -1;
\r
28 public static int BELOW_THRESHOLD = 0;
\r
29 public static int ABOVE_THRESHOLD = 1;
\r
31 AlignmentAnnotation annotation;
\r
32 int aboveAnnotationThreshold = -1;
\r
34 GraphLine annotationThreshold;
\r
36 float r1, g1, b1, rr, gg, bb, dr, dg, db;
\r
39 ColourSchemeI colourScheme;
\r
42 * Creates a new AnnotationColourGradient object.
\r
44 public AnnotationColourGradient(AlignmentAnnotation annotation,
\r
45 ColourSchemeI originalColour,
\r
48 if(originalColour instanceof AnnotationColourGradient)
\r
50 colourScheme = ((AnnotationColourGradient)originalColour).colourScheme;
\r
53 colourScheme = originalColour;
\r
55 this.annotation = annotation;
\r
57 aboveAnnotationThreshold = aboveThreshold;
\r
59 if(aboveThreshold!=NO_THRESHOLD && annotation.threshold!=null)
\r
60 annotationThreshold = annotation.threshold;
\r
64 * Creates a new AnnotationColourGradient object.
\r
66 public AnnotationColourGradient(AlignmentAnnotation annotation,
\r
67 Color minColour, Color maxColour, int aboveThreshold)
\r
69 this.annotation = annotation;
\r
71 aboveAnnotationThreshold = aboveThreshold;
\r
73 if(aboveThreshold!=NO_THRESHOLD && annotation.threshold!=null)
\r
74 annotationThreshold = annotation.threshold;
\r
76 r1 = minColour.getRed();
\r
77 g1 = minColour.getGreen();
\r
78 b1 = minColour.getBlue();
\r
80 rr = maxColour.getRed() - r1;
\r
81 gg = maxColour.getGreen() - g1;
\r
82 bb = maxColour.getBlue() - b1;
\r
84 range = annotation.graphMax - annotation.graphMin;
\r
88 public Color getMinColour()
\r
90 return new Color( (int) r1, (int) g1, (int) b1);
\r
93 public Color getMaxColour()
\r
95 return new Color( (int) (r1 + rr), (int) (g1 + gg), (int) (b1 + bb));
\r
101 * @param n DOCUMENT ME!
\r
103 * @return DOCUMENT ME!
\r
105 public Color findColour(String n)
\r
113 * @param n DOCUMENT ME!
\r
114 * @param j DOCUMENT ME!
\r
116 * @return DOCUMENT ME!
\r
118 public Color findColour(String n, int j)
\r
120 currentColour = Color.white;
\r
122 if ((threshold == 0) || aboveThreshold(n, j))
\r
124 if( j<annotation.annotations.length
\r
125 && annotation.annotations[j]!=null
\r
126 && !jalview.util.Comparison.isGap(n.charAt(0)))
\r
128 if( aboveAnnotationThreshold==NO_THRESHOLD
\r
129 || (annotationThreshold!=null && aboveAnnotationThreshold==ABOVE_THRESHOLD && annotation.annotations[j].value>=annotationThreshold.value)
\r
130 || (annotationThreshold!=null && aboveAnnotationThreshold==BELOW_THRESHOLD && annotation.annotations[j].value<=annotationThreshold.value))
\r
132 if(colourScheme!=null)
\r
134 currentColour = colourScheme.findColour(n, j);
\r
139 ( (annotation.annotations[j].value - annotation.graphMin) /
\r
143 ( (annotation.annotations[j].value - annotation.graphMin) /
\r
147 ( (annotation.annotations[j].value - annotation.graphMin) /
\r
151 currentColour = new Color( (int) dr, (int) dg, (int) db);
\r
157 if(conservationColouring)
\r
158 applyConservation(j);
\r
160 return currentColour;
\r