JAL-2008 handle fast mouse drag of feature ordering correctly
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 4 Aug 2016 09:55:50 +0000 (10:55 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 4 Aug 2016 09:55:50 +0000 (10:55 +0100)
src/jalview/gui/FeatureSettings.java

index a4d8728..7d9e937 100644 (file)
@@ -211,11 +211,20 @@ public class FeatureSettings extends JPanel implements
         int newRow = table.rowAtPoint(evt.getPoint());
         if (newRow != selectedRow && selectedRow != -1 && newRow != -1)
         {
+          /*
+           * reposition 'selectedRow' to 'newRow' (the dragged to location)
+           * this could be more than one row away for a very fast drag action
+           * so just swap it with adjacent rows until we get it there
+           */
           Object[][] data = ((FeatureTableModel) table.getModel())
                   .getData();
-          Object[] temp = data[selectedRow];
-          data[selectedRow] = data[newRow];
-          data[newRow] = temp;
+          int direction = newRow < selectedRow ? -1 : 1;
+          for (int i = selectedRow; i != newRow; i += direction)
+          {
+            Object[] temp = data[i];
+            data[i] = data[i + direction];
+            data[i + direction] = temp;
+          }
           updateFeatureRenderer(data);
           table.repaint();
           selectedRow = newRow;