X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fschemes%2FFeatureColour.java;h=0d36f4f3057f289fc43bf670f632ba99d56c9598;hb=4f77328104498504339216829abf5ea87e2791ec;hp=55fdf243c9984a963d7ca4bc347a5a8185579dec;hpb=e42eed3a0089a8a064560df4cf17a5021fd1e16a;p=jalview.git diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java index 55fdf24..0d36f4f 100644 --- a/src/jalview/schemes/FeatureColour.java +++ b/src/jalview/schemes/FeatureColour.java @@ -25,6 +25,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.features.FeatureMatcher; import jalview.util.ColorUtils; import jalview.util.Format; +import jalview.util.MessageManager; import java.awt.Color; import java.util.StringTokenizer; @@ -50,6 +51,12 @@ import java.util.StringTokenizer; */ public class FeatureColour implements FeatureColourI { + private static final String I18N_LABEL = MessageManager + .getString("label.label"); + + private static final String I18N_SCORE = MessageManager + .getString("label.score"); + private static final String ABSOLUTE = "abso"; private static final String ABOVE = "above"; @@ -316,19 +323,19 @@ public class FeatureColour implements FeatureColourI { if (minval.length() > 0) { - min = new Float(minval).floatValue(); + min = Float.valueOf(minval).floatValue(); } } catch (Exception e) { throw new IllegalArgumentException( - "Couldn't parse the minimum value for graduated colour (" - + descriptor + ")"); + "Couldn't parse the minimum value for graduated colour ('" + + minval + "')"); } try { if (maxval.length() > 0) { - max = new Float(maxval).floatValue(); + max = Float.valueOf(maxval).floatValue(); } } catch (Exception e) { @@ -396,7 +403,7 @@ public class FeatureColour implements FeatureColourI { gcol.nextToken(); tval = gcol.nextToken(); - featureColour.setThreshold(new Float(tval).floatValue()); + featureColour.setThreshold(Float.valueOf(tval).floatValue()); } catch (Exception e) { System.err.println("Couldn't parse threshold value as a float: (" @@ -672,9 +679,12 @@ public class FeatureColour implements FeatureColourI /** * Returns the colour for the given instance of the feature. This may be a - * simple colour, a colour generated from the feature description (if - * isColourByLabel()), or a colour derived from the feature score (if - * isGraduatedColour()). + * simple colour, a colour generated from the feature description or other + * attribute (if isColourByLabel()), or a colour derived from the feature + * score or other attribute (if isGraduatedColour()). + *

+ * Answers null if feature score (or attribute) value lies outside a + * configured threshold. * * @param feature * @return @@ -884,4 +894,78 @@ public class FeatureColour implements FeatureColourI attributeName = name; } + @Override + public boolean isOutwithThreshold(SequenceFeature feature) + { + if (!isGraduatedColour()) + { + return false; + } + float scr = feature.getScore(); + if (attributeName != null) + { + try + { + String attVal = feature.getValueAsString(attributeName); + scr = Float.valueOf(attVal); + } catch (Throwable e) + { + scr = Float.NaN; + } + } + if (Float.isNaN(scr)) + { + return false; + } + + return ((isAboveThreshold() && scr <= threshold) + || (isBelowThreshold() && scr >= threshold)); + } + + @Override + public String getDescription() + { + if (isSimpleColour()) + { + return "r=" + colour.getRed() + ",g=" + colour.getGreen() + ",b=" + + colour.getBlue(); + } + StringBuilder tt = new StringBuilder(); + String by = null; + + if (getAttributeName() != null) + { + by = FeatureMatcher.toAttributeDisplayName(getAttributeName()); + } + else if (isColourByLabel()) + { + by = I18N_LABEL; + } + else + { + by = I18N_SCORE; + } + tt.append(MessageManager.formatMessage("action.by_title_param", by)); + + /* + * add threshold if any + */ + if (isAboveThreshold() || isBelowThreshold()) + { + tt.append(" ("); + if (isColourByLabel()) + { + /* + * Jalview features file supports the combination of + * colour by label or attribute text with score threshold + */ + tt.append(I18N_SCORE).append(" "); + } + tt.append(isAboveThreshold() ? "> " : "< "); + tt.append(getThreshold()).append(")"); + } + + return tt.toString(); + } + }