JAL-2228 removed ColumnCounterI, finessed recalc of annotation height
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 18 Jan 2017 16:24:41 +0000 (16:24 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 18 Jan 2017 16:24:41 +0000 (16:24 +0000)
src/jalview/workers/ColumnCounterI.java [deleted file]
src/jalview/workers/ColumnCounterSetWorker.java
src/jalview/workers/FeatureSetCounterI.java

diff --git a/src/jalview/workers/ColumnCounterI.java b/src/jalview/workers/ColumnCounterI.java
deleted file mode 100644 (file)
index 53f1b4b..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- * 
- * This file is part of Jalview.
- * 
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *  
- * Jalview is distributed in the hope that it will be useful, but 
- * WITHOUT ANY WARRANTY; without even the implied warranty 
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
- * PURPOSE.  See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.workers;
-
-/**
- * interfaces that provide counting routines for the newCalculator
- * AlignmentAnnotationFactory methods
- * 
- * @author jprocter
- *
- */
-public interface ColumnCounterI
-{
-
-}
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;
   }
 
   /**
index 3bbf8ec..e14952f 100644 (file)
@@ -26,17 +26,16 @@ import jalview.datamodel.SequenceFeature;
 import java.util.List;
 
 /**
- * Like FeatureCounterI but returns a vector of counts for a set of features
- * 
- * An interface for a type that returns counts of any value of interest at a
- * sequence position that can be determined from the sequence character and any
- * features present at that position
+ * An interface for a type that returns counts (per computed annotation type) of
+ * any value of interest at a sequence position that can be determined from the
+ * sequence character and any features present at that position
  * 
  */
-public interface FeatureSetCounterI extends ColumnCounterI
+public interface FeatureSetCounterI
 {
   /**
-   * Returns counts of some properties of interest, for example
+   * Returns counts (per annotation type) of some properties of interest, for
+   * example
    * <ul>
    * <li>the number of variant features at the position</li>
    * <li>the number of Cath features of status 'True Positive'</li>
@@ -52,7 +51,7 @@ public interface FeatureSetCounterI extends ColumnCounterI
   int[] count(String residue, List<SequenceFeature> features);
 
   /**
-   * Returns names for the annotation that this is counting, for use as the
+   * Returns names for the annotations that this is counting, for use as the
    * displayed labels
    * 
    * @return
@@ -60,7 +59,7 @@ public interface FeatureSetCounterI extends ColumnCounterI
   String[] getNames();
 
   /**
-   * Returns descriptions for the annotation, for display as tooltips
+   * Returns descriptions for the annotations, for display as tooltips
    * 
    * @return
    */