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 <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2013-06-15 12:12:22 -05:00
parent e6a69d29bd
commit 09812fe5df

View File

@ -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);