JAL-2439 Out-by-one in setting endRes/endSeq
[jalview.git] / src / jalview / viewmodel / ViewportPositionProps.java
index 1bb49af..61dd18c 100644 (file)
  */
 package jalview.viewmodel;
 
-import jalview.api.ViewStyleI;
 import jalview.datamodel.AlignmentI;
 
 /**
  * Supplies and updates viewport properties relating to position such as: start
- * and end residues and sequences, hidden column/row adjustments, ratio of
- * viewport to alignment etc
+ * and end residues and sequences
  */
 public class ViewportPositionProps extends ViewportProperties
 {
@@ -42,23 +40,16 @@ public class ViewportPositionProps extends ViewportProperties
   // end sequence of viewport
   private int endSeq;
 
-  // character height
-  private int charHeight;
-
-  // character width
-  private int charWidth;
-
   // alignment
   private AlignmentI al;
 
-  // viewstyle
-  private ViewStyleI viewstyle;
-
   /**
    * Constructor
-   * @param alignment TODO
+   * 
+   * @param alignment
+   *          the viewport's alignment
    */
-  public ViewportPositionProps(AlignmentI alignment, ViewStyleI vstyle)
+  public ViewportPositionProps(AlignmentI alignment)
   {
     // initial values of viewport settings
     this.startRes = 0;
@@ -66,17 +57,6 @@ public class ViewportPositionProps extends ViewportProperties
     this.startSeq = 0;
     this.endSeq = alignment.getHeight() - 1;
     this.al = alignment;
-    this.viewstyle = vstyle;
-  }
-
-  public void setCharHeight(int h)
-  {
-    viewstyle.setCharHeight(h);
-  }
-
-  public void setCharWidth(int w)
-  {
-    viewstyle.setCharWidth(w);
   }
 
   // ways to update values
@@ -86,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)
@@ -114,24 +100,36 @@ 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() - 1)
+    if (res >= al.getWidth())
     {
       res = al.getWidth() - 1;
     }
-    else if (res < 0)
+    else if (res < 1)
     {
-      res = 0;
+      res = 1;
     }
     this.endRes = res;
   }
 
+  /**
+   * Set the first sequence visible in the viewport
+   * 
+   * @param seq
+   *          sequence position
+   */
   public void setStartSeq(int seq)
   {
-    if (seq > al.getHeight())
+    if (seq > al.getHeight() - 1)
     {
-      seq = al.getHeight();
+      seq = al.getHeight() - 1;
     }
     else if (seq < 0)
     {
@@ -140,15 +138,21 @@ 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 < 0)
+    else if (seq < 1)
     {
-      seq = 0;
+      seq = 1;
     }
     this.endSeq = seq;
   }
@@ -184,68 +188,4 @@ public class ViewportPositionProps extends ViewportProperties
   {
     return endSeq;
   }
-  /**
-   * Get start residue of viewport
-   */
-  public int getStartRes(boolean countHidden)
-  {
-    if (countHidden)
-    {
-      return 0; // av.getColumnSelection().adjustForHiddenColumns(startRes);
-    }
-    else
-    {
-      return startRes;
-    }
-  }
-
-  /**
-   * Convert distance x in viewport pixels to a distance in number of residues
-   * 
-   * @param x
-   *          number of pixels
-   * @return number of residues
-   */
-  public int convertPixelsToResidues(int x)
-  {
-    return Math.round((float) x / viewstyle.getCharWidth());
-    // return (int) ((float) x / viewstyle.getCharWidth());
-  }
-
-  /**
-   * Convert distance y in viewport pixels to a distance in number of sequences
-   * 
-   * @param y
-   *          number of pixels
-   * @return number of sequences
-   */
-  public int convertPixelsToSequences(int y)
-  {
-    return Math.round((float) y / viewstyle.getCharHeight());
-    // return (int) ((float) y / viewstyle.getCharHeight());
-  }
-  
-  /**
-   * Convert number of sequences s to a height in viewport pixels
-   * 
-   * @param s
-   *          number of sequences
-   * @return number of pixels
-   */
-  public int convertSequencesToPixels(int s)
-  {
-    return (s * viewstyle.getCharHeight());
-  }
-
-  /**
-   * Convert number of residues r to a width in viewport pixels
-   * 
-   * @param r
-   *          number of residues
-   * @return number of pixels
-   */
-  public int convertResiduesToPixels(int r)
-  {
-    return (r * viewstyle.getCharWidth());
-  }
 }