Merge branch 'develop' into features/mchmmer
[jalview.git] / src / jalview / workers / InformationThread.java
index 2abfc69..8f8dac5 100644 (file)
@@ -15,9 +15,9 @@ import java.util.List;
 
 public class InformationThread extends AlignCalcWorker
 {
-  
+
   Float max = 0f;
-  
+
   /**
    * Constructor for information thread.
    * 
@@ -25,107 +25,102 @@ public class InformationThread extends AlignCalcWorker
    * @param alignPanel
    */
   public InformationThread(AlignViewportI alignViewport,
-            AlignmentViewPanel alignPanel)
+          AlignmentViewPanel alignPanel)
+  {
+    super(alignViewport, alignPanel);
+  }
+
+  @Override
+  public void run()
+  {
+    if (calcMan.isPending(this))
     {
-      super(alignViewport, alignPanel);
+      return;
     }
+    calcMan.notifyStart(this);
+    long started = System.currentTimeMillis();
 
-    @Override
-    public void run()
+    List<AlignmentAnnotation> information = getInformationAnnotations();
+    try
     {
-      if (calcMan.isPending(this))
+      if ((information == null) || calcMan.isPending(this))
       {
+        calcMan.workerComplete(this);
         return;
       }
-      calcMan.notifyStart(this);
-      long started = System.currentTimeMillis();
-
-    List<AlignmentAnnotation> information = getInformationAnnotations();
-      try
+      while (!calcMan.notifyWorking(this))
       {
-      if ((information == null) || calcMan.isPending(this))
-        {
-          calcMan.workerComplete(this);
-          return;
-        }
-        while (!calcMan.notifyWorking(this))
-        {
-          // System.err.println("Thread
+        // System.err.println("Thread
         // (Information"+Thread.currentThread().getName()+") Waiting around.");
-          try
-          {
-            if (ap != null)
-            {
-              ap.paintAlignment(false);
-            }
-            Thread.sleep(200);
-          } catch (Exception ex)
+        try
+        {
+          if (ap != null)
           {
-            ex.printStackTrace();
+            ap.paintAlignment(false, false);
           }
-        }
-        if (alignViewport.isClosed())
+          Thread.sleep(200);
+        } catch (Exception ex)
         {
-          abortAndDestroy();
-          return;
+          ex.printStackTrace();
         }
-        AlignmentI alignment = alignViewport.getAlignment();
+      }
+      if (alignViewport.isClosed())
+      {
+        abortAndDestroy();
+        return;
+      }
+      AlignmentI alignment = alignViewport.getAlignment();
 
-        int aWidth = -1;
+      int aWidth = -1;
 
-        if (alignment == null || (aWidth = alignment.getWidth()) < 0)
-        {
-          calcMan.workerComplete(this);
-          return;
-        }
+      if (alignment == null || (aWidth = alignment.getWidth()) < 0)
+      {
+        calcMan.workerComplete(this);
+        return;
+      }
 
       eraseInformation(aWidth);
       computeInformation(alignment);
-        updateResultAnnotation(true);
+      updateResultAnnotation(true);
 
-        if (ap != null)
-        {
-          ap.paintAlignment(true);
-        }
-      } catch (OutOfMemoryError error)
+      if (ap != null)
       {
-        calcMan.disableWorker(this);
+        ap.paintAlignment(true, true);
+      }
+    } catch (OutOfMemoryError error)
+    {
+      calcMan.disableWorker(this);
       ap.raiseOOMWarning("calculating information", error);
     } finally
     {
       calcMan.workerComplete(this);
-      }
-
-
-
     }
+  }
 
-    /**
+  /**
    * Clear out any existing information annotations
    * 
    * @param aWidth
    *          the width (number of columns) of the annotated alignment
    */
   protected void eraseInformation(int aWidth)
-    {
+  {
 
     List<AlignmentAnnotation> information = getInformationAnnotations();
     for (AlignmentAnnotation info : information)
     {
       info.annotations = new Annotation[aWidth];
     }
-    }
-
+  }
 
