From: gmungoc Date: Wed, 20 Jul 2016 05:09:01 +0000 (+0100) Subject: JAL-2068 AnnotationWorker create/update annotation, not delete / re-add X-Git-Tag: Release_2_10_0~125^2~13 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6d2246e02a1232760ec873f9b6ee4a775c6b4b7d;p=jalview.git JAL-2068 AnnotationWorker create/update annotation, not delete / re-add --- diff --git a/src/jalview/workers/AlignCalcWorker.java b/src/jalview/workers/AlignCalcWorker.java index 7719c88..771c492 100644 --- a/src/jalview/workers/AlignCalcWorker.java +++ b/src/jalview/workers/AlignCalcWorker.java @@ -26,6 +26,7 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; +import jalview.datamodel.Annotation; import java.util.List; @@ -103,4 +104,33 @@ public abstract class AlignCalcWorker implements AlignCalcWorkerI return false; } + /** + * Calculate min and max values of annotations and set as graphMin, graphMax + * on the AlignmentAnnotation. This is needed because otherwise, well, bad + * things happen. + * + * @param ann + * @param anns + */ + protected void setGraphMinMax(AlignmentAnnotation ann, Annotation[] anns) + { + // TODO feels like this belongs inside AlignmentAnnotation! + float max = Float.MIN_VALUE; + float min = Float.MAX_VALUE; + boolean set = false; + for (Annotation a : anns) { + if (a != null) { + set = true; + float val = a.value; + max = Math.max(max, val); + min = Math.min(min, val); + } + } + if (set) + { + ann.graphMin = min; + ann.graphMax = max; + } + } + } diff --git a/src/jalview/workers/AnnotationWorker.java b/src/jalview/workers/AnnotationWorker.java index 65603d6..4d81307 100644 --- a/src/jalview/workers/AnnotationWorker.java +++ b/src/jalview/workers/AnnotationWorker.java @@ -79,7 +79,7 @@ class AnnotationWorker extends AlignCalcWorker return; } - removeAnnotation(); + // removeAnnotation(); AlignmentI alignment = alignViewport.getAlignment(); if (alignment != null) { @@ -89,10 +89,19 @@ class AnnotationWorker extends AlignCalcWorker alignment, new FeatureRenderer(alignViewport)); for (AlignmentAnnotation ann : anns) { - ann.showAllColLabels = true; - ann.graph = AlignmentAnnotation.BAR_GRAPH; - ourAnnots.add(ann); - alignment.addAnnotation(ann); + AlignmentAnnotation theAnn = alignment.findOrCreateAnnotation( + ann.label, ann.description, false, null, null); + theAnn.showAllColLabels = true; + theAnn.graph = AlignmentAnnotation.BAR_GRAPH; + theAnn.scaleColLabel = true; + theAnn.annotations = ann.annotations; + setGraphMinMax(theAnn, theAnn.annotations); + theAnn.validateRangeAndDisplay(); + if (!ourAnnots.contains(theAnn)) + { + ourAnnots.add(theAnn); + } + // alignment.addAnnotation(ann); } } catch (IndexOutOfBoundsException x) { diff --git a/src/jalview/workers/ColumnCounterWorker.java b/src/jalview/workers/ColumnCounterWorker.java index 4e1a336..2f73cb5 100644 --- a/src/jalview/workers/ColumnCounterWorker.java +++ b/src/jalview/workers/ColumnCounterWorker.java @@ -184,35 +184,6 @@ class ColumnCounterWorker extends AlignCalcWorker } /** - * Calculate min and max values of annotations and set as graphMin, graphMax - * on the AlignmentAnnotation. This is needed because otherwise, well, bad - * things happen. - * - * @param ann - * @param anns - */ - private void setGraphMinMax(AlignmentAnnotation ann, Annotation[] anns) - { - // TODO feels like this belongs inside AlignmentAnnotation! - float max = Float.MIN_VALUE; - float min = Float.MAX_VALUE; - boolean set = false; - for (Annotation a : anns) { - if (a != null) { - set = true; - float val = a.value; - max = Math.max(max, val); - min = Math.min(min, val); - } - } - if (set) - { - ann.graphMin = min; - ann.graphMax = max; - } - } - - /** * Returns a count of any feature types present at the specified position of * the alignment *