JAL-2388 Corrected overview panel behaviour, updated tests
[jalview.git] / src / jalview / gui / OverviewPanel.java
index fc3cc4b..d15ec40 100755 (executable)
@@ -36,7 +36,8 @@ import java.awt.image.BufferedImage;
 import javax.swing.JPanel;
 
 /**
- * DOCUMENT ME!
+ * Panel displaying an overview of the full alignment, with an interactive box
+ * representing the viewport onto the alignment.
  * 
  * @author $author$
  * @version $Revision$
@@ -73,21 +74,28 @@ public class OverviewPanel extends JPanel implements Runnable
   /**
    * Creates a new OverviewPanel object.
    * 
-   * @param ap
+   * @param alPanel
    *          The alignment panel which is shown in the overview panel
    */
-  public OverviewPanel(AlignmentPanel ap)
+  public OverviewPanel(AlignmentPanel alPanel)
   {
-    this.av = ap.av;
-    this.ap = ap;
+    this.av = alPanel.av;
+    this.ap = alPanel;
     setLayout(null);
 
     sr = new SequenceRenderer(av);
     sr.renderGaps = false;
     sr.forOverview = true;
-    fr = new FeatureRenderer(ap);
+    fr = new FeatureRenderer(alPanel);
 
-    od = new OverviewDimensions(av);
+    boolean showAnnotation = false;
+    // TODO: in applet this was getSequenceConsensusHash()
+    // check if it makes any functional difference: hconsensus or conservation
+    if (av.getAlignmentConservationAnnotation() == null)
+    {
+      showAnnotation = true;
+    }
+    od = new OverviewDimensions(av, showAnnotation);
 
     addComponentListener(new ComponentAdapter()
     {
@@ -111,9 +119,8 @@ public class OverviewPanel extends JPanel implements Runnable
         {
           // TODO: feature: jv2.5 detect shift drag and update selection from
           // it.
-          od.setBoxX(evt.getX());
-          od.setBoxY(evt.getY());
-          checkValid();
+          od.updateViewportFromMouse(evt.getX(), evt.getY());
+          ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
         }
       }
     });
@@ -125,9 +132,8 @@ public class OverviewPanel extends JPanel implements Runnable
       {
         if (!av.getWrapAlignment())
         {
-          od.setBoxX(evt.getX());
-          od.setBoxY(evt.getY());
-          checkValid();
+          od.updateViewportFromMouse(evt.getX(), evt.getY());
+          ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
         }
       }
     });
@@ -136,16 +142,6 @@ public class OverviewPanel extends JPanel implements Runnable
   }
 
   /**
-   * Check box dimensions and scroll positions and correct if necessary
-   */
-  private void checkValid()
-  {
-    od.checkValid();
-    ap.setScrollValues(od.getScrollCol(), od.getScrollRow());
-
-  }
-
-  /**
    * Updates the overview image when the related alignment panel is updated
    */
   public void updateOverviewImage()
@@ -192,15 +188,11 @@ public class OverviewPanel extends JPanel implements Runnable
     mg.setColor(Color.orange);
     mg.fillRect(0, 0, od.getWidth(), miniMe.getHeight());
 
-    // calculate scale based on current alignment width and height
-    od.updateScales();
-
     // calculate sampleCol and sampleRow
     // alignment width is max number of residues/bases
     // alignment height is number of sequences
     int alwidth = av.getAlignment().getWidth();
-    int alheight = av.getAlignment().getHeight()
-            + av.getAlignment().getHiddenSequences().getSize();
+    int alheight = av.getAlignment().getAbsoluteHeight();
 
     // sampleCol or sampleRow is the width/height allocated to each residue
     // in particular, sometimes we may need more than one row/col of the
@@ -250,7 +242,7 @@ public class OverviewPanel extends JPanel implements Runnable
     int color = Color.white.getRGB();
 
     jalview.datamodel.SequenceI seq = null;
-    final boolean hasHiddenRows = av.hasHiddenRows();
+
     final boolean hasHiddenCols = av.hasHiddenColumns();
     boolean hiddenRow = false;
     // get hidden row and hidden column map once at beginning.
@@ -266,29 +258,10 @@ public class OverviewPanel extends JPanel implements Runnable
 
         lastrow = currentrow;
 
-        hiddenRow = false;
-        // should be method(s) in Alignment
-        if (hasHiddenRows)
-        {
-          seq = av.getAlignment().getHiddenSequences()
-                  .getHiddenSequence(lastrow);
-          if (seq == null)
-          {
-            int index = av.getAlignment().getHiddenSequences()
-                    .findIndexWithoutHiddenSeqs(lastrow);
-
-            seq = av.getAlignment().getSequenceAt(index);
-          }
-          else
-          {
-            hiddenRow = true;
-          }
-        }
-        else
-        {
-          seq = av.getAlignment().getSequenceAt(lastrow);
-        }
-        // end of Alignment method(s)
+        // get the sequence which would be at alignment index 'lastrow' if no
+        // columns were hidden, and determine whether it is hidden or not
+        hiddenRow = av.getAlignment().isHidden(lastrow);
+        seq = av.getAlignment().getSequenceAtAbsoluteIndex(lastrow);
       }
 
       if (seq == null)
@@ -391,9 +364,6 @@ public class OverviewPanel extends JPanel implements Runnable
     }
     // TODO: render selected regions
     g.setColor(Color.red);
-    g.drawRect(od.getBoxX(), od.getBoxY(), od.getBoxWidth(),
-            od.getBoxHeight());
-    g.drawRect(od.getBoxX() + 1, od.getBoxY() + 1, od.getBoxWidth() - 2,
-            od.getBoxHeight() - 2);
+    od.drawBox(g);
   }
 }