JAL-2439 Out-by-one in setting endRes/endSeq
[jalview.git] / src / jalview / viewmodel / ViewportPositionProps.java
index 2789d77..61dd18c 100644 (file)
  */
 package jalview.viewmodel;
 
-import jalview.api.AlignViewportI;
 import jalview.datamodel.AlignmentI;
 
 /**
  * Supplies and updates viewport properties relating to position such as: start
- * and end residues and sequences, hidden column/row adjustments, etc
+ * and end residues and sequences
  */
 public class ViewportPositionProps extends ViewportProperties
 {
@@ -44,15 +43,13 @@ public class ViewportPositionProps extends ViewportProperties
   // alignment
   private AlignmentI al;
 
-  // viewport
-  private AlignViewportI av; // this is a bad dependency, viewmodel should not
-                             // depend on api
-
   /**
    * Constructor
-   * @param alignment TODO
+   * 
+   * @param alignment
+   *          the viewport's alignment
    */
-  public ViewportPositionProps(AlignmentI alignment, AlignViewportI viewport)
+  public ViewportPositionProps(AlignmentI alignment)
   {
     // initial values of viewport settings
     this.startRes = 0;
@@ -60,7 +57,6 @@ public class ViewportPositionProps extends ViewportProperties
     this.startSeq = 0;
     this.endSeq = alignment.getHeight() - 1;
     this.al = alignment;
-    this.av = viewport;
   }
 
   // ways to update values
@@ -70,21 +66,27 @@ public class ViewportPositionProps extends ViewportProperties
   // ways to supply positional information
 
   /**
-   * Get alignment width
+   * Get alignment width in cols, including hidden cols
    */
-  public int getAlignmentWidthInCols()
+  public int getAbsoluteAlignmentWidth()
   {
     return al.getWidth();
   }
 
   /**
-   * Get alignment height
+   * Get alignment height in rows, including hidden rows
    */
-  public int getAlignmentHeightInRows()
+  public int getAbsoluteAlignmentHeight()
   {
-    return al.getHeight();
+    return al.getHeight() + al.getHiddenSequences().getSize();
   }
 
+  /**
+   * Set first residue visible in the viewport
+   * 
+   * @param res
+   *          residue position
+   */
   public void setStartRes(int res)
   {
     if (res > al.getWidth() - 1)
@@ -98,11 +100,17 @@ public class ViewportPositionProps extends ViewportProperties
     this.startRes = res;
   }
 
+  /**
+   * Set last residue visible in the viewport
+   * 
+   * @param res
+   *          residue position
+   */
   public void setEndRes(int res)
   {
-    if (res > al.getWidth())
+    if (res >= al.getWidth())
     {
-      res = al.getWidth();
+      res = al.getWidth() - 1;
     }
     else if (res < 1)
     {
@@ -111,6 +119,12 @@ public class ViewportPositionProps extends ViewportProperties
     this.endRes = res;
   }
 
+  /**
+   * Set the first sequence visible in the viewport
+   * 
+   * @param seq
+   *          sequence position
+   */
   public void setStartSeq(int seq)
   {
     if (seq > al.getHeight() - 1)
@@ -124,11 +138,17 @@ public class ViewportPositionProps extends ViewportProperties
     this.startSeq = seq;
   }
 
+  /**
+   * Set the last sequence visible in the viewport
+   * 
+   * @param seq
+   *          sequence position
+   */
   public void setEndSeq(int seq)
   {
-    if (seq > al.getHeight())
+    if (seq >= al.getHeight())
     {
-      seq = al.getHeight();
+      seq = al.getHeight() - 1;
     }
     else if (seq < 1)
     {
@@ -168,62 +188,4 @@ public class ViewportPositionProps extends ViewportProperties
   {
     return endSeq;
   }
-
-  /**
-   * Get absolute start residue of viewport
-   */
-  public int getAbsoluteStartRes()
-  {
-    int start = startRes;
-
-    if (av.hasHiddenColumns())
-    {
-      start = av.getColumnSelection().adjustForHiddenColumns(start);
-    }
-    return start;
-  }
-
-  /**
-   * Get absolute start residue of viewport
-   */
-  public int getAbsoluteEndRes()
-  {
-    int end = endRes;
-
-    if (av.hasHiddenColumns())
-    {
-      end = av.getColumnSelection().adjustForHiddenColumns(end);
-    }
-    return end;
-  }
-
-  /**
-   * Get absolute start sequence of viewport
-   */
-  public int getAbsoluteStartSeq()
-  {
-    int start = startSeq;
-
-    if (av.hasHiddenRows())
-    {
-      start = av.getAlignment().getHiddenSequences()
-              .adjustForHiddenSeqs(start);
-    }
-    return start;
-  }
-
-  /**
-   * Get absolute end sequence of viewport
-   */
-  public int getAbsoluteEndSeq()
-  {
-    int end = endSeq;
-
-    if (av.hasHiddenRows())
-    {
-      end = av.getAlignment().getHiddenSequences().adjustForHiddenSeqs(end);
-    }
-    return end;
-  }
-
 }