JAL-147 improved wrapped scrolling (including Overview) with
[jalview.git] / src / jalview / appletgui / SeqPanel.java
index f0ec51c..e4e3640 100644 (file)
@@ -616,6 +616,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     int res = 0;
     int x = evt.getX();
 
+    int startRes = av.getRanges().getStartRes();
     if (av.getWrapAlignment())
     {
 
@@ -630,7 +631,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
       int y = evt.getY();
       y -= hgap;
-      x -= seqCanvas.LABEL_WEST;
+      x = Math.max(0, x - seqCanvas.LABEL_WEST);
 
       int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width);
       if (cwidth < 1)
@@ -639,14 +640,15 @@ public class SeqPanel extends Panel implements MouseMotionListener,
       }
 
       wrappedBlock = y / cHeight;
-      wrappedBlock += av.getRanges().getStartRes() / cwidth;
-
-      res = wrappedBlock * cwidth + x / av.getCharWidth();
-
+      wrappedBlock += startRes / cwidth;
+      int startOffset = startRes % cwidth; // in case start is scrolled right
+                                           // from 0
+      res = wrappedBlock * cwidth
+              + Math.min(cwidth - 1, startOffset + x / av.getCharWidth());
     }
     else
     {
-      res = (x / av.getCharWidth()) + av.getRanges().getStartRes();
+      res = (x / av.getCharWidth()) + startRes;
     }
 
     if (av.hasHiddenColumns())
@@ -909,7 +911,9 @@ public class SeqPanel extends Panel implements MouseMotionListener,
   /**
    * 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
@@ -924,7 +928,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     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();
@@ -934,7 +939,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
   List<SequenceFeature> findFeaturesAtRes(SequenceI sequence, int res)
   {
-    List<SequenceFeature> result = new ArrayList<SequenceFeature>();
+    List<SequenceFeature> result = new ArrayList<>();
     SequenceFeature[] features = sequence.getSequenceFeatures();
     if (features != null)
     {
@@ -1498,7 +1503,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
         {
           if (links == null)
           {
-            links = new Vector<String>();
+            links = new Vector<>();
           }
           for (int j = 0; j < sf.links.size(); j++)
           {
@@ -1923,8 +1928,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     }
     if (copycolsel
             && av.hasHiddenColumns()
-            && (av.getColumnSelection() == null || av.getAlignment()
-                    .getHiddenColumns().getHiddenRegions() == null))
+            && (av.getColumnSelection() == null))
     {
       System.err.println("Bad things");
     }