From 51f87c0026052e327ab4eaf24f8e4dadca96a615 Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 17 Mar 2009 16:58:35 +0000 Subject: [PATCH] holds shading and range parameters rendering a feature colour --- src/jalview/schemes/GraduatedColor.java | 156 +++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 src/jalview/schemes/GraduatedColor.java diff --git a/src/jalview/schemes/GraduatedColor.java b/src/jalview/schemes/GraduatedColor.java new file mode 100644 index 0000000..25681c4 --- /dev/null +++ b/src/jalview/schemes/GraduatedColor.java @@ -0,0 +1,156 @@ +/** + * + */ +package jalview.schemes; + +import jalview.datamodel.SequenceFeature; + +import java.awt.Color; + +/** + * Value and/or thresholded colour scale used for colouring by annotation and feature score + * @author JimP + * + */ +public class GraduatedColor +{ + int thresholdState = AnnotationColourGradient.NO_THRESHOLD; // or ABOVE_THRESHOLD or BELOW_THRESHOLD + float lr,lg,lb,dr,dg,db; + /** + * linear scaling parameters, base, minimum colour threshold, range of linear scale from lower to upper + */ + float base,range,thrsh; + /** + * when true, colour from u to u-d rather than u to u+d + */ + boolean tolow=false; + /** + * construct a graduatedColor object from simple parameters + * @param low + * @param high + * @param min + * @param max + * color low->high from min->max + */ + public GraduatedColor(Color low,Color high, float min,float max) + { + thrsh = Float.NaN; + tolow = min>=max; + lr = low.getRed()/255f; + lg = low.getGreen()/255f; + lb = low.getBlue()/255f; + dr = (high.getRed()/255f)-lr; + dg = (high.getGreen()/255f)-lg; + db = (high.getBlue()/255f)-lb; + if (tolow) + { + base = max; + range = min-max; + } else { + base = min; + range = max-min; + } + } + public GraduatedColor(GraduatedColor oldcs) + { + lr = oldcs.lr; + lg = oldcs.lg; + lb = oldcs.lb; + dr = oldcs.dr; + dg = oldcs.dg; + db = oldcs.db; + base = oldcs.base; + range = oldcs.range; + tolow = oldcs.tolow; + thresholdState = oldcs.thresholdState; + thrsh = oldcs.thrsh; + } + /** + * make a new gradient from an old one with a different scale range + * @param oldcs + * @param min + * @param max + */ + public GraduatedColor(GraduatedColor oldcs, float min, float max) + { + this(oldcs); + if (max1f) { scl = 1f; } + return new Color(lr+scl*dr,lg+scl*dg,lb+scl*db); + } + public void setThresh(float value) + { + thrsh = value; + } + public void setThreshType(int aboveThreshold) + { + thresholdState = aboveThreshold; + } + public int getThreshType() + { + return thresholdState; + } +} -- 1.7.10.2