From 51904e34c4fa66504e19ec0a984e4ce6d9031c44 Mon Sep 17 00:00:00 2001 From: soares Date: Tue, 3 Mar 2020 20:40:03 +0000 Subject: [PATCH] JAL-3468 Adapted methods to report how many features have been dropped from the tooltip, and add final note to tooltip. Backward compatible methods left in. --- src/jalview/gui/SeqPanel.java | 19 ++++-- src/jalview/io/SequenceAnnotationReport.java | 87 ++++++++++++++++++++------ 2 files changed, 84 insertions(+), 22 deletions(-) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 75bf0cc..796d339 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1042,12 +1042,14 @@ public class SeqPanel extends JPanel * add features that straddle the gap (pos may be the residue before or * after the gap) */ + int unshownFeatures = 0; if (av.isShowSequenceFeatures()) { List features = ap.getFeatureRenderer() .findFeaturesAtColumn(sequence, column + 1); - seqARep.appendFeatures(tooltipText, pos, features, - this.ap.getSeqPanel().seqCanvas.fr); + unshownFeatures = seqARep.appendFeaturesLengthLimit(tooltipText, pos, + features, + this.ap.getSeqPanel().seqCanvas.fr, MAX_TOOLTIP_LENGTH); /* * add features in CDS/protein complement at the corresponding @@ -1065,7 +1067,9 @@ public class SeqPanel extends JPanel pos); if (mf != null) { - seqARep.appendFeatures(tooltipText, pos, mf, fr2); + unshownFeatures = seqARep.appendFeaturesLengthLimit( + tooltipText, pos, mf, fr2, + MAX_TOOLTIP_LENGTH); } } } @@ -1080,7 +1084,14 @@ public class SeqPanel extends JPanel if (tooltipText.length() > MAX_TOOLTIP_LENGTH) // constant { tooltipText.setLength(MAX_TOOLTIP_LENGTH); - tooltipText.append("..."); + tooltipText.append("...TOOLONG!"); + } + if (unshownFeatures > 0) + { + tooltipText.append("
").append("... ").append("") + .append(unshownFeatures) + .append(" feature").append(unshownFeatures == 1 ? "" : "s") + .append(" not shown"); } String textString = tooltipText.toString(); if (lastTooltip == null || !lastTooltip.equals(textString)) diff --git a/src/jalview/io/SequenceAnnotationReport.java b/src/jalview/io/SequenceAnnotationReport.java index df28ea3..9d82d66 100644 --- a/src/jalview/io/SequenceAnnotationReport.java +++ b/src/jalview/io/SequenceAnnotationReport.java @@ -126,37 +126,65 @@ public class SequenceAnnotationReport } /** - * Append text for the list of features to the tooltip + * Append text for the list of features to the tooltip Returns number of + * features left if maxlength limit is (or would have been) reached * * @param sb * @param residuePos * @param features * @param minmax + * @param maxlength */ - public void appendFeatures(final StringBuilder sb, int residuePos, - List features, FeatureRendererModel fr) + public int appendFeaturesLengthLimit(final StringBuilder sb, + int residuePos, List features, + FeatureRendererModel fr, int maxlength) { - for (SequenceFeature feature : features) + for (int i = 0; i < features.size(); i++) { - appendFeature(sb, residuePos, fr, feature, null); + SequenceFeature feature = features.get(i); + if (appendFeature(sb, residuePos, fr, feature, null, maxlength)) + { + return features.size() - i; + } } + return 0; + } + + public void appendFeatures(final StringBuilder sb, int residuePos, + List features, FeatureRendererModel fr) + { + appendFeaturesLengthLimit(sb, residuePos, features, fr, 0); } /** * Appends text for mapped features (e.g. CDS feature for peptide or vice versa) + * Returns number of features left if maxlength limit is (or would have been) + * reached * * @param sb * @param residuePos * @param mf * @param fr + * @param maxlength */ - public void appendFeatures(StringBuilder sb, int residuePos, - MappedFeatures mf, FeatureRendererModel fr) + public int appendFeaturesLengthLimit(StringBuilder sb, int residuePos, + MappedFeatures mf, FeatureRendererModel fr, int maxlength) { - for (SequenceFeature feature : mf.features) + for (int i = 0; i < mf.features.size(); i++) { - appendFeature(sb, residuePos, fr, feature, mf); + SequenceFeature feature = mf.features.get(i); + if (appendFeature(sb, residuePos, fr, feature, mf, maxlength)) + { + return mf.features.size() - i; + } } + return 0; + } + + public void appendFeatures(StringBuilder sb, int residuePos, + MappedFeatures mf, FeatureRendererModel fr) + { + appendFeaturesLengthLimit(sb, residuePos, mf, fr, 0); } /** @@ -167,27 +195,28 @@ public class SequenceAnnotationReport * @param minmax * @param feature */ - void appendFeature(final StringBuilder sb, int rpos, + boolean appendFeature(final StringBuilder sb0, int rpos, FeatureRendererModel fr, SequenceFeature feature, - MappedFeatures mf) + MappedFeatures mf, int maxlength) { + StringBuilder sb = new StringBuilder(); if (feature.isContactFeature()) { if (feature.getBegin() == rpos || feature.getEnd() == rpos) { if (sb.length() > 6) { - sb.append("
"); + sb.append("
"); } sb.append(feature.getType()).append(" ").append(feature.getBegin()) .append(":").append(feature.getEnd()); } - return; + return appendTextMaxLengthReached(sb0, sb, maxlength); } - if (sb.length() > 6) + if (sb0.length() > 6) { - sb.append("
"); + sb.append("
"); } // TODO: remove this hack to display link only features boolean linkOnly = feature.getValue("linkonly") != null; @@ -219,6 +248,7 @@ public class SequenceAnnotationReport description = description.substring(0, MAX_DESCRIPTION_LENGTH) + ELLIPSIS; } + sb.append("; ").append(description); } @@ -259,6 +289,27 @@ public class SequenceAnnotationReport } } } + return appendTextMaxLengthReached(sb0, sb, maxlength); + } + + void appendFeature(final StringBuilder sb, int rpos, + FeatureRendererModel fr, SequenceFeature feature, + MappedFeatures mf) + { + appendFeature(sb, rpos, fr, feature, mf, 0); + } + + private static boolean appendTextMaxLengthReached(StringBuilder sb0, + StringBuilder sb, int maxlength) + { + boolean ret = false; + if (maxlength == 0 || sb0.length() + sb.length() < maxlength) + { + sb0.append(sb); + return false; + } else { + return true; + } } /** @@ -475,7 +526,7 @@ public class SequenceAnnotationReport countForSource++; if (countForSource == 1 || !summary) { - sb.append("
"); + sb.append("
"); } if (countForSource <= MAX_REFS_PER_SOURCE || !summary) { @@ -501,11 +552,11 @@ public class SequenceAnnotationReport } if (moreSources) { - sb.append("
").append(source).append(COMMA).append(ELLIPSIS); + sb.append("
").append(source).append(COMMA).append(ELLIPSIS); } if (ellipsis) { - sb.append("
("); + sb.append("
("); sb.append(MessageManager.getString("label.output_seq_details")); sb.append(")"); } -- 1.7.10.2