JAL-2228 removed ColumnCounterI, finessed recalc of annotation height
[jalview.git] / src / jalview / workers / ColumnCounterSetWorker.java
index e1cbd2a..6c5707d 100644 (file)
@@ -69,6 +69,7 @@ class ColumnCounterSetWorker extends AlignCalcWorker
   @Override
   public void run()
   {
+    boolean annotationAdded = false;
     try
     {
       calcMan.notifyStart(this);
@@ -93,7 +94,7 @@ class ColumnCounterSetWorker extends AlignCalcWorker
       {
         try
         {
-          computeAnnotations();
+          annotationAdded = computeAnnotations();
         } catch (IndexOutOfBoundsException x)
         {
           // probable race condition. just finish and return without any fuss.
@@ -111,7 +112,10 @@ class ColumnCounterSetWorker extends AlignCalcWorker
 
     if (ap != null)
     {
-      ap.adjustAnnotationHeight();
+      if (annotationAdded)
+      {
+        ap.adjustAnnotationHeight();
+      }
       ap.paintAlignment(true);
     }
 
@@ -120,8 +124,10 @@ class ColumnCounterSetWorker extends AlignCalcWorker
   /**
    * Scan each column of the alignment to calculate a count by feature type. Set
    * the count as the value of the alignment annotation for that feature type.
+   * 
+   * @return
    */
-  void computeAnnotations()
+  boolean computeAnnotations()
   {
     FeatureRenderer fr = new FeatureRenderer(alignViewport);
     // TODO use the commented out code once JAL-2075 is fixed
@@ -170,6 +176,9 @@ class ColumnCounterSetWorker extends AlignCalcWorker
         max[crow] = Math.max(count[crow], max[crow]);
       }
     }
+
+    boolean annotationAdded = false;
+
     for (int anrow = 0; anrow < rows; anrow++)
     {
       Annotation[] anns = new Annotation[width];
@@ -192,9 +201,12 @@ class ColumnCounterSetWorker extends AlignCalcWorker
        * construct or update the annotation
        */
       String description = counter.getDescriptions()[anrow];
-      AlignmentAnnotation ann = alignViewport.getAlignment()
-              .findOrCreateAnnotation(counter.getNames()[anrow],
-                      description, false, null, null);
+      if (!alignment.findAnnotation(description).iterator().hasNext())
+      {
+        annotationAdded = true;
+      }
+      AlignmentAnnotation ann = alignment.findOrCreateAnnotation(
+              counter.getNames()[anrow], description, false, null, null);
       ann.description = description;
       ann.showAllColLabels = true;
       ann.scaleColLabel = true;
@@ -207,6 +219,7 @@ class ColumnCounterSetWorker extends AlignCalcWorker
         ourAnnots.add(ann);
       }
     }
+    return annotationAdded;
   }
 
   /**