Mercurial > hg > jslab
comparison src/samer/core_/util/MouseRetarget.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bf79fb79ee13 |
---|---|
1 /* | |
2 * MouseRetarget.java | |
3 * | |
4 * Copyright (c) 2000, Samer Abdallah, King's College London. | |
5 * All rights reserved. | |
6 * | |
7 * This software is provided AS iS and WITHOUT ANY WARRANTY; | |
8 * without even the implied warranty of MERCHANTABILITY or | |
9 * FITNESS FOR A PARTICULAR PURPOSE. | |
10 */ | |
11 | |
12 package samer.core.util; | |
13 import java.awt.*; | |
14 import java.awt.event.*; | |
15 | |
16 | |
17 /** | |
18 This is a mouse event handler that makes | |
19 a component effectively invisible to | |
20 mouse clicks by routing a events through | |
21 to the parent container. | |
22 */ | |
23 | |
24 public class MouseRetarget extends MouseAdapter | |
25 { | |
26 private void retarget(MouseEvent e) | |
27 { | |
28 if (!e.isConsumed()) { // no point otherwise | |
29 Component c=e.getComponent(); | |
30 Component parent=c.getParent(); | |
31 | |
32 if (parent!=null) { | |
33 Point origin=c.getLocation(); | |
34 | |
35 // Must make new event look as if it | |
36 // was generated by parent | |
37 | |
38 MouseEvent ee = new MouseEvent( | |
39 parent, | |
40 e.getID(), | |
41 e.getWhen(), | |
42 e.getModifiers(), | |
43 e.getX() + origin.x, | |
44 e.getY() + origin.y, | |
45 e.getClickCount(), | |
46 e.isPopupTrigger()); | |
47 | |
48 parent.dispatchEvent(ee); | |
49 } | |
50 } | |
51 } | |
52 | |
53 public void mouseClicked(MouseEvent e) { retarget(e); } | |
54 public void mousePressed(MouseEvent e) { retarget(e); } | |
55 public void mouseReleased(MouseEvent e) { retarget(e); } | |
56 | |
57 // This one static object can handle all the mouse | |
58 // event redirection for everyone | |
59 | |
60 public static final MouseListener listener=new MouseRetarget(); | |
61 public static void mouseInvisibilityFor(Component c) { | |
62 c.addMouseListener(listener); | |
63 } | |
64 } | |
65 | |
66 | |
67 |