From ddc7f53dd8398442e2025d11330fa8dfe2f8dd35 Mon Sep 17 00:00:00 2001 From: jprocter Date: Sat, 1 Sep 2012 13:08:27 +0100 Subject: [PATCH] JAL-1161 JAL-1160 implement custom mousewheel listener and increased scroll increment for annotation panel --- src/jalview/gui/AnnotationLabels.java | 1 + src/jalview/gui/AnnotationPanel.java | 83 ++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 319dcf4..533b22c 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -115,6 +115,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, addMouseListener(this); addMouseMotionListener(this); + addMouseWheelListener(ap.annotationPanel); } public AnnotationLabels(AlignViewport av) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index df29464..411c244 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -32,8 +32,8 @@ import jalview.renderer.AwtRenderPanelI; * @version $Revision$ */ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, - MouseListener, MouseMotionListener, ActionListener, - AdjustmentListener + MouseListener, MouseWheelListener, MouseMotionListener, + ActionListener, AdjustmentListener, Scrollable { final String HELIX = "Helix"; @@ -95,6 +95,8 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, public final AnnotationRenderer renderer; + private MouseWheelListener[] _mwl; + /** * Creates a new AnnotationPanel object. * @@ -116,6 +118,10 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, addMouseMotionListener(this); ap.annotationScroller.getVerticalScrollBar() .addAdjustmentListener(this); + // save any wheel listeners on the scroller, so we can propagate scroll events to them. + _mwl = ap.annotationScroller.getMouseWheelListeners(); + // and then set our own listener to consume all mousewheel events + ap.annotationScroller.addMouseWheelListener(this); renderer = new AnnotationRenderer(); } @@ -125,15 +131,78 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, renderer = new AnnotationRenderer(); } - /** - * DOCUMENT ME! - * - * @param evt - * DOCUMENT ME! + @Override + public void mouseWheelMoved(MouseWheelEvent e) + { + if (e.isShiftDown()) + { + e.consume(); + if (e.getWheelRotation() > 0) + { + ap.scrollRight(true); + } + else + { + ap.scrollRight(false); + } + } + else + { + // TODO: find the correct way to let the event bubble up to ap.annotationScroller + for (MouseWheelListener mwl : _mwl) + { + if (mwl != null) + { + mwl.mouseWheelMoved(e); + } + if (e.isConsumed()) + { + break; + } + } + } + } + + @Override + public Dimension getPreferredScrollableViewportSize() + { + return getPreferredSize(); + } + + @Override + public int getScrollableBlockIncrement(Rectangle visibleRect, + int orientation, int direction) + { + return 30; + } + + @Override + public boolean getScrollableTracksViewportHeight() + { + return false; + } + + @Override + public boolean getScrollableTracksViewportWidth() + { + return true; + } + + @Override + public int getScrollableUnitIncrement(Rectangle visibleRect, + int orientation, int direction) + { + return 30; + } + + /* + * (non-Javadoc) + * @see java.awt.event.AdjustmentListener#adjustmentValueChanged(java.awt.event.AdjustmentEvent) */ @Override public void adjustmentValueChanged(AdjustmentEvent evt) { + // update annotation label display ap.alabels.setScrollOffset(-evt.getValue()); } -- 1.7.10.2