-    /**
+  /**
    * Computes the profiles from a HMM for an alignment.
    * 
    * @param alignment
    */
   protected void computeInformation(AlignmentI alignment)
-    {
-
-      int width = alignment.getWidth();
+  {
+    int width = alignment.getWidth();
     List<SequenceI> hmmSeqs = alignment.getHMMConsensusSequences(false);
     int index = 0;
 
@@ -139,80 +134,79 @@ public class InformationThread extends AlignCalcWorker
       // setColourSchemeInformation(hinformation);
       index++;
     }
-    }
+  }
 
-    /**
+  /**
    * gets the sequences on the alignment on the viewport.
    * 
    * @return
    */
-    protected SequenceI[] getSequences()
-    {
-      return alignViewport.getAlignment().getSequencesArray();
-    }
+  protected SequenceI[] getSequences()
+  {
+    return alignViewport.getAlignment().getSequencesArray();
+  }
 
   protected void setColourSchemeInformation(ProfilesI information)
+  {
+    ResidueShaderI cs = alignViewport.getResidueShading();
+    if (cs != null)
     {
-      ResidueShaderI cs = alignViewport.getResidueShading();
-      if (cs != null)
-      {
       cs.setInformation(information);
-      }
     }
+  }
 
-    /**
+  /**
    * Get the Information annotation for the alignment
    * 
    * @return
    */
   protected List<AlignmentAnnotation> getInformationAnnotations()
-    {
+  {
     return alignViewport.getInformationAnnotations();
-    }
+  }
 
-    /**
-     * Get the Gap annotation for the alignment
-     * 
-     * @return
-     */
-    protected AlignmentAnnotation getGapAnnotation()
-    {
-      return alignViewport.getAlignmentGapAnnotation();
-    }
+  /**
+   * Get the Gap annotation for the alignment
+   * 
+   * @return
+   */
+  protected AlignmentAnnotation getGapAnnotation()
+  {
+    return alignViewport.getAlignmentGapAnnotation();
+  }
 
-    /**
+  /**
    * update the information annotation from the sequence profile data using
    * current visualization settings.
    */
-    @Override
-    public void updateAnnotation()
-    {
-
-      updateResultAnnotation(false);
-    }
+  @Override
+  public void updateAnnotation()
+  {
+    updateResultAnnotation(false);
+  }
 
   /**
    * Derives the information content for an information annotation.
    * 
    * @param immediate
    */
-    public void updateResultAnnotation(boolean immediate)
-    {
+  public void updateResultAnnotation(boolean immediate)
+  {
     List<AlignmentAnnotation> annots = getInformationAnnotations();
     int index = 0;
     for (AlignmentAnnotation information : annots)
     {
       ProfilesI hinformation = (ProfilesI) getSequenceInformation(index);
       if (immediate || !calcMan.isWorking(this) && information != null
-            && hinformation != null)
+              && hinformation != null)
       {
         deriveInformation(information, hinformation);
       }
       index++;
-      }
     }
+  }
 
-    /**
+  /**
    * Convert the computed information data into the desired annotation for
    * display.
    * 
@@ -223,28 +217,20 @@ public class InformationThread extends AlignCalcWorker
    */
   protected void deriveInformation(
           AlignmentAnnotation informationAnnotation, ProfilesI hinformation)
-    {
-      long nseq = getSequences().length;
+  {
+    long nseq = getSequences().length;
     max = AAFrequency.completeInformation(informationAnnotation,
             hinformation, hinformation.getStartColumn(),
             hinformation.getEndColumn() + 1, nseq, max);
-    }
-
-
+  }
 
-    /**
+  /**
    * Get the information data stored on the viewport.
    * 
    * @return
    */
   protected Object getSequenceInformation(int index)
-    {
-    // TODO convert ComplementInformationThread to use Profile
+  {
     return alignViewport.getSequenceInformationHash(index);
-    }
   }
-
-
-
-
-
+}