JAL-2773 add new flag to paintAlignment(updateOverview,updateStructures) and first...
[jalview.git] / src / jalview / workers / AnnotationWorker.java
index efe707a..8f37f15 100644 (file)
@@ -47,11 +47,11 @@ class AnnotationWorker extends AlignCalcWorker
    * @param af
    * @param counter
    */
-  public AnnotationWorker(AlignViewportI viewport,
-          AlignmentViewPanel panel, AnnotationProviderI counter)
+  public AnnotationWorker(AlignViewportI viewport, AlignmentViewPanel panel,
+          AnnotationProviderI counter)
   {
     super(viewport, panel);
-    ourAnnots = new ArrayList<AlignmentAnnotation>();
+    ourAnnots = new ArrayList<>();
     this.counter = counter;
     calcMan.registerWorker(this);
   }
@@ -79,7 +79,7 @@ class AnnotationWorker extends AlignCalcWorker
         return;
       }
 
-      removeAnnotations();
+      // 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)
         {
@@ -112,21 +121,11 @@ class AnnotationWorker extends AlignCalcWorker
     if (ap != null)
     {
       ap.adjustAnnotationHeight();
-      ap.paintAlignment(true);
+      // TODO: only need to update colour and geometry if panel height changes
+      // and view is coloured by annotation, and the annotation is actually
+      // changed!
+      ap.paintAlignment(true, true);
     }
-
-  }
-
-  /**
-   * Remove all our annotations before re-calculating them
-   */
-  void removeAnnotations()
-  {
-    for (AlignmentAnnotation ann : ourAnnots)
-    {
-      alignViewport.getAlignment().deleteAnnotation(ann);
-    }
-    ourAnnots.clear();
   }
 
   @Override