From 09812fe5dfaeb4a96485362bfdb3406ff9958a2e Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Sat, 15 Jun 2013 12:12:22 -0500 Subject: [PATCH] cooja TimeLine: support mouse wheel zoom Add listener that zooms based on mouse wheel. The zoom center is the mouse position, which alleviates the pressure to touch pabigot/contikix#4. Closes pabigot/contikix#5 Signed-off-by: Peter A. Bigot --- tools/cooja/java/se/sics/cooja/plugins/TimeLine.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/cooja/java/se/sics/cooja/plugins/TimeLine.java b/tools/cooja/java/se/sics/cooja/plugins/TimeLine.java index 730af29d7..cfd29ceea 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/TimeLine.java +++ b/tools/cooja/java/se/sics/cooja/plugins/TimeLine.java @@ -43,6 +43,7 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; @@ -1499,6 +1500,7 @@ public class TimeLine extends VisPlugin implements HasQuickHelp { addMouseListener(mouseAdapter); addMouseMotionListener(mouseAdapter); + addMouseWheelListener(mouseAdapter); /* Popup menu */ final JPopupMenu popupMenu = new JPopupMenu(); @@ -1696,6 +1698,16 @@ public class TimeLine extends VisPlugin implements HasQuickHelp { mousePixelPositionX = -1; repaint(); } + public void mouseWheelMoved(MouseWheelEvent e) { + if (e.isControlDown()) { + final int nticks = e.getWheelRotation(); + final int zoomLevel = zoomGetLevel() + nticks; + final long zct = (long) (e.getX()*currentPixelDivisor); + final double zc = (double) (e.getX() - timeline.getVisibleRect().x) / timeline.getVisibleRect().width; + zoomFinishLevel(zoomLevel, zct, zc); + return; + } + } }; private final Color SEPARATOR_COLOR = new Color(220, 220, 220);