Patch for incorrect column selection when hidden regions are present * JAL-558
[jalview.git] / src / jalview / gui / ScalePanel.java
index 2acd92c..907fe69 100755 (executable)
@@ -72,10 +72,13 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
 
     if (av.hasHiddenColumns)
     {
-      res = av.getColumnSelection().adjustForHiddenColumns(x);
+      x = av.getColumnSelection().adjustForHiddenColumns(x);
     }
-    else
+    
+    if (x >= av.alignment.getWidth())
     {
+      res = av.alignment.getWidth() - 1;
+    } else {
       res = x;
     }
 
@@ -169,7 +172,6 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       iVec = null;
       sg.setStartRes(res);
       sg.setEndRes(res);
-      av.setSelectionGroup(sg);
 
       if (evt.isShiftDown())
       {
@@ -182,7 +184,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
         sg.setStartRes(min);
         sg.setEndRes(max);
       }
-
+      av.setSelectionGroup(sg);
     }
 
     ap.paintAlignment(false);
@@ -201,14 +203,14 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
 
     int res = (evt.getX() / av.getCharWidth()) + av.getStartRes();
 
-    if (res > av.alignment.getWidth())
+    if (av.hasHiddenColumns)
     {
-      res = av.alignment.getWidth() - 1;
+      res = av.getColumnSelection().adjustForHiddenColumns(res);
     }
 
-    if (av.hasHiddenColumns)
+    if (res >= av.alignment.getWidth())
     {
-      res = av.getColumnSelection().adjustForHiddenColumns(res);
+      res = av.alignment.getWidth() - 1;
     }
 
     if (!stretchingGroup)
@@ -257,7 +259,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       res = av.getColumnSelection().adjustForHiddenColumns(res);
     }
 
-    if (res > av.alignment.getWidth())
+    if (res >= av.alignment.getWidth())
     {
       res = av.alignment.getWidth() - 1;
     }
@@ -295,7 +297,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
       int col;
       for (int i = min; i <= max; i++)
       {
-        col = av.getColumnSelection().adjustForHiddenColumns(i);
+        col = i; // av.getColumnSelection().adjustForHiddenColumns(i);
 
         if ((col < sg.getStartRes()) || (col > sg.getEndRes()))
         {
@@ -398,6 +400,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
 
     // Fill the selected columns
     ColumnSelection cs = av.getColumnSelection();
+    int s;
     if (cs != null)
     {
       gg.setColor(new Color(220, 0, 0));
@@ -407,7 +410,14 @@ public class ScalePanel extends JPanel implements MouseMotionListener,
         int sel = cs.columnAt(i);
         if (av.hasHiddenColumns)
         {
-          sel = cs.findColumnPosition(sel);
+          if (cs.isVisible(sel))
+          {
+            sel = cs.findColumnPosition(sel);
+          }
+          else
+          {
+            continue;
+          }
         }
 
         if ((sel >= startx) && (sel <= endx))