| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.gui.chart; |
| 27 |
|
| 28 |
import java.awt.*; |
| 29 |
import java.awt.event.*; |
| 30 |
import java.awt.geom.Point2D; |
| 31 |
import java.awt.geom.Rectangle2D; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class ChartSelector implements MouseListener, MouseMotionListener { |
| 38 |
|
| 39 |
public ChartSelector(JChart chart) { |
| 40 |
this.chart = chart; |
| 41 |
chart.addMouseListener(this); |
| 42 |
chart.addMouseMotionListener(this); |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
public boolean isCrossHairCursor() { |
| 47 |
return crossHairCursor; |
| 48 |
} |
| 49 |
|
| 50 |
public void setCrossHairCursor(boolean crossHairCursor) { |
| 51 |
this.crossHairCursor = crossHairCursor; |
| 52 |
} |
| 53 |
|
| 54 |
private void setupCursor() { |
| 55 |
if (crossHairCursor) { |
| 56 |
chart.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); |
| 57 |
} else { |
| 58 |
chart.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
| 59 |
} |
| 60 |
|
| 61 |
chart.repaint(); |
| 62 |
} |
| 63 |
|
| 64 |
public void mouseClicked(MouseEvent mouseEvent) { |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
public void mousePressed(MouseEvent mouseEvent) { |
| 84 |
|
| 85 |
|
| 86 |
dragPoint = new Point2D.Double(mouseEvent.getPoint().getX(), mouseEvent.getPoint().getY()); |
| 87 |
if (!mouseEvent.isShiftDown()) { |
| 88 |
chart.clearSelection(); |
| 89 |
} |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
public void mouseReleased(MouseEvent mouseEvent) { |
| 94 |
if (chart == null) { |
| 95 |
return; |
| 96 |
} |
| 97 |
|
| 98 |
double x1 = Math.min(dragPoint.getX(), mouseEvent.getPoint().getX()); |
| 99 |
double y1 = Math.min(dragPoint.getY(), mouseEvent.getPoint().getY()); |
| 100 |
double x2 = Math.max(dragPoint.getX(), mouseEvent.getPoint().getX()); |
| 101 |
double y2 = Math.max(dragPoint.getY(), mouseEvent.getPoint().getY()); |
| 102 |
chart.selectPoints(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1), mouseEvent.isShiftDown()); |
| 103 |
|
| 104 |
chart.setDragRectangle(null); |
| 105 |
} |
| 106 |
|
| 107 |
public void mouseEntered(MouseEvent mouseEvent) { |
| 108 |
} |
| 109 |
|
| 110 |
public void mouseExited(MouseEvent mouseEvent) { |
| 111 |
} |
| 112 |
|
| 113 |
public void mouseMoved(MouseEvent mouseEvent) { |
| 114 |
} |
| 115 |
|
| 116 |
public void mouseDragged(MouseEvent mouseEvent) { |
| 117 |
|
| 118 |
if (dragPoint == null) { |
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
double x1 = Math.min(dragPoint.getX(), mouseEvent.getPoint().getX()); |
| 123 |
double y1 = Math.min(dragPoint.getY(), mouseEvent.getPoint().getY()); |
| 124 |
double x2 = Math.max(dragPoint.getX(), mouseEvent.getPoint().getX()); |
| 125 |
double y2 = Math.max(dragPoint.getY(), mouseEvent.getPoint().getY()); |
| 126 |
chart.setDragRectangle(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1)); |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
private JChart chart; |
| 131 |
private Point2D dragPoint = null; |
| 132 |
|
| 133 |
private boolean crossHairCursor = false; |
| 134 |
} |