-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPlotPanleMouseListener.java
More file actions
73 lines (63 loc) · 1.6 KB
/
Copy pathPlotPanleMouseListener.java
File metadata and controls
73 lines (63 loc) · 1.6 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.sin.java.plot;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
/**
* 绘图面板鼠标监听器
*
* @author RobinTang
*
*/
public class PlotPanleMouseListener implements MouseListener, MouseMotionListener {
private PlotPanle panle = null;
private int downX;
private int downY;
public PlotPanleMouseListener(PlotPanle panle) {
super();
this.panle = panle;
}
@Override
public void mouseClicked(MouseEvent e) {
int ix = panle.getDrawableObjectByXY(e.getX(), e.getY());
if (ix >= 0) {
panle.toggleShow(ix);
} else if (e.getClickCount() >= 2) {
if (e.getButton() == MouseEvent.BUTTON1)
panle.zoomIn(e.getX(), e.getY());
else if (e.getButton() == MouseEvent.BUTTON3) {
panle.zoomOut(e.getX(), e.getY());
}
}
}
@Override
public void mousePressed(MouseEvent e) {
downX = e.getX();
downY = e.getY();
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
this.panle.updateUI();
}
@Override
public void mouseDragged(MouseEvent e) {
int x = e.getX();
int y = e.getY();
int w = panle.getWidth();
int h = panle.getHeight();
double sx = ((double) (downX - x)) / ((double) w);
double sy = ((double) (y - downY)) / ((double) h);
this.panle.moveAxis(sx, sy);
downX = e.getX();
downY = e.getY();
}
@Override
public void mouseMoved(MouseEvent e) {
this.panle.setCursorPoint(e.getX(), e.getY());
}
}