From 07f33ebba24aeb58615429df45a8ec30fa085c89 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 4 Aug 2016 10:55:50 +0100 Subject: [PATCH] JAL-2008 handle fast mouse drag of feature ordering correctly --- src/jalview/gui/FeatureSettings.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index a4d8728..7d9e937 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -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; -- 1.7.10.2