2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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;
21 import jalview.datamodel.SequenceFeature;
23 import java.awt.Color;
26 * Value and/or thresholded colour scale used for colouring by annotation and feature score
30 public class GraduatedColor
32 int thresholdState = AnnotationColourGradient.NO_THRESHOLD; // or ABOVE_THRESHOLD or BELOW_THRESHOLD
33 float lr,lg,lb,dr,dg,db;
35 * linear scaling parameters, base, minimum colour threshold, range of linear scale from lower to upper
37 float base,range,thrsh;
39 * when true, colour from u to u-d rather than u to u+d
43 * when false, min/max range has been manually set so should not be dynamically adjusted.
45 boolean autoScale = true;
47 * construct a graduatedColor object from simple parameters
52 * color low->high from min->max
54 public GraduatedColor(Color low,Color high, float min,float max)
58 lr = low.getRed()/255f;
59 lg = low.getGreen()/255f;
60 lb = low.getBlue()/255f;
61 dr = (high.getRed()/255f)-lr;
62 dg = (high.getGreen()/255f)-lg;
63 db = (high.getBlue()/255f)-lb;
73 public GraduatedColor(GraduatedColor oldcs)
84 thresholdState = oldcs.thresholdState;
86 autoScale = oldcs.autoScale;
89 * make a new gradient from an old one with a different scale range
94 public GraduatedColor(GraduatedColor oldcs, float min, float max)
97 updateBounds(min, max);
99 public Color getMinColor()
101 return new Color(lr,lg,lb);
103 public Color getMaxColor()
105 return new Color(lr+dr,lg+dg,lb+db);
107 public boolean getTolow()
111 public void setTolow(boolean tolower)
115 public boolean isColored(SequenceFeature feature)
117 float val = feature.getScore();
122 if (this.thresholdState==AnnotationColourGradient.NO_THRESHOLD)
126 if (this.thrsh==Float.NaN)
130 boolean rtn = thresholdState==AnnotationColourGradient.ABOVE_THRESHOLD;
133 return !rtn; // ? !tolow : tolow;
135 return rtn; // ? tolow : !tolow;
138 public Color findColor(SequenceFeature feature)
142 return getMaxColor();
144 float scr = feature.getScore();
147 return getMinColor();
149 float scl = (scr-base)/range;
150 if (tolow) { scl = -scl; }
151 if (scl<0f) { scl = 0f; }
152 if (scl>1f) { scl = 1f; }
153 return new Color(lr+scl*dr,lg+scl*dg,lb+scl*db);
155 public void setThresh(float value)
159 public float getThresh() {
162 public void setThreshType(int aboveThreshold)
164 thresholdState = aboveThreshold;
166 public int getThreshType()
168 return thresholdState;
170 public float getMax()
172 // regenerate the original values passed in to the constructor
173 return (tolow) ? base : (base + range);
175 public float getMin()
177 // regenerate the original value passed in to the constructor
178 return (tolow) ? (base+range) : base;
180 public boolean isAutoScale()
184 public void setAutoScaled(boolean autoscale) {
185 autoScale = autoscale;
188 * update the base and range appropriatly for the given minmax range
189 * @param a float[] {min,max} array containing minmax range for the associated score values
191 public void updateBounds(float min,float max)