apply jalview code style
[jalview.git] / src / jalview / gui / AlignViewport.java
index 2791ffc..6f713fc 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
@@ -433,7 +433,8 @@ public class AlignViewport implements SelectionSource
     showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
             false);
     sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
-    followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS", true); 
+    followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
+            true);
   }
 
   /**
@@ -477,11 +478,6 @@ public class AlignViewport implements SelectionSource
   private boolean shownpfeats;
 
   /**
-   * consensus annotation includes all percentage for all symbols in column
-   */
-  private boolean includeAllConsensusSymbols = true;
-
-  /**
    * trigger update of conservation annotation
    */
   public void updateConservation(final AlignmentPanel ap)
@@ -556,11 +552,9 @@ public class AlignViewport implements SelectionSource
         consensus.annotations = new Annotation[aWidth];
 
         hconsensus = new Hashtable[aWidth];
-        AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
-                .getWidth(), hconsensus, includeAllConsensusSymbols);
-        AAFrequency.completeConsensus(consensus, hconsensus, 0, aWidth,
-                ignoreGapsInConsensusCalculation,
-                includeAllConsensusSymbols);
+        AAFrequency.calculate(alignment.getSequencesArray(), 0,
+                alignment.getWidth(), hconsensus, true);
+        updateAnnotation(true);
 
         if (globalColourScheme != null)
         {
@@ -583,6 +577,28 @@ public class AlignViewport implements SelectionSource
         ap.paintAlignment(true);
       }
     }
+
+    /**
+     * update the consensus annotation from the sequence profile data using
+     * current visualization settings.
+     */
+    public void updateAnnotation()
+    {
+      updateAnnotation(false);
+    }
+
+    protected void updateAnnotation(boolean immediate)
+    {
+      // TODO: make calls thread-safe, so if another thread calls this method,
+      // it will either return or wait until one calculation is finished.
+      if (immediate
+              || (!updatingConsensus && consensus != null && hconsensus != null))
+      {
+        AAFrequency.completeConsensus(consensus, hconsensus, 0,
+                hconsensus.length, ignoreGapsInConsensusCalculation,
+                showSequenceLogo);
+      }
+    }
   }
 
   /**
@@ -1837,8 +1853,8 @@ public class AlignViewport implements SelectionSource
       {
         Alignment al = (Alignment) alignment;
         Conservation c = new Conservation("All",
-                ResidueProperties.propHash, 3, al.getSequences(), 0, al
-                        .getWidth() - 1);
+                ResidueProperties.propHash, 3, al.getSequences(), 0,
+                al.getWidth() - 1);
         c.calculate();
         c.verdict(false, ConsPercGaps);
 
@@ -1852,8 +1868,8 @@ public class AlignViewport implements SelectionSource
       SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
       if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
       {
-        ((ClustalxColourScheme) sg.cs).resetClustalX(sg
-                .getSequences(hiddenRepSequences), sg.getWidth());
+        ((ClustalxColourScheme) sg.cs).resetClustalX(
+                sg.getSequences(hiddenRepSequences), sg.getWidth());
       }
       sg.recalcConservation();
     }
@@ -2206,6 +2222,16 @@ public class AlignViewport implements SelectionSource
    */
   public void setShowSequenceLogo(boolean showSequenceLogo)
   {
+    if (showSequenceLogo != this.showSequenceLogo)
+    {
+      // TODO: decouple settings setting from calculation when refactoring
+      // annotation update method from alignframe to viewport
+      this.showSequenceLogo = showSequenceLogo;
+      if (consensusThread != null)
+      {
+        consensusThread.updateAnnotation();
+      }
+    }
     this.showSequenceLogo = showSequenceLogo;
   }
 
@@ -2253,24 +2279,6 @@ public class AlignViewport implements SelectionSource
   }
 
   /**
-   * @return the includeAllConsensusSymbols
-   */
-  public boolean isIncludeAllConsensusSymbols()
-  {
-    return includeAllConsensusSymbols;
-  }
-
-  /**
-   * @param includeAllConsensusSymbols
-   *          the includeAllConsensusSymbols to set
-   */
-  public void setIncludeAllConsensusSymbols(
-          boolean includeAllConsensusSymbols)
-  {
-    this.includeAllConsensusSymbols = includeAllConsensusSymbols;
-  }
-
-  /**
    * 
    * @return flag to indicate if the consensus histogram should be rendered by
    *         default