import java.awt.event.*;
import java.awt.image.BufferedImage;
-
import jalview.datamodel.*;
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)
{
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)
}
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();
}
}
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();
}
public void mouseExited(MouseEvent evt)
{
+ dragCancelled = false;
if (dragEvent == null)
{
{
return;
}
+ dragCancelled=false;
// todo: move below to mouseClicked ?
selectedRow = getSelectedRow(evt.getY() + scrollOffset);
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(),
g.drawString("to add annotation", 2, 18);
}
}
-
}