JAL-2388 First move of endRes etc out of AlignmentViewport (in progress)
[jalview.git] / src / jalview / viewmodel / OverviewDimensions.java
index 9b55e55..b4c7c6d 100644 (file)
@@ -39,6 +39,8 @@ public class OverviewDimensions
 
   private AlignViewportI av;
 
+  private ViewportPositionProps posProps;
+
   private float scalew = 1f;
 
   private float scaleh = 1f;
@@ -72,6 +74,7 @@ public class OverviewDimensions
   public OverviewDimensions(AlignViewportI avi)
   {
     this.av = avi;
+    this.posProps = av.getPosProps();
 
     // scale the initial size of overviewpanel to shape of alignment
     float initialScale = (float) av.getAlignment().getWidth()
@@ -84,7 +87,8 @@ public class OverviewDimensions
       graphHeight = 0;
     }
 
-    if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
+    if (posProps.getAlignmentWidthInCols() > posProps
+            .getAlignmentHeightInRows())
     {
       // wider
       width = MAX_WIDTH;
@@ -132,14 +136,21 @@ public class OverviewDimensions
       if (av.hasHiddenColumns())
       {
         // Try smallest possible box
-        boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1)
-                * av.getCharWidth() * scalew);
+        boxWidth = (int) (posProps.convertResiduesToPixels(posProps
+                .getEndRes() - posProps.getStartRes() + 1) * scalew);
+
+        // boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1)
+        // * av.getCharWidth() * scalew);
       }
       boxX = width - boxWidth;
     }
 
-    scrollCol = (int) (boxX / scalew / av.getCharWidth());
-    scrollRow = (int) (boxY / scaleh / av.getCharHeight());
+    scrollCol = posProps.convertPixelsToResidues(Math.round(boxX / scalew));
+    scrollRow = posProps
+            .convertPixelsToSequences(Math.round(boxY / scaleh));
+
+    // scrollCol = (int) (boxX / scalew / av.getCharWidth());
+    // scrollRow = (int) (boxY / scaleh / av.getCharHeight());
 
     if (av.hasHiddenColumns())
     {
@@ -188,11 +199,21 @@ public class OverviewDimensions
               .adjustForHiddenSeqs(endSeq);
     }
 
-    boxX = (int) (startRes * av.getCharWidth() * scalew);
-    boxY = (int) (startSeq * av.getCharHeight() * scaleh);
+    boxX = Math.round(posProps.convertResiduesToPixels(startRes) * scalew);
+    boxY = Math.round(posProps.convertSequencesToPixels(startSeq) * scaleh);
+
+    // boxX = (int) (startRes * av.getCharWidth() * scalew);
+    // boxY = (int) (startSeq * av.getCharHeight() * scaleh);
+
+    boxWidth = Math.round(posProps.convertResiduesToPixels(endRes
+            - startRes
+            + 1) * scalew);
+    boxHeight = Math.round(posProps.convertSequencesToPixels(endSeq
+            - startSeq)
+            * scaleh);
 
-    boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
-    boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
+    // boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
+    // boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
   }
 
   /**