com.isti.util.gui
Class PopupHandler

java.lang.Object
  extended by com.isti.util.gui.PopupHandler
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.MouseListener, java.util.EventListener

public class PopupHandler
extends java.lang.Object
implements java.awt.event.ActionListener, java.awt.event.MouseListener

Create the popup handler.

The 'processMenuItem' method may be overridden or the 'setMenuItemActionListener' method may be used to process menu item actions.


Constructor Summary
PopupHandler(javax.swing.JPopupMenu popupMenu, java.awt.Component parent)
          Create the popup handler.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Action listener.
 void addButton(javax.swing.AbstractButton button)
          Add a button.
 javax.swing.JMenuItem addMenuItem(javax.swing.JMenuItem menuItem)
          Adds the menu item.
 javax.swing.JMenuItem addMenuItem(java.lang.String text)
          Adds a menu item with the specified text.
 void addMenuItems(java.lang.String[] text)
          Adds menu items with the specified text.
 void addSeparator()
          Appends a new separator at the end of the menu.
protected  int calculatePopupMenuY(java.awt.Component invoker)
          Calculate the popup menu Y location.
protected  javax.swing.JMenuItem createMenuItem(java.lang.String text)
          Create the menu item with the specified text.
protected  int getHeight(java.awt.Component component)
          Get the component height.
 java.awt.event.ActionListener getMenuItemActionListener()
          Get the menu item action listener.
protected  int getPopupMenuY(java.awt.Component invoker)
          Get the popup menu Y location.
 void mouseClicked(java.awt.event.MouseEvent e)
          Invoked when the mouse button has been clicked (pressed and released) on a component.
 void mouseEntered(java.awt.event.MouseEvent e)
          Invoked when the mouse enters a component.
 void mouseExited(java.awt.event.MouseEvent e)
          Invoked when the mouse exits a component.
 void mousePressed(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been pressed on a component.
 void mouseReleased(java.awt.event.MouseEvent e)
          Invoked when a mouse button has been released on a component.
protected  void processMenuItem(javax.swing.JMenuItem menuItem)
          Process the menu item.
 boolean removeButton(javax.swing.AbstractButton button)
          Remove a button.
 java.awt.event.ActionListener removeMenuItemActionListener()
          Remove the menu item action listener.
 void setMenuItemActionListener(java.awt.event.ActionListener l)
          Set the menu item action listener.
protected  void showPopup(java.awt.AWTEvent e)
          Show the popup menu if conditions are met.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PopupHandler

public PopupHandler(javax.swing.JPopupMenu popupMenu,
                    java.awt.Component parent)
Create the popup handler.

Parameters:
popupMenu - the popup menu.
parent - the component in which the popup menu menu is to be displayed.
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Action listener.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - the action event.

addButton

public void addButton(javax.swing.AbstractButton button)
Add a button.

Parameters:
button - the button.

addMenuItem

public javax.swing.JMenuItem addMenuItem(javax.swing.JMenuItem menuItem)
Adds the menu item.

Parameters:
menuItem - the menu item.
Returns:
the menu item.

addMenuItem

public javax.swing.JMenuItem addMenuItem(java.lang.String text)
Adds a menu item with the specified text.

Parameters:
text - the menu item text or null for separator.
Returns:
the menu item or null if separator.

addMenuItems

public void addMenuItems(java.lang.String[] text)
Adds menu items with the specified text.

Parameters:
text - the array of menu item text or null for separator.

addSeparator

public void addSeparator()
Appends a new separator at the end of the menu.


calculatePopupMenuY

protected int calculatePopupMenuY(java.awt.Component invoker)
Calculate the popup menu Y location.

Parameters:
invoker - the invoker.
Returns:
the popup menu Y location.

createMenuItem

protected javax.swing.JMenuItem createMenuItem(java.lang.String text)
Create the menu item with the specified text.

Parameters:
text - the text.
Returns:
the menu item.

getHeight

protected int getHeight(java.awt.Component component)
Get the component height.

Parameters:
component - the component.
Returns:
the component height.

getMenuItemActionListener

public java.awt.event.ActionListener getMenuItemActionListener()
Get the menu item action listener.

Returns:
the menu item action listener or null if none.

getPopupMenuY

protected int getPopupMenuY(java.awt.Component invoker)
Get the popup menu Y location.

Parameters:
invoker - the invoker.
Returns:
the popup menu Y location.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Invoked when the mouse button has been clicked (pressed and released) on a component.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - the mouse event.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Invoked when the mouse enters a component.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - the mouse event.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Invoked when the mouse exits a component.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - the mouse event.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Invoked when a mouse button has been pressed on a component.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - the mouse event.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Invoked when a mouse button has been released on a component.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - the mouse event.

processMenuItem

protected void processMenuItem(javax.swing.JMenuItem menuItem)
Process the menu item.

Parameters:
menuItem - the menu item.

removeButton

public boolean removeButton(javax.swing.AbstractButton button)
Remove a button.

Parameters:
button - the button.
Returns:
true if the button was removed, false otherwise.

removeMenuItemActionListener

public java.awt.event.ActionListener removeMenuItemActionListener()
Remove the menu item action listener.

Returns:
the menu item action listener that was removed or null if none.

setMenuItemActionListener

public void setMenuItemActionListener(java.awt.event.ActionListener l)
Set the menu item action listener.

Parameters:
l - the menu item action listener.

showPopup

protected void showPopup(java.awt.AWTEvent e)
Show the popup menu if conditions are met.

Parameters:
e - the event or null if none.