Mercurial > hg > jslab
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/core_/util/MouseRetarget.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,67 @@ +/* + * MouseRetarget.java + * + * Copyright (c) 2000, Samer Abdallah, King's College London. + * All rights reserved. + * + * This software is provided AS iS and WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + */ + +package samer.core.util; +import java.awt.*; +import java.awt.event.*; + + +/** + This is a mouse event handler that makes + a component effectively invisible to + mouse clicks by routing a events through + to the parent container. + */ + +public class MouseRetarget extends MouseAdapter +{ + private void retarget(MouseEvent e) + { + if (!e.isConsumed()) { // no point otherwise + Component c=e.getComponent(); + Component parent=c.getParent(); + + if (parent!=null) { + Point origin=c.getLocation(); + + // Must make new event look as if it + // was generated by parent + + MouseEvent ee = new MouseEvent( + parent, + e.getID(), + e.getWhen(), + e.getModifiers(), + e.getX() + origin.x, + e.getY() + origin.y, + e.getClickCount(), + e.isPopupTrigger()); + + parent.dispatchEvent(ee); + } + } + } + + public void mouseClicked(MouseEvent e) { retarget(e); } + public void mousePressed(MouseEvent e) { retarget(e); } + public void mouseReleased(MouseEvent e) { retarget(e); } + + // This one static object can handle all the mouse + // event redirection for everyone + + public static final MouseListener listener=new MouseRetarget(); + public static void mouseInvisibilityFor(Component c) { + c.addMouseListener(listener); + } +} + + +