From: James Procter Date: Thu, 14 Dec 2023 14:14:15 +0000 (+0000) Subject: Merge branch 'develop' into bug/JAL-2934proportionalScrolling X-Git-Tag: Release_2_11_3_3~8^2~2^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3ba561cc50d627d9426285993988d3d99c2232f8;hp=deb7e7788d802d45cc6b2f8a5a04285308f1e8ee;p=jalview.git Merge branch 'develop' into bug/JAL-2934proportionalScrolling --- diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index d3f80ce..8e7c745 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -42,6 +42,7 @@ import java.io.FileWriter; import java.io.PrintWriter; import java.util.List; +import javax.swing.BoundedRangeModel; import javax.swing.SwingUtilities; import jalview.analysis.AnnotationSorter; @@ -789,6 +790,22 @@ public class AlignmentPanel extends GAlignmentPanel implements } /** + * Answers true if the panel has no horizontal scrollbar, or the scrollbar is + * at its rightmost position, else false. + * + * @return + */ + boolean isScrolledFullyRight() + { + if (hscroll == null) + { + return true; + } + BoundedRangeModel model = hscroll.getModel(); + return (model.getExtent() + model.getValue() >= model.getMaximum()); + } + + /** * Respond to adjustment event when horizontal or vertical scrollbar is * changed * diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 68ceff0..ea32684 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -192,21 +192,27 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, renderer = new AnnotationRenderer(); } + /** + * Responds to a mouse wheel movement by scrolling the annotations up or down. + * Annotation labels are scrolled via method adjustmentValueChanged when the + * vertical scrollbar is adjusted. + *

+ * If shift is pressed, then scrolling is left or right instead, and is + * delegated to AlignmentPanel, so that both sequences and annotations are + * scrolled together. + *

+ * This object is a MouseWheelListener to AnnotationLabels, so mouse wheel + * events over the labels are delegated to this method. + *

+ * Note that this method may also be fired by scrolling with a gesture on a + * trackpad. + */ @Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.isShiftDown()) { - e.consume(); - double wheelRotation = e.getPreciseWheelRotation(); - if (wheelRotation > 0) - { - av.getRanges().scrollRight(true); - } - else if (wheelRotation < 0) - { - av.getRanges().scrollRight(false); - } + ap.getSeqPanel().mouseWheelMoved(e); } else { diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 7b491e4..3fff67b 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -26,8 +26,6 @@ import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; import java.util.List; import javax.swing.JPanel; @@ -50,12 +48,9 @@ import jalview.viewmodel.ViewportRanges; /** * This panel hosts alignment sequence ids and responds to mouse clicks on them, * as well as highlighting ids matched by a search from the Find menu. - * - * @author $author$ - * @version $Revision$ */ public class IdPanel extends JPanel - implements MouseListener, MouseMotionListener, MouseWheelListener + implements MouseListener, MouseMotionListener { private IdCanvas idCanvas; @@ -90,7 +85,7 @@ public class IdPanel extends JPanel add(getIdCanvas(), BorderLayout.CENTER); addMouseListener(this); addMouseMotionListener(this); - addMouseWheelListener(this); + addMouseWheelListener(alignPanel.getSeqPanel()); ToolTipManager.sharedInstance().registerComponent(this); } @@ -171,38 +166,6 @@ public class IdPanel extends JPanel } /** - * Response to the mouse wheel by scrolling the alignment panel. - */ - @Override - public void mouseWheelMoved(MouseWheelEvent e) - { - e.consume(); - double wheelRotation = e.getPreciseWheelRotation(); - if (wheelRotation > 0) - { - if (e.isShiftDown()) - { - av.getRanges().scrollRight(true); - } - else - { - av.getRanges().scrollUp(false); - } - } - else if (wheelRotation < 0) - { - if (e.isShiftDown()) - { - av.getRanges().scrollRight(false); - } - else - { - av.getRanges().scrollUp(true); - } - } - } - - /** * Handle a mouse click event. Currently only responds to a double-click. The * action is to try to open a browser window at a URL that searches for the * selected sequence id. The search URL is configured in Preferences | diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 2caea17..845004b 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -2221,32 +2221,85 @@ public class SeqPanel extends JPanel } } + /** + * Responds to a mouse wheel movement by scrolling the alignment + *

+ * Note that this method may also be fired by scrolling with a gesture on a + * trackpad. + */ @Override public void mouseWheelMoved(MouseWheelEvent e) { e.consume(); double wheelRotation = e.getPreciseWheelRotation(); + + /* + * scroll more for large (fast) mouse movements + */ + int size = 1 + (int) Math.abs(wheelRotation); + if (wheelRotation > 0) { if (e.isShiftDown()) { - av.getRanges().scrollRight(true); - + /* + * scroll right + * stop trying to scroll right when limit is reached (saves + * expensive calls to Alignment.getWidth()) + */ + while (size-- > 0 && !ap.isScrolledFullyRight()) + { + if (!av.getRanges().scrollRight(true)) + { + break; + } + } } else { - av.getRanges().scrollUp(false); + /* + * scroll down + */ + while (size-- > 0) + { + if (!av.getRanges().scrollUp(false)) + { + break; + } + } } } else if (wheelRotation < 0) { if (e.isShiftDown()) { - av.getRanges().scrollRight(false); + /* + * scroll left + */ + while (size-- > 0) + { + if (!av.getRanges().scrollRight(false)) + { + break; + } + } } else { - av.getRanges().scrollUp(true); + /* + * scroll up + */ + while (size-- > 0) + { + if (!av.getRanges().scrollUp(true)) + { + break; + } + } } }