Merge branch 'features/JAL-2376_add-horizontal-bar' into develop
[jalview.git] / src / jalview / viewmodel / OverviewDimensions.java
index 6f4a4e0..a837d53 100644 (file)
@@ -149,11 +149,13 @@ public abstract class OverviewDimensions
 
   public float getPixelsPerCol()
   {
+    resetAlignmentDims();
     return (float) width / alwidth;
   }
 
   public float getPixelsPerSeq()
   {
+    resetAlignmentDims();
     return (float) sequencesHeight / alheight;
   }
 
@@ -178,12 +180,9 @@ public abstract class OverviewDimensions
    *          the alignment's hidden sequences
    * @param hiddenCols
    *          the alignment's hidden columns
-   * @param ranges
-   *          the alignment's width and height ranges
    */
   public abstract void updateViewportFromMouse(int mousex, int mousey,
-          HiddenSequences hiddenSeqs, HiddenColumns hiddenCols,
-          ViewportRanges ranges);
+          HiddenSequences hiddenSeqs, HiddenColumns hiddenCols);
 
   /**
    * Set the overview panel's box position to match the viewport
@@ -192,33 +191,49 @@ public abstract class OverviewDimensions
    *          the alignment's hidden sequences
    * @param hiddenCols
    *          the alignment's hidden columns
-   * @param ranges
-   *          the alignment's width and height ranges
    */
   public abstract void setBoxPosition(HiddenSequences hiddenSeqs,
-          HiddenColumns hiddenCols, ViewportRanges ranges);
+          HiddenColumns hiddenCols);
 
   /**
    * Get the collection of columns used by this overview dimensions object
    * 
-   * @param ranges
-   *          the alignment's width and height ranges
    * @param hiddenCols
    *          the alignment's hidden columns
    * @return a column collection
    */
-  public abstract AlignmentColsCollectionI getColumns(
-          ViewportRanges ranges, HiddenColumns hiddenCols);
+  public abstract AlignmentColsCollectionI getColumns(AlignmentI al);
 
   /**
    * Get the collection of rows used by this overview dimensions object
    * 
-   * @param ranges
-   *          the alignment's width and height ranges
    * @param al
    *          the alignment
    * @return a row collection
    */
-  public abstract AlignmentRowsCollectionI getRows(
-          ViewportRanges ranges, AlignmentI al);
+  public abstract AlignmentRowsCollectionI getRows(AlignmentI al);
+
+  /**
+   * Updates overview dimensions to account for current alignment dimensions
+   */
+  protected abstract void resetAlignmentDims();
+
+  protected void setBoxPosition(int startRes, int endRes, int startSeq,
+          int endSeq)
+  {
+    resetAlignmentDims();
+
+    // boxX, boxY is the x,y location equivalent to startRes, startSeq
+    boxX = Math.round((float) startRes * width / alwidth);
+    boxY = Math.round((float) startSeq * sequencesHeight / alheight);
+
+    // boxWidth is the width in residues translated to pixels
+    // since the box includes both the start and end residues, add 1 to the
+    // difference
+    boxWidth = Math
+            .round((float) (endRes - startRes + 1) * width / alwidth);
+    // boxHeight is the height in sequences translated to pixels
+    boxHeight = Math.round((float) (endSeq - startSeq + 1)
+            * sequencesHeight / alheight);
+  }
 }
\ No newline at end of file