/Users/lyon/j4p/src/gui/mouse/MouseController.java

1    package gui.mouse; 
2     
3    import gui.ClosableJFrame; 
4     
5    import java.awt.event.MouseMotionListener; 
6     
7    public abstract class MouseController 
8            implements java.awt.event.MouseListener, MouseMotionListener { 
9        private java.awt.Point pressPoint; 
10    
11       public void mouseMoved(java.awt.event.MouseEvent e) { 
12       } 
13    
14       public void mouseReleased(java.awt.event.MouseEvent e) { 
15           released(e.getPoint()); 
16       } 
17    
18       public void mouseEntered(java.awt.event.MouseEvent e) { 
19       } 
20    
21       public void mouseExited(java.awt.event.MouseEvent e) { 
22       } 
23    
24       public void mouseClicked(java.awt.event.MouseEvent e) { 
25           if (e.getClickCount() == 2) { 
26               doubleClicked(e.getPoint()); 
27               return; 
28           } 
29           if (e.isShiftDown() && e.getClickCount() == 1) { 
30               shiftClicked(e.getPoint()); 
31               return; 
32           } 
33           clicked(e.getPoint()); 
34       } 
35    
36       public void mousePressed(java.awt.event.MouseEvent e) { 
37           pressPoint = e.getPoint(); 
38           pressed(pressPoint); 
39       } 
40    
41       public void mouseDragged(java.awt.event.MouseEvent e) { 
42           if (e.isShiftDown()) 
43               dragShift(pressPoint, e.getPoint()); 
44           else 
45               dragged(pressPoint, e.getPoint()); 
46       } 
47    
48       public abstract void released(java.awt.Point p); 
49    
50       public abstract void dragged( 
51               java.awt.Point p1, java.awt.Point p2); 
52    
53       public abstract void dragShift( 
54               java.awt.Point p1, java.awt.Point p2); 
55    
56       public abstract void pressed(java.awt.Point p); 
57    
58       public abstract void doubleClicked(java.awt.Point p); 
59    
60       public abstract void clicked(java.awt.Point p); 
61    
62       public abstract void shiftClicked(java.awt.Point p); 
63    
64       public static void main(String args[]) { 
65           ClosableJFrame cf = new ClosableJFrame(); 
66           cf.addMouseController(new MouseController() { 
67               public void pressed(java.awt.Point p) { 
68                   System.out.println("pressed:x,y=" + p.x + "," + p.y); 
69               } 
70    
71               public void released(java.awt.Point p) { 
72                   System.out.println("rel:x,y=" + p.x + "," + p.y); 
73               } 
74    
75               public void dragShift( 
76                       java.awt.Point p1, java.awt.Point p2) { 
77                   System.out.println( 
78                           "draShift:x1,y1,x2,y2=" + p1 + ": " + p2); 
79               } 
80    
81               public void doubleClicked(java.awt.Point p) { 
82                   System.out.println("d 2 clicked:x,y=" + p.x + "," + p.y); 
83               } 
84    
85               public void clicked(java.awt.Point p) { 
86                   System.out.println("clicked:x,y=" + p.x + "," + p.y); 
87               } 
88    
89               public void shiftClicked(java.awt.Point p) { 
90                   System.out.println("Sh clicked:x,y=" + p.x + "," + p.y); 
91               } 
92    
93               public void dragged( 
94                       java.awt.Point p1, java.awt.Point p2) { 
95                   System.out.println( 
96                           "dra:x1,y1,x2,y2=" + p1 + ": " + p2); 
97               } 
98    
99           }); 
100          cf.setSize(200, 200); 
101          cf.setVisible(true); 
102      } 
103   
104  } 
105