|
21 | 21 | import java.awt.Dimension;
|
22 | 22 | import java.awt.Graphics;
|
23 | 23 | import java.awt.event.MouseEvent;
|
| 24 | +import java.awt.event.MouseWheelEvent; |
24 | 25 | import java.io.IOException;
|
25 | 26 | import javax.swing.JMenu;
|
26 | 27 | import javax.swing.JMenuItem;
|
@@ -68,6 +69,10 @@ public class IrPlotter extends HarcPanel {
|
68 | 69 | private final static Color endingColor = Color.GREEN;
|
69 | 70 | private final static int invalid = -1;
|
70 | 71 |
|
| 72 | + private final static int RESET_MOUSE_BUTTON = 6; |
| 73 | + private final static double BASIS = 1.05; |
| 74 | + private final static double LOGBASIS = Math.log(BASIS); |
| 75 | + |
71 | 76 | /** max horizontal coordinate, in microseconds */
|
72 | 77 | private int xmin = 0;
|
73 | 78 | private int xmax = 200000;
|
@@ -193,7 +198,8 @@ private void setDragBegin(int x) {
|
193 | 198 |
|
194 | 199 | private void setDragEnd(int x) {
|
195 | 200 | if (dragBeginX != invalid && Math.abs(dragBeginX - x) > dragThreshold) {
|
196 |
| - xmin = screenX2x(Math.min(dragBeginX, x)); |
| 201 | + // Nothing interesting is going on for negative x's, so force xmin non-negative |
| 202 | + xmin = Math.max(screenX2x(Math.min(dragBeginX, x)), 0); |
197 | 203 | xmax = screenX2x(Math.max(dragBeginX, x));
|
198 | 204 | //System.err.println("End: " + x + " " + screenX2x(x));
|
199 | 205 | }
|
@@ -329,7 +335,7 @@ private int[] getTickValues(int xmin, int xmax, int pixelWidth) {
|
329 | 335 | int tickWidth = rounder((int)Math.round(goalWidth));
|
330 | 336 | useMilliSeconds = tickWidth >= 5000;
|
331 | 337 | int newXmin = xmin/tickWidth*tickWidth;
|
332 |
| - this.xmin = newXmin; |
| 338 | + //this.xmin = newXmin; |
333 | 339 | int noTicks = (int) Math.ceil(((double)(xmax-newXmin))/tickWidth) + 1;
|
334 | 340 | if (noTicks <= 0) {
|
335 | 341 | System.err.println(">>>>>>>>>>>>>>" + xmax + " " + newXmin + " " + tickWidth + " " + goalWidth);
|
@@ -398,14 +404,38 @@ else if (evt.getButton() == MouseEvent.BUTTON3)
|
398 | 404 |
|
399 | 405 | @Override
|
400 | 406 | public void mouseReleased(java.awt.event.MouseEvent evt) {
|
401 |
| - if (evt.getButton() == MouseEvent.BUTTON1) |
402 |
| - setDragEnd(evt.getX()); |
403 |
| - else if (evt.getButton() == MouseEvent.BUTTON3) |
404 |
| - if (evt.isPopupTrigger()) |
405 |
| - plotterPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); |
| 407 | + switch (evt.getButton()) { |
| 408 | + case MouseEvent.BUTTON1: |
| 409 | + setDragEnd(evt.getX()); |
| 410 | + break; |
| 411 | + case MouseEvent.BUTTON3: |
| 412 | + if (evt.isPopupTrigger()) |
| 413 | + plotterPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); |
| 414 | + break; |
| 415 | + case RESET_MOUSE_BUTTON: |
| 416 | + reset(); |
| 417 | + break; |
| 418 | + default: |
| 419 | + ; // nothing |
| 420 | + } |
406 | 421 | }
|
407 | 422 | });
|
408 | 423 |
|
| 424 | + addMouseWheelListener((MouseWheelEvent evt) -> { |
| 425 | + int screenX = evt.getX(); |
| 426 | + int myX = screenX2x(screenX); |
| 427 | + double length = xmax - xmin; |
| 428 | + double frac = (myX - xmin) / length; |
| 429 | + double noClicks = evt.getPreciseWheelRotation(); |
| 430 | + double factor = Math.exp(noClicks * LOGBASIS); |
| 431 | + double toReduce = (factor - 1.0) * length; |
| 432 | + double left = toReduce * frac; |
| 433 | + double right = toReduce * (1.0 - frac); |
| 434 | + xmin += (int) left; |
| 435 | + xmax -= (int) right; |
| 436 | + repaint(); |
| 437 | + }); |
| 438 | + |
409 | 439 | addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
|
410 | 440 | @Override
|
411 | 441 | public void mouseDragged(java.awt.event.MouseEvent evt) {
|
|
0 commit comments