From: gmungoc Date: Thu, 4 Aug 2016 09:55:50 +0000 (+0100) Subject: JAL-2008 handle fast mouse drag of feature ordering correctly X-Git-Tag: Release_2_10_0~117 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=07f33ebba24aeb58615429df45a8ec30fa085c89;p=jalview.git JAL-2008 handle fast mouse drag of feature ordering correctly --- 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;