JAL-2068 AnnotationWorker create/update annotation, not delete / re-add
[jalview.git] / src / jalview / workers / ColumnCounterWorker.java
index 947b3c7..2f73cb5 100644 (file)
@@ -89,7 +89,6 @@ class ColumnCounterWorker extends AlignCalcWorker
         return;
       }
 
-      removeAnnotation();
       if (alignViewport.getAlignment() != null)
       {
         try
@@ -159,20 +158,29 @@ class ColumnCounterWorker extends AlignCalcWorker
       {
         Color color = ColorUtils.getGraduatedColour(count, 0, Color.cyan,
                 max, Color.blue);
-        anns[i] = new Annotation(String.valueOf(count),
-                String.valueOf(count), '0', count, color);
+        String str = String.valueOf(count);
+        anns[i] = new Annotation(str, str, '0', count, color);
       }
     }
 
     /*
-     * construct the annotation, save it and add it to the displayed alignment
+     * construct or update the annotation
      */
-    AlignmentAnnotation ann = new AlignmentAnnotation(counter.getName(),
-            counter.getDescription(), anns);
+    AlignmentAnnotation ann = alignViewport.getAlignment()
+            .findOrCreateAnnotation(counter.getName(),
+                    counter.getDescription(), false, null,
+                    null);
+    ann.description = counter.getDescription();
     ann.showAllColLabels = true;
+    ann.scaleColLabel = true;
     ann.graph = AlignmentAnnotation.BAR_GRAPH;
-    ourAnnots.add(ann);
-    alignViewport.getAlignment().addAnnotation(ann);
+    ann.annotations = anns;
+    setGraphMinMax(ann, anns);
+    ann.validateRangeAndDisplay();
+    if (!ourAnnots.contains(ann))
+    {
+      ourAnnots.add(ann);
+    }
   }
 
   /**