JAL-147 improved wrapped scrolling (including Overview) with
[jalview.git] / src / jalview / gui / SeqPanel.java
index 6773611..6fbed49 100644 (file)
@@ -189,6 +189,7 @@ public class SeqPanel extends JPanel implements MouseListener,
     int res = 0;
     int x = evt.getX();
 
+    int startRes = av.getRanges().getStartRes();
     if (av.getWrapAlignment())
     {
 
@@ -203,7 +204,7 @@ public class SeqPanel extends JPanel implements MouseListener,
 
       int y = evt.getY();
       y -= hgap;
-      x -= seqCanvas.LABEL_WEST;
+      x = Math.max(0, x - seqCanvas.LABEL_WEST);
 
       int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
       if (cwidth < 1)
@@ -212,10 +213,11 @@ public class SeqPanel extends JPanel implements MouseListener,
       }
 
       wrappedBlock = y / cHeight;
-      wrappedBlock += av.getRanges().getStartRes() / cwidth;
-
-      res = wrappedBlock * cwidth + x / av.getCharWidth();
-
+      wrappedBlock += startRes / cwidth;
+      // allow for wrapped view scrolled right (possible from Overview)
+      int startOffset = startRes % cwidth;
+      res = wrappedBlock * cwidth
+              + Math.min(cwidth - 1, startOffset + x / av.getCharWidth());
     }
     else
     {
@@ -225,7 +227,7 @@ public class SeqPanel extends JPanel implements MouseListener,
         // right-hand gutter
         x = seqCanvas.getX() + seqCanvas.getWidth();
       }
-      res = (x / av.getCharWidth()) + av.getRanges().getStartRes();
+      res = (x / av.getCharWidth()) + startRes;
       if (res > av.getRanges().getEndRes())
       {
         // moused off right
@@ -394,8 +396,7 @@ public class SeqPanel extends JPanel implements MouseListener,
     }
     else
     {
-      av.getRanges().scrollToVisible(seqCanvas.cursorX, seqCanvas.cursorY,
-              av);
+      av.getRanges().scrollToVisible(seqCanvas.cursorX, seqCanvas.cursorY);
     }
     setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
             seqCanvas.cursorX, seqCanvas.cursorY);
@@ -804,7 +805,9 @@ public class SeqPanel extends JPanel implements MouseListener,
   /**
    * Removes from the list of features any that start after, or end before, the
    * given column position. This allows us to retain only those features
-   * adjacent to a gapped position that straddle the position.
+   * adjacent to a gapped position that straddle the position. Contact features
+   * that 'straddle' the position are also removed, since they are not 'at' the
+   * position.
    * 
    * @param features
    * @param column
@@ -819,7 +822,8 @@ public class SeqPanel extends JPanel implements MouseListener,
     while (it.hasNext())
     {
       SequenceFeature sf = it.next();
-      if (sequence.findIndex(sf.getBegin()) > column
+      if (sf.isContactFeature()
+              || sequence.findIndex(sf.getBegin()) > column
               || sequence.findIndex(sf.getEnd()) < column)
       {
         it.remove();
@@ -2143,8 +2147,7 @@ public class SeqPanel extends JPanel implements MouseListener,
 
     if (copycolsel
             && av.hasHiddenColumns()
-            && (av.getAlignment().getHiddenColumns() == null || av
-                    .getAlignment().getHiddenColumns().getHiddenRegions() == null))
+            && (av.getAlignment().getHiddenColumns() == null))
     {
       System.err.println("Bad things");
     }