From 2ac76a67e4f3421b4dee3ffa8fbb5956692dfda5 Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 4 Sep 2017 15:57:49 +0100 Subject: [PATCH] JAL-2673 Attempt to stop infinite scrolling etc --- src/jalview/gui/SeqPanel.java | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 328dfdc..cb29c3f 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1095,7 +1095,7 @@ public class SeqPanel extends JPanel } mouseDragging = true; - if (scrollThread != null) + if ((scrollThread != null) && (scrollThread.isRunning())) { scrollThread.setEvent(evt); } @@ -1521,9 +1521,9 @@ public class SeqPanel extends JPanel oldSeq = 0; } - if (scrollThread != null) + if ((scrollThread != null) && (scrollThread.isRunning())) { - scrollThread.running = false; + scrollThread.stopScrolling(); scrollThread = null; } } @@ -1949,7 +1949,7 @@ public class SeqPanel extends JPanel mouseDragging = true; - if (scrollThread != null) + if ((scrollThread != null) && (scrollThread.isRunning())) { scrollThread.setEvent(evt); } @@ -1959,9 +1959,9 @@ public class SeqPanel extends JPanel { if (evt == null) { - if (scrollThread != null) + if ((scrollThread != null) && (scrollThread.isRunning())) { - scrollThread.running = false; + scrollThread.stopScrolling(); scrollThread = null; } mouseDragging = false; @@ -1984,7 +1984,7 @@ public class SeqPanel extends JPanel { MouseEvent evt; - boolean running = false; + private volatile boolean threadRunning = true; public ScrollThread() { @@ -1998,37 +1998,40 @@ public class SeqPanel extends JPanel public void stopScrolling() { - running = false; + threadRunning = false; + } + + public boolean isRunning() + { + return threadRunning; } @Override public void run() { - running = true; - - while (running) + while (threadRunning) { if (evt != null) { if (mouseDragging && (evt.getY() < 0) && (av.getRanges().getStartSeq() > 0)) { - running = av.getRanges().scrollUp(true); + av.getRanges().scrollUp(true); } if (mouseDragging && (evt.getY() >= getHeight()) && (av .getAlignment().getHeight() > av.getRanges().getEndSeq())) { - running = av.getRanges().scrollUp(false); + av.getRanges().scrollUp(false); } if (mouseDragging && (evt.getX() < 0)) { - running = av.getRanges().scrollRight(false); + av.getRanges().scrollRight(false); } else if (mouseDragging && (evt.getX() >= getWidth())) { - running = av.getRanges().scrollRight(true); + av.getRanges().scrollRight(true); } } -- 1.7.10.2