From 78f929d85e95b6445f7fab46504abc394d8c3fe9 Mon Sep 17 00:00:00 2001 From: jprocter Date: Mon, 14 Feb 2011 12:58:37 +0000 Subject: [PATCH] JAL-769 --- src/jalview/appletgui/AlignFrame.java | 2 + src/jalview/appletgui/AnnotationLabels.java | 69 +++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 1997264..f7cfba0 100755 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -210,6 +210,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, { case 27: // escape key deselectAllSequenceMenuItem_actionPerformed(); + + alignPanel.alabels.cancelDrag(); break; case KeyEvent.VK_X: if (evt.isControlDown() || evt.isMetaDown()) diff --git a/src/jalview/appletgui/AnnotationLabels.java b/src/jalview/appletgui/AnnotationLabels.java index 2344719..27c579a 100755 --- a/src/jalview/appletgui/AnnotationLabels.java +++ b/src/jalview/appletgui/AnnotationLabels.java @@ -23,7 +23,6 @@ import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; - import jalview.datamodel.*; public class AnnotationLabels extends Panel implements ActionListener, @@ -224,7 +223,6 @@ public class AnnotationLabels extends Panel implements ActionListener, public void mouseMoved(MouseEvent evt) { resizePanel = evt.getY() < 10 && evt.getX() < 14; - int row = getSelectedRow(evt.getY() + scrollOffset); if (row > -1) @@ -246,13 +244,34 @@ public class AnnotationLabels extends Panel implements ActionListener, { tooltip.setTip(""); } - } + /** + * curent drag position + */ MouseEvent dragEvent = null; + /** + * flag to indicate drag events should be ignored + */ + private boolean dragCancelled = false; + + /** + * clear any drag events in progress + */ + public void cancelDrag() + { + dragEvent = null; + dragCancelled = true; + } + public void mouseDragged(MouseEvent evt) { + if (dragCancelled) + { + return; + } + ; dragEvent = evt; if (resizePanel) @@ -285,6 +304,22 @@ public class AnnotationLabels extends Panel implements ActionListener, } else { + int diff; + if ((diff = 6 - evt.getY()) > 0) + { + // nudge scroll up + ap.apvscroll.setValue(ap.apvscroll.getValue() - diff); + ap.adjustmentValueChanged(null); + + } + else if ((0 < (diff = 6 + - ap.annotationSpaceFillerHolder.getSize().height + + evt.getY()))) + { + // nudge scroll down + ap.apvscroll.setValue(ap.apvscroll.getValue() + diff); + ap.adjustmentValueChanged(null); + } repaint(); } } @@ -295,8 +330,31 @@ public class AnnotationLabels extends Panel implements ActionListener, public void mouseReleased(MouseEvent evt) { + if (!dragCancelled) + { + int start = selectedRow; + + int end = getSelectedRow(evt.getY() + scrollOffset); + + if (start != end) + { + // Swap these annotations + AlignmentAnnotation startAA = ap.av.alignment + .getAlignmentAnnotation()[start]; + if (end == -1) + { + end = ap.av.alignment.getAlignmentAnnotation().length - 1; + } + AlignmentAnnotation endAA = ap.av.alignment + .getAlignmentAnnotation()[end]; + + ap.av.alignment.getAlignmentAnnotation()[end] = startAA; + ap.av.alignment.getAlignmentAnnotation()[start] = endAA; + } + } resizePanel = false; dragEvent = null; + dragCancelled = false; repaint(); ap.annotationPanel.repaint(); } @@ -312,6 +370,7 @@ public class AnnotationLabels extends Panel implements ActionListener, public void mouseExited(MouseEvent evt) { + dragCancelled = false; if (dragEvent == null) { @@ -334,6 +393,7 @@ public class AnnotationLabels extends Panel implements ActionListener, { return; } + dragCancelled=false; // todo: move below to mouseClicked ? selectedRow = getSelectedRow(evt.getY() + scrollOffset); @@ -637,7 +697,7 @@ public class AnnotationLabels extends Panel implements ActionListener, g.drawLine(2, 8, 5, 2); g.drawLine(5, 2, 8, 8); } - else if (dragEvent != null && aa != null) + else if (!dragCancelled && dragEvent != null && aa != null) { g.setColor(Color.lightGray); g.drawString(aa[selectedRow].label, dragEvent.getX(), @@ -651,5 +711,4 @@ public class AnnotationLabels extends Panel implements ActionListener, g.drawString("to add annotation", 2, 18); } } - } -- 1.7.10.2