JAL-3093 tweaks to code and test for 3px gap above annotations in
[jalview.git] / src / jalview / gui / SeqPanel.java
index 0b62629..d0859b8 100644 (file)
@@ -272,29 +272,44 @@ public class SeqPanel extends JPanel
     int alignmentHeight = av.getAlignment().getHeight();
     if (av.getWrapAlignment())
     {
-      int hgap = charHeight;
-      if (av.getScaleAboveWrapped())
-      {
-        hgap += charHeight;
-      }
+      seqCanvas.calculateWrappedGeometry(seqCanvas.getWidth(),
+              seqCanvas.getHeight());
+      // int gapHeight = charHeight;
+      // if (av.getScaleAboveWrapped())
+      // {
+      // gapHeight += charHeight;
+      // }
+      //
+      // final int alignmentHeightPixels = gapHeight
+      // + alignmentHeight * charHeight;
+      // int cHeight = alignmentHeightPixels;
+      // if (av.isShowAnnotation())
+      // {
+      // cHeight += (seqCanvas.getAnnotationHeight() +
+      // SeqCanvas.SEQS_ANNOTATION_GAP);
+      // }
 
-      final int alignmentHeightPixels = alignmentHeight * charHeight + hgap;
-      final int annotationHeight = seqCanvas.getAnnotationHeight();
-      final int cHeight = alignmentHeightPixels + annotationHeight
-              + SeqCanvas.SEQS_ANNOTATION_GAP;
+      /*
+       * yPos modulo repeating width height
+       */
+      int yOffsetPx = y % seqCanvas.wrappedRepeatHeightPx;
 
-      int yOffsetPx = y % cHeight; // yPos below repeating width(s)
-      if (yOffsetPx >= alignmentHeightPixels
-              + SeqCanvas.SEQS_ANNOTATION_GAP)
+      /*
+       * height of sequences plus space / scale above,
+       * plus gap between sequences and annotations
+       */
+      int alignmentHeightPixels = seqCanvas.wrappedSpaceAboveAlignment
+              + alignmentHeight * charHeight
+              + SeqCanvas.SEQS_ANNOTATION_GAP;
+      if (yOffsetPx >= alignmentHeightPixels)
       {
         /*
-         * mouse is over annotations; find annotation index, also
+         * mouse is over annotations; find annotation index, also set
          * last sequence above (for backwards compatible behaviour)
          */
         AlignmentAnnotation[] anns = av.getAlignment()
                 .getAlignmentAnnotation();
-        int rowOffsetPx = yOffsetPx - alignmentHeightPixels
-                - SeqCanvas.SEQS_ANNOTATION_GAP;
+        int rowOffsetPx = yOffsetPx - alignmentHeightPixels;
         annIndex = AnnotationPanel.getRowIndex(rowOffsetPx, anns);
         seqIndex = alignmentHeight - 1;
       }
@@ -303,7 +318,7 @@ public class SeqPanel extends JPanel
         /*
          * mouse is over sequence (or the space above sequences)
          */
-        yOffsetPx -= hgap;
+        yOffsetPx -= seqCanvas.wrappedSpaceAboveAlignment;
         if (yOffsetPx >= 0)
         {
           seqIndex = Math.min(yOffsetPx / charHeight, alignmentHeight - 1);
@@ -333,7 +348,6 @@ public class SeqPanel extends JPanel
     int startRes = av.getRanges().getStartRes();
     if (av.getWrapAlignment())
     {
-
       int hgap = av.getCharHeight();
       if (av.getScaleAboveWrapped())
       {
@@ -358,7 +372,7 @@ public class SeqPanel extends JPanel
       // allow for wrapped view scrolled right (possible from Overview)
       int startOffset = startRes % cwidth;
       res = wrappedBlock * cwidth + startOffset
-              + +Math.min(cwidth - 1, x / av.getCharWidth());
+              + Math.min(cwidth - 1, x / av.getCharWidth());
     }
     else
     {
@@ -908,6 +922,7 @@ public class SeqPanel extends JPanel
     {
       lastMousePosition = null;
       setToolTipText(null);
+      lastTooltip = null;
       ap.alignFrame.statusBar.setText("");
       return;
     }
@@ -1026,20 +1041,26 @@ public class SeqPanel extends JPanel
   @Override
   public Point getToolTipLocation(MouseEvent event)
   {
-    int x = event.getX(), w = getWidth();
-    int wdth = (w - x < 200) ? -(w / 2) : 5; // switch sides when tooltip is too
-    // close to edge
+    if (tooltipText == null || tooltipText.length() <= 6)
+    {
+      lastp = null;
+      return null;
+    }
+
+    int x = event.getX();
+    int w = getWidth();
+    // switch sides when tooltip is too close to edge
+    int wdth = (w - x < 200) ? -(w / 2) : 5;
     Point p = lastp;
     if (!event.isShiftDown() || p == null)
     {
-      p = (tooltipText != null && tooltipText.length() > 6)
-              ? new Point(event.getX() + wdth, event.getY() - 20)
-              : null;
+      p = new Point(event.getX() + wdth, event.getY() - 20);
+      lastp = p;
     }
     /*
-     * TODO: try to modify position region is not obcured by tooltip
+     * TODO: try to set position so region is not obscured by tooltip
      */
-    return lastp = p;
+    return p;
   }
 
   String lastTooltip;