FreeHEP API
Version current

org.freehep.swing.popup
Class GlobalMouseListener

java.lang.Object
  extended byorg.freehep.swing.popup.GlobalMouseListener

public class GlobalMouseListener
extends Object

This class is designed to work around a deficiency in Swing's mouse handling. It enables a listener to be applied to a component so that all mouse events in that component, or any of its subcomponents will be reported. This is useful for example in creating Popup menus for complex graphical objects (such as plots).

There is no easy way to implement this functionality in Swing, so this class works by recursively adding mouse listeners to all components in the heirarchy. It also adds a ComponentListener so that it can add and remove listeners from items as they are added to the tree.

Warning: This class can have unexpected side effects in some rare cases. Normally swing will delegate mouse events to a component's parent if that component does not listen for mouse events itself. Since this class adds mouse listeners to all components, it can have the side effect of preventing this mouse event delegation. (In Java 1.4 it is possible to tell if a mouse listener already exists on a component, so maybe it would be possible to work around this limitation. Not clear how you would know if a mouse listener was subsequently added).

Version:
$Id: GlobalMouseListener.java,v 1.1 2003/08/15 02:20:19 tonyj Exp $
Author:
tonyj
Source Code:
GlobalMouseListener.java

Constructor Summary
GlobalMouseListener(Component c)
          Create a new GlobalMouseListener associated to a component
 
Method Summary
 void addMouseListener(MouseListener l)
          Add a mouse listener.
 void removeMouseListener(MouseListener l)
          Remove a mouse listener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GlobalMouseListener

public GlobalMouseListener(Component c)
Create a new GlobalMouseListener associated to a component

Parameters:
c - The component on which to listen for mouse events
Method Detail

addMouseListener

public void addMouseListener(MouseListener l)
Add a mouse listener.

Parameters:
l - The listener to add

removeMouseListener

public void removeMouseListener(MouseListener l)
Remove a mouse listener

Parameters:
l - The listener to remove

FreeHEP API
Version current

Copyright © 2000-2004 FreeHEP, All Rights Reserved.