X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FSeqPanel.java;h=401bd0a30b5933a16d5759eacc6d2184b3de7fb0;hb=ad8b755b7d5daaa914a61fc4ca476196551b2f0a;hp=cb14b0e3b7e42a2295b3db00ad2d39f8dc36b4d4;hpb=948bd3bcbacc509da0cefaae3eedd97300a6ccce;p=jalview.git diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index cb14b0e..401bd0a 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -48,6 +48,7 @@ import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportRanges; import java.awt.BorderLayout; import java.awt.Color; @@ -628,13 +629,14 @@ public class SeqPanel extends JPanel return; } - if (!editingSeqs) + if (editingSeqs) + { + endEditing(); + } + else { doMouseReleasedDefineMode(evt, didDrag); - return; } - - endEditing(); } /** @@ -1161,9 +1163,9 @@ public class SeqPanel extends JPanel } mouseDragging = true; - if ((scrollThread != null) && (scrollThread.isRunning())) + if (scrollThread != null) { - scrollThread.setEvent(evt); + scrollThread.setMousePosition(evt.getPoint()); } } @@ -1575,10 +1577,10 @@ public class SeqPanel extends JPanel } /** - * DOCUMENT ME! + * On reentering the panel, stops any scrolling that was started on dragging + * out of the panel * * @param e - * DOCUMENT ME! */ @Override public void mouseEntered(MouseEvent e) @@ -1587,29 +1589,19 @@ public class SeqPanel extends JPanel { oldSeq = 0; } - - if ((scrollThread != null) && (scrollThread.isRunning())) - { - scrollThread.stopScrolling(); - scrollThread = null; - } + stopScrolling(); } /** - * DOCUMENT ME! + * On leaving the panel, if the mouse is being dragged, starts a thread to + * scroll it until the mouse is released (in unwrapped mode only) * * @param e - * DOCUMENT ME! */ @Override public void mouseExited(MouseEvent e) { - if (av.getWrapAlignment()) - { - return; - } - - if (mouseDragging && scrollThread == null) + if (!av.getWrapAlignment() && mouseDragging && scrollThread == null) { scrollThread = new ScrollThread(); } @@ -1670,7 +1662,8 @@ public class SeqPanel extends JPanel public void mouseWheelMoved(MouseWheelEvent e) { e.consume(); - if (e.getWheelRotation() > 0) + double wheelRotation = e.getPreciseWheelRotation(); + if (wheelRotation > 0) { if (e.isShiftDown()) { @@ -1682,7 +1675,7 @@ public class SeqPanel extends JPanel av.getRanges().scrollUp(false); } } - else + else if (wheelRotation < 0) { if (e.isShiftDown()) { @@ -1918,10 +1911,7 @@ public class SeqPanel extends JPanel return; } - if (res >= av.getAlignment().getWidth()) - { - res = av.getAlignment().getWidth() - 1; - } + res = Math.min(res, av.getAlignment().getWidth()-1); if (stretchGroup.getEndRes() == res) { @@ -2007,89 +1997,126 @@ public class SeqPanel extends JPanel mouseDragging = true; - if ((scrollThread != null) && (scrollThread.isRunning())) + if (scrollThread != null) { - scrollThread.setEvent(evt); + scrollThread.setMousePosition(evt.getPoint()); } } - void scrollCanvas(MouseEvent evt) + /** + * Stops the scroll thread if it is running + */ + void stopScrolling() { - if (evt == null) + if (scrollThread != null) { - if ((scrollThread != null) && (scrollThread.isRunning())) - { - scrollThread.stopScrolling(); - scrollThread = null; - } - mouseDragging = false; + scrollThread.stopScrolling(); + scrollThread = null; } - else - { - if (scrollThread == null) - { - scrollThread = new ScrollThread(); - } + mouseDragging = false; + } - mouseDragging = true; - scrollThread.setEvent(evt); + /** + * Starts a thread to scroll the alignment, towards a given mouse position + * outside the panel bounds + * + * @param mousePos + */ + void startScrolling(Point mousePos) + { + if (scrollThread == null) + { + scrollThread = new ScrollThread(); } + mouseDragging = true; + scrollThread.setMousePosition(mousePos); } - // this class allows scrolling off the bottom of the visible alignment + /** + * Performs scrolling of the visible alignment left, right, up or down + */ class ScrollThread extends Thread { - MouseEvent evt; + private Point mousePos; private volatile boolean threadRunning = true; + /** + * Constructor + */ public ScrollThread() { + setName("SeqPanel$ScrollThread"); start(); } - public void setEvent(MouseEvent e) + /** + * Sets the position of the mouse that determines the direction of the + * scroll to perform + * + * @param p + */ + public void setMousePosition(Point p) { - evt = e; + mousePos = p; } + /** + * Sets a flag that will cause the thread to exit + */ public void stopScrolling() { threadRunning = false; } - public boolean isRunning() - { - return threadRunning; - } - + /** + * Scrolls the alignment left or right, and/or up or down, depending on the + * last notified mouse position, until the limit of the alignment is + * reached, or a flag is set to stop the scroll + */ @Override public void run() { - while (threadRunning) + while (threadRunning && mouseDragging) { - if (evt != null) + if (mousePos != null) { - if (mouseDragging && (evt.getY() < 0) - && (av.getRanges().getStartSeq() > 0)) + boolean scrolled = false; + ViewportRanges ranges = SeqPanel.this.av.getRanges(); + + /* + * scroll up or down + */ + if (mousePos.y < 0) { - av.getRanges().scrollUp(true); + // mouse is above this panel - try scroll up + scrolled = ranges.scrollUp(true); } - - if (mouseDragging && (evt.getY() >= getHeight()) && (av - .getAlignment().getHeight() > av.getRanges().getEndSeq())) + else if (mousePos.y >= getHeight()) { - av.getRanges().scrollUp(false); + // mouse is below this panel - try scroll down + scrolled = ranges.scrollUp(false); } - if (mouseDragging && (evt.getX() < 0)) + /* + * scroll left or right + */ + if (mousePos.x < 0) + { + scrolled |= ranges.scrollRight(false); + } + else if (mousePos.x >= getWidth()) { - av.getRanges().scrollRight(false); + scrolled |= ranges.scrollRight(true); } - else if (mouseDragging && (evt.getX() >= getWidth())) + if (!scrolled) { - av.getRanges().scrollRight(true); + /* + * we have reached the limit of the visible alignment - quit + */ + threadRunning = false; + SeqPanel.this.ap.repaint(); } } @@ -2291,4 +2318,13 @@ public class SeqPanel extends JPanel return true; } + + /** + * + * @return null or last search results handled by this panel + */ + public SearchResultsI getLastSearchResults() + { + return lastSearchResults; + } }