JAL-2388 Minor refactoring
[jalview.git] / src / jalview / viewmodel / OverviewDimensions.java
index 17f56c9..9b55e55 100644 (file)
@@ -22,6 +22,8 @@ package jalview.viewmodel;
 
 import jalview.api.AlignViewportI;
 
+import java.awt.Graphics;
+
 public class OverviewDimensions
 {
   // Default width and height values
@@ -108,14 +110,15 @@ public class OverviewDimensions
   /**
    * Check box dimensions and scroll positions and correct if necessary
    */
-  public void checkValid()
+  public void setBoxPositionByMouse(int x, int y)
   {
+    boxX = x;
+    boxY = y;
     if (boxY < 0)
     {
       boxY = 0;
     }
-
-    if (boxY > (sequencesHeight - boxHeight))
+    else if (boxY > (sequencesHeight - boxHeight))
     {
       boxY = sequencesHeight - boxHeight + 1;
     }
@@ -124,8 +127,7 @@ public class OverviewDimensions
     {
       boxX = 0;
     }
-
-    if (boxX > (width - boxWidth))
+    else if (boxX > (width - boxWidth))
     {
       if (av.hasHiddenColumns())
       {
@@ -184,21 +186,12 @@ public class OverviewDimensions
 
       endSeq = av.getAlignment().getHiddenSequences()
               .adjustForHiddenSeqs(endSeq);
-
     }
 
     boxX = (int) (startRes * av.getCharWidth() * scalew);
     boxY = (int) (startSeq * av.getCharHeight() * scaleh);
 
-    if (av.hasHiddenColumns())
-    {
-      boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
-    }
-    else
-    {
-      boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
-    }
-
+    boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew);
     boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh);
   }
 
@@ -218,6 +211,18 @@ public class OverviewDimensions
     scaleh = (float) sequencesHeight / fullsizeHeight;
   }
 
+  /**
+   * Draw the overview panel's viewport box on a graphics object
+   * 
+   * @param g
+   *          the graphics object to draw on
+   */
+  public void drawBox(Graphics g)
+  {
+    g.drawRect(boxX, boxY, boxWidth, boxHeight);
+    g.drawRect(boxX + 1, boxY + 1, boxWidth - 2, boxHeight - 2);
+  }
+
   // don't like this, scroll vals are separate from setting code
   public int getScrollCol()
   {
@@ -229,11 +234,15 @@ public class OverviewDimensions
     return scrollRow;
   }
 
+  // TODO should be removed, when unit test has mock Graphics object available
+  // to check boxX/boxY
   public int getBoxX()
   {
     return boxX;
   }
 
+  // TODO should be removed, when unit test has mock Graphics object available
+  // to check boxX/boxY
   public int getBoxY()
   {
     return boxY;