JIDE 3.5.15

com.jidesoft.tree
Class TreePopupMenuInstaller

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

public class TreePopupMenuInstaller
extends MouseAdapter

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


 TreePopupMenuInstaller installer = new TreePopupMenuInstaller(tree);
 
Or if you want to uninstall it, call

 TreePopupMenuInstaller.getTreePopupMenuInstaller(tree).uninstallListeners();
 
However TreePopupMenuInstaller has no menu items. You need create your own TreePopupMenuCustomizer to do it.


Field Summary
static String CLIENT_PROPERTY_POPUP_MENU_INSTALLER
          Client property used by JTree to provide its own TreePopupMenuCustomizer.
 
Constructor Summary
TreePopupMenuInstaller(JTree tree)
          Creates a TreePopupMenuInstaller.
 
Method Summary
static void addSeparatorIfNecessary(JPopupMenu popup)
          Adds a separator to the popup menu if there are menu items on it already.
 void addTreePopupMenuCustomizer(TreePopupMenuCustomizer customizer)
          Add a tree popup menu customizer.
protected  JPopupMenu createPopupMenu()
          Create the popup menu.
protected  void customizeMenuItems(JTree tree, JPopupMenu popup, TreePath[] path)
          Customizes the menu items for the popup menu.
protected  TreePath[] getTargetTreePath(JTree tree, Point p)
          Finds the target tree path the menu will install on.
 TreePopupMenuCustomizer[] getTreePopupMenuCustomizers()
          Get the installed popup menu customizer.
static TreePopupMenuInstaller getTreePopupMenuInstaller(JTree tree)
          Gets the TreePopupMenuInstaller installed on the JTree.
 void installListeners()
          Installs the listeners needed in order to show the popup menu for the JTree.
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void removeTreePopupMenuCustomizer(TreePopupMenuCustomizer customizer)
          Remove a tree popup menu customizer.
 void uninstallListeners()
          Uninstalls the listeners needed in order to show the popup menu for the JTree.
 
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 JTree to provide its own TreePopupMenuCustomizer.

See Also:
Constant Field Values
Constructor Detail

TreePopupMenuInstaller

public TreePopupMenuInstaller(JTree tree)
Creates a TreePopupMenuInstaller.

Parameters:
tree - the JTree.
Method Detail

addTreePopupMenuCustomizer

public void addTreePopupMenuCustomizer(TreePopupMenuCustomizer customizer)
Add a tree popup menu customizer.

Parameters:
customizer - the customizer

removeTreePopupMenuCustomizer

public void removeTreePopupMenuCustomizer(TreePopupMenuCustomizer customizer)
Remove a tree popup menu customizer.

Parameters:
customizer - the customizer

getTreePopupMenuCustomizers

public TreePopupMenuCustomizer[] getTreePopupMenuCustomizers()
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(JTree tree,
                                  JPopupMenu popup,
                                  TreePath[] path)
Customizes the menu items for the popup menu.

Parameters:
tree - the JTree.
popup - the popup menu.
path - the target tree paths.

installListeners

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


uninstallListeners

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


getTreePopupMenuInstaller

public static TreePopupMenuInstaller getTreePopupMenuInstaller(JTree tree)
Gets the TreePopupMenuInstaller installed on the JTree. Null is no TreePopupMenuInstaller was installed.

Parameters:
tree - the JTree
Returns:
the TreePopupMenuInstaller installed. Null is no TreePopupMenuInstaller was installed.

getTargetTreePath

protected TreePath[] getTargetTreePath(JTree tree,
                                       Point p)
Finds the target tree path the menu will install on.

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

Parameters:
tree - the JTree
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