com.jgoodies.uifextras.util
Class PopupAdapter

java.lang.Object
  extended by java.awt.event.MouseAdapter
      extended by com.jgoodies.uifextras.util.PopupAdapter
All Implemented Interfaces:
MouseListener, MouseMotionListener, MouseWheelListener, EventListener

public abstract class PopupAdapter
extends MouseAdapter

A MouseListener that minimizes the effort required to add a JPopupMenu to a JComponent. Handles mouse pressed and mouse released events and shows the popup menu if the event indicates a popupTrigger. The JPopupMenu is either rebuilt dynamically or lazily created and reused.

TODO: Consider using the Look&Feel dependent popup trigger check in JPopupMenu.isPopupTrigger(java.awt.event.MouseEvent). See also the commented code in #popupMenuIfTriggered.

Version:
$Revision: 1.4 $
Author:
Karsten Lentzsch

Constructor Summary
PopupAdapter()
          Creates a PopupAdapter that rebuilds its popup menu everytime.
PopupAdapter(boolean reusePopupMenu)
          Creates a PopupAdapter with the specified reuse policy.
 
Method Summary
protected abstract  JPopupMenu buildPopupMenu(MouseEvent e)
          Builds and returns this adapter's popup menu.
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mouseWheelMoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PopupAdapter

public PopupAdapter()
Creates a PopupAdapter that rebuilds its popup menu everytime.


PopupAdapter

public PopupAdapter(boolean reusePopupMenu)
Creates a PopupAdapter with the specified reuse policy. Either the popup menu is reused or it is rebuild everytime.

Parameters:
reusePopupMenu - true to lazily create and reuse the popup, false to rebuild the popup everytime
Method Detail

buildPopupMenu

protected abstract JPopupMenu buildPopupMenu(MouseEvent e)
Builds and returns this adapter's popup menu. If this adapter has been configured to rebuild the popup menu everytime, this method is invoked everytime before the menu shall be shown. Otherwise it'll be called once, the menu is stored and will be reused until the look&feel changes.

Parameters:
e - the MouseEvent that initiated the popup menu build process

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener
Overrides:
mousePressed in class MouseAdapter

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener
Overrides:
mouseReleased in class MouseAdapter


Copyright © 2000-2008 JGoodies Karsten Lentzsch. All Rights Reserved.