JAL-3878 update branch from 2.12 merge from 2.11.2
[jalview.git] / src / jalview / viewmodel / AlignmentViewport.java
index 1a08b1b..0e3bb9e 100644 (file)
@@ -74,6 +74,9 @@ import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
 
 /**
  * base class holding visualization and analysis attributes and common logic for
@@ -87,7 +90,6 @@ public abstract class AlignmentViewport
 {
   public static final String PROPERTY_ALIGNMENT = "alignment";
   public static final String PROPERTY_SEQUENCE = "sequence";
-
   protected ViewportRanges ranges;
 
   protected ViewStyleI viewStyle = new ViewStyle();
@@ -616,6 +618,7 @@ public abstract class AlignmentViewport
    * alignment
    */
   protected boolean isDataset = false;
+
   
   public void setDataset(boolean b)
   {
@@ -654,11 +657,10 @@ public abstract class AlignmentViewport
   {
     autoCalculateStrucConsensus = b;
   }
-
-
   protected boolean ignoreGapsInConsensusCalculation = false;
 
   protected ResidueShaderI residueShading = new ResidueShader();
+
   
   @Override
   public void setGlobalColourScheme(ColourSchemeI cs)
@@ -733,6 +735,7 @@ public abstract class AlignmentViewport
   {
     return residueShading;
   }
+
   
   protected AlignmentAnnotation consensus;
 
@@ -767,6 +770,7 @@ public abstract class AlignmentViewport
   protected Hashtable<String, Object>[] hStrucConsensus = null;
 
   protected Conservation hconservation = null;
+
   
   @Override
   public void setConservation(Conservation cons)
@@ -952,7 +956,6 @@ public abstract class AlignmentViewport
       calculator.registerWorker(new InformationThread(this, ap));
     }
   }
-
   // --------START Structure Conservation
   public void updateStrucConsensus(final AlignmentViewPanel ap)
   {
@@ -995,6 +998,20 @@ public abstract class AlignmentViewport
     return false;
   }
 
+  private ScheduledExecutorService serviceExecutor = Executors.newSingleThreadScheduledExecutor();
+
+  /**
+   * Get a default scheduled executor service which can be used by
+   * services and calculators to run parallel jobs associated with this
+   * viewport.
+   * 
+   * @return default service executor of that viewport
+   */
+  public ScheduledExecutorService getServiceExecutor()
+  {
+    return serviceExecutor;
+  }
+
   public void setAlignment(AlignmentI align)
   {
     this.alignment = align;
@@ -1024,11 +1041,14 @@ public abstract class AlignmentViewport
     gapcounts = null;
     calculator.shutdown();
     calculator = null;
+    serviceExecutor.shutdown();
+    serviceExecutor = null;
     residueShading = null; // may hold a reference to Consensus
     changeSupport = null;
     ranges = null;
     currentTree = null;
     selectionGroup = null;
+    colSel = null;
     setAlignment(null);
   }
 
@@ -1139,7 +1159,6 @@ public abstract class AlignmentViewport
     }
     this.hmmShowSequenceLogo = showHMMSequenceLogo;
   }
-
   /**
    * @param showConsensusHistogram
    *          the showConsensusHistogram to set
@@ -1447,7 +1466,6 @@ public abstract class AlignmentViewport
   {
     return infoLetterHeight;
   }
-
   // property change stuff
   // JBPNote Prolly only need this in the applet version.
   private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
@@ -1499,6 +1517,7 @@ public abstract class AlignmentViewport
     }
   }
 
+
   // common hide/show column stuff
 
   public void hideSelectedColumns()
@@ -1570,7 +1589,6 @@ public abstract class AlignmentViewport
     }
   }
 
-
   public void showSequence(int index)
   {
     int startSeq = ranges.getStartSeq();
@@ -1593,6 +1611,7 @@ public abstract class AlignmentViewport
       }
 
       ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
+
       notifyAlignment();
       sendSelection();
     }
@@ -2078,7 +2097,6 @@ public abstract class AlignmentViewport
               MessageManager.getString("label.consensus_descr"),
               new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
       initConsensus(consensus);
-
       initGapCounts();
 
       initComplementConsensus();
@@ -3124,7 +3142,6 @@ public abstract class AlignmentViewport
     }
     return false;
   }
-
   @Override
   public void setCurrentTree(TreeModel tree)
   {
@@ -3251,6 +3268,24 @@ public abstract class AlignmentViewport
       codingComplement.setUpdateStructures(needToUpdateStructureViews);
     }
   }
+
+  @Override
+  public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
+  {
+    int start = 0;
+    int end = 0;
+    if (selectedRegionOnly && selectionGroup != null)
+    {
+      start = selectionGroup.getStartRes();
+      end = selectionGroup.getEndRes() + 1;
+    }
+    else
+    {
+      end = alignment.getWidth();
+    }
+    return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
+            false));
+  }
   /**
    * Filters out sequences with an eValue higher than the specified value. The
    * filtered sequences are hidden or deleted. Sequences with no eValues are also