2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
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.
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.
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
19 package jalview.schemes;
23 import jalview.datamodel.*;
25 public class AnnotationColourGradient extends ResidueColourScheme
27 public static int NO_THRESHOLD = -1;
28 public static int BELOW_THRESHOLD = 0;
29 public static int ABOVE_THRESHOLD = 1;
31 AlignmentAnnotation annotation;
32 int aboveAnnotationThreshold = -1;
34 GraphLine annotationThreshold;
36 float r1, g1, b1, rr, gg, bb, dr, dg, db;
39 ColourSchemeI colourScheme;
42 * Creates a new AnnotationColourGradient object.
44 public AnnotationColourGradient(AlignmentAnnotation annotation,
45 ColourSchemeI originalColour,
48 if(originalColour instanceof AnnotationColourGradient)
50 colourScheme = ((AnnotationColourGradient)originalColour).colourScheme;
53 colourScheme = originalColour;
55 this.annotation = annotation;
57 aboveAnnotationThreshold = aboveThreshold;
59 if(aboveThreshold!=NO_THRESHOLD && annotation.threshold!=null)
60 annotationThreshold = annotation.threshold;
64 * Creates a new AnnotationColourGradient object.
66 public AnnotationColourGradient(AlignmentAnnotation annotation,
67 Color minColour, Color maxColour, int aboveThreshold)
69 this.annotation = annotation;
71 aboveAnnotationThreshold = aboveThreshold;
73 if(aboveThreshold!=NO_THRESHOLD && annotation.threshold!=null)
74 annotationThreshold = annotation.threshold;
76 r1 = minColour.getRed();
77 g1 = minColour.getGreen();
78 b1 = minColour.getBlue();
80 rr = maxColour.getRed() - r1;
81 gg = maxColour.getGreen() - g1;
82 bb = maxColour.getBlue() - b1;
84 range = annotation.graphMax - annotation.graphMin;
89 public String getAnnotation()
91 return annotation.label;
94 public int getAboveThreshold()
96 return aboveAnnotationThreshold;
99 public float getAnnotationThreshold()
101 if(annotationThreshold==null)
104 return annotationThreshold.value;
107 public ColourSchemeI getBaseColour()
112 public Color getMinColour()
114 return new Color( (int) r1, (int) g1, (int) b1);
117 public Color getMaxColour()
119 return new Color( (int) (r1 + rr), (int) (g1 + gg), (int) (b1 + bb));
125 * @param n DOCUMENT ME!
127 * @return DOCUMENT ME!
129 public Color findColour(String n)
137 * @param n DOCUMENT ME!
138 * @param j DOCUMENT ME!
140 * @return DOCUMENT ME!
142 public Color findColour(String n, int j)
144 currentColour = Color.white;
146 if ((threshold == 0) || aboveThreshold(n, j))
148 if( j<annotation.annotations.length
149 && annotation.annotations[j]!=null
150 && !jalview.util.Comparison.isGap(n.charAt(0)))
152 if( aboveAnnotationThreshold==NO_THRESHOLD
153 || (annotationThreshold!=null && aboveAnnotationThreshold==ABOVE_THRESHOLD && annotation.annotations[j].value>=annotationThreshold.value)
154 || (annotationThreshold!=null && aboveAnnotationThreshold==BELOW_THRESHOLD && annotation.annotations[j].value<=annotationThreshold.value))
156 if(colourScheme!=null)
158 currentColour = colourScheme.findColour(n, j);
163 ( (annotation.annotations[j].value - annotation.graphMin) /
167 ( (annotation.annotations[j].value - annotation.graphMin) /
171 ( (annotation.annotations[j].value - annotation.graphMin) /
175 currentColour = new Color( (int) dr, (int) dg, (int) db);
181 if(conservationColouring)
182 applyConservation(j);
184 return currentColour;