JIDE 3.5.15

com.jidesoft.list
Class ListPopupMenuInstaller

java.lang.Object
  extended by java.awt.event.MouseAdapter
      extended by com.jidesoft.list.ListPopupMenuInstaller
All Implemented Interfaces:
MouseListener, MouseMotionListener, MouseWheelListener, EventListener

public class ListPopupMenuInstaller
extends MouseAdapter

ListPopupMenuInstaller allows you to add a popup menu to a JList and customize it. To use it, you just need to call


 ListPopupMenuInstaller installer = new ListPopupMenuInstaller(list);
 
Or if you want to uninstall it, call

 ListPopupMenuInstaller.getListPopupMenuCustomizers(list).uninstallListeners();
 
However ListPopupMenuInstaller has no menu items. You need create your own ListPopupMenuCustomizer to do it.


Field Summary
static String CLIENT_PROPERTY_POPUP_MENU_INSTALLER
          Client property used by JList to provide its own ListPopupMenuCustomizer.
 
Constructor Summary
ListPopupMenuInstaller(JList list)
          Creates a ListPopupMenuInstaller.
 
Method Summary
 void addListPopupMenuCustomizer(ListPopupMenuCustomizer customizer)
          Add a list popup menu customizer.
static void addSeparatorIfNecessary(JPopupMenu popup)
          Adds a separator to the popup menu if there are menu items on it already.
protected  JPopupMenu createPopupMenu()
          Create the popup menu.
protected  void customizeMenuItems(JList list, JPopupMenu popup, int[] indices)
          Customizes the menu items for the popup menu.
 ListPopupMenuCustomizer[] getListPopupMenuCustomizers()
          Get the installed popup menu customizer.
static ListPopupMenuInstaller getListPopupMenuInstaller(JList list)
          Gets the ListPopupMenuInstaller installed on the JList.
protected  int[] getTargetListItems(JList list, Point p)
          Finds the target list items the menu will install on.
 void installListeners()
          Installs the listeners needed in order to show the popup menu for the JList.
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void removeListPopupMenuCustomizer(ListPopupMenuCustomizer customizer)
          Remove a list popup menu customizer.
 void uninstallListeners()
          Uninstalls the listeners needed in order to show the popup menu for the JList.
 
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
 

Field Detail

CLIENT_PROPERTY_POPUP_MENU_INSTALLER

public static final String CLIENT_PROPERTY_POPUP_MENU_INSTALLER
Client property used by JList to provide its own ListPopupMenuCustomizer.

See Also:
Constant Field Values
Constructor Detail

ListPopupMenuInstaller

public ListPopupMenuInstaller(JList list)
Creates a ListPopupMenuInstaller.

Parameters:
list - the JList.
Method Detail

addListPopupMenuCustomizer

public void addListPopupMenuCustomizer(ListPopupMenuCustomizer customizer)
Add a list popup menu customizer.

Parameters:
customizer - the customizer

removeListPopupMenuCustomizer

public void removeListPopupMenuCustomizer(ListPopupMenuCustomizer customizer)
Remove a list popup menu customizer.

Parameters:
customizer - the customizer

getListPopupMenuCustomizers

public ListPopupMenuCustomizer[] getListPopupMenuCustomizers()
Get the installed popup menu customizer.

Returns:
all popup menu customizer in array.

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

createPopupMenu

protected JPopupMenu createPopupMenu()
Create the popup menu.

The default implementation is to return a new created JidePopupMenu instance.

Returns:
the popup menu.

customizeMenuItems

protected void customizeMenuItems(JList list,
                                  JPopupMenu popup,
                                  int[] indices)
Customizes the menu items for the popup menu.

Parameters:
list - the JList.
popup - the popup menu.
indices - the target list items.

installListeners

public void installListeners()
Installs the listeners needed in order to show the popup menu for the JList.


uninstallListeners

public void uninstallListeners()
Uninstalls the listeners needed in order to show the popup menu for the JList.


getListPopupMenuInstaller

public static ListPopupMenuInstaller getListPopupMenuInstaller(JList list)
Gets the ListPopupMenuInstaller installed on the JList. Null is no ListPopupMenuInstaller was installed.

Parameters:
list - the JList
Returns:
the ListPopupMenuInstaller installed. Null is no ListPopupMenuInstaller was installed.

getTargetListItems

protected int[] getTargetListItems(JList list,
                                   Point p)
Finds the target list items the menu will install on.

The default implementation is the current selected indices. You could override this method to have your own definition.

Parameters:
list - the JList
p - the point
Returns:
the column or null

addSeparatorIfNecessary

public static void addSeparatorIfNecessary(JPopupMenu popup)
Adds a separator to the popup menu if there are menu items on it already.

Parameters:
popup - the popup menu.

JIDE 3.5.15