From fae86f8127622397f9df1e120c85546f1656a33b Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 8 Mar 2018 11:29:11 +0000 Subject: [PATCH] JAL-2930 use MouseWheelEvent.getPreciseWheelRotation, not getWheelRotation --- src/jalview/gui/AnnotationPanel.java | 5 ++-- src/jalview/gui/IdPanel.java | 5 ++-- src/jalview/gui/RotatableCanvas.java | 46 ++++++++++++++++++++++++---------- src/jalview/gui/SeqPanel.java | 5 ++-- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 260b771..dee56b0 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -175,11 +175,12 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, if (e.isShiftDown()) { e.consume(); - if (e.getWheelRotation() > 0) + double wheelRotation = e.getPreciseWheelRotation(); + if (wheelRotation > 0) { av.getRanges().scrollRight(true); } - else + else if (wheelRotation < 0) { av.getRanges().scrollRight(false); } diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 1f2a3ad..f2761ab 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -148,7 +148,8 @@ public class IdPanel extends JPanel public void mouseWheelMoved(MouseWheelEvent e) { e.consume(); - if (e.getWheelRotation() > 0) + double wheelRotation = e.getPreciseWheelRotation(); + if (wheelRotation > 0) { if (e.isShiftDown()) { @@ -159,7 +160,7 @@ public class IdPanel extends JPanel av.getRanges().scrollUp(false); } } - else + else if (wheelRotation < 0) { if (e.isShiftDown()) { diff --git a/src/jalview/gui/RotatableCanvas.java b/src/jalview/gui/RotatableCanvas.java index 4ef18d4..02368df 100755 --- a/src/jalview/gui/RotatableCanvas.java +++ b/src/jalview/gui/RotatableCanvas.java @@ -128,7 +128,6 @@ public class RotatableCanvas extends JPanel implements MouseListener, boolean applyToAllViews = false; - // Controller controller; public RotatableCanvas(AlignmentPanel ap) { this.av = ap.av; @@ -136,16 +135,23 @@ public class RotatableCanvas extends JPanel implements MouseListener, addMouseWheelListener(new MouseWheelListener() { + @Override public void mouseWheelMoved(MouseWheelEvent e) { - if (e.getWheelRotation() > 0) + double wheelRotation = e.getPreciseWheelRotation(); + if (wheelRotation > 0) { + /* + * zoom in + */ scale = (float) (scale * 1.1); repaint(); } - - else + else if (wheelRotation < 0) { + /* + * zoom out + */ scale = (float) (scale * 0.9); repaint(); } @@ -162,6 +168,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, boolean first = true; + @Override public void setPoints(Vector points, int npoint) { this.points = points; @@ -327,7 +334,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, dim = height; } - return (float) ((dim * scalefactor) / (2 * maxwidth)); + return (dim * scalefactor) / (2 * maxwidth); } /** @@ -352,6 +359,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * * @return DOCUMENT ME! */ + @Override public Dimension getPreferredSize() { if (prefsize != null) @@ -369,6 +377,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * * @return DOCUMENT ME! */ + @Override public Dimension getMinimumSize() { return getPreferredSize(); @@ -380,6 +389,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param g * DOCUMENT ME! */ + @Override public void paintComponent(Graphics g1) { @@ -475,8 +485,8 @@ public class RotatableCanvas extends JPanel implements MouseListener, for (int i = 0; i < npoint; i++) { SequencePoint sp = (SequencePoint) points.elementAt(i); - int x = (int) ((float) (sp.coord[0] - centre[0]) * scale) + halfwidth; - int y = (int) ((float) (sp.coord[1] - centre[1]) * scale) + int x = (int) ((sp.coord[0] - centre[0]) * scale) + halfwidth; + int y = (int) ((sp.coord[1] - centre[1]) * scale) + halfheight; float z = sp.coord[1] - centre[2]; @@ -547,6 +557,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void keyTyped(KeyEvent evt) { } @@ -557,6 +568,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void keyReleased(KeyEvent evt) { } @@ -567,6 +579,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void keyPressed(KeyEvent evt) { if (evt.getKeyCode() == KeyEvent.VK_UP) @@ -598,6 +611,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseClicked(MouseEvent evt) { } @@ -608,6 +622,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseEntered(MouseEvent evt) { } @@ -618,6 +633,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseExited(MouseEvent evt) { } @@ -628,6 +644,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseReleased(MouseEvent evt) { } @@ -638,6 +655,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mousePressed(MouseEvent evt) { int x = evt.getX(); @@ -690,6 +708,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, // controller.handleSequenceSelectionEvent(new // SequenceSelectionEvent(this,sel)); // } + @Override public void mouseMoved(MouseEvent evt) { SequenceI found = findPoint(evt.getX(), evt.getY()); @@ -710,6 +729,7 @@ public class RotatableCanvas extends JPanel implements MouseListener, * @param evt * DOCUMENT ME! */ + @Override public void mouseDragged(MouseEvent evt) { mx = evt.getX(); @@ -725,8 +745,8 @@ public class RotatableCanvas extends JPanel implements MouseListener, { rotmat.setIdentity(); - rotmat.rotate((float) (my - omy), 'x'); - rotmat.rotate((float) (mx - omx), 'y'); + rotmat.rotate(my - omy, 'x'); + rotmat.rotate(mx - omx, 'y'); for (int i = 0; i < npoint; i++) { @@ -774,9 +794,9 @@ public class RotatableCanvas extends JPanel implements MouseListener, { SequencePoint sp = (SequencePoint) points.elementAt(i); int tmp1 = (int) (((sp.coord[0] - centre[0]) * scale) - + ((float) getWidth() / 2.0)); + + (getWidth() / 2.0)); int tmp2 = (int) (((sp.coord[1] - centre[1]) * scale) - + ((float) getHeight() / 2.0)); + + (getHeight() / 2.0)); if ((tmp1 > x1) && (tmp1 < x2) && (tmp2 > y1) && (tmp2 < y2)) { @@ -816,9 +836,9 @@ public class RotatableCanvas extends JPanel implements MouseListener, for (int i = 0; i < npoint; i++) { SequencePoint sp = (SequencePoint) points.elementAt(i); - int px = (int) ((float) (sp.coord[0] - centre[0]) * scale) + int px = (int) ((sp.coord[0] - centre[0]) * scale) + halfwidth; - int py = (int) ((float) (sp.coord[1] - centre[1]) * scale) + int py = (int) ((sp.coord[1] - centre[1]) * scale) + halfheight; if ((Math.abs(px - x) < 3) && (Math.abs(py - y) < 3)) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 84b85e9..dd8def0 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1669,7 +1669,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()) { @@ -1681,7 +1682,7 @@ public class SeqPanel extends JPanel av.getRanges().scrollUp(false); } } - else + else if (wheelRotation < 0) { if (e.isShiftDown()) { -- 1.7.10.2