org.graffiti.plugin.view.interactive
Class PopupMenuItem

java.lang.Object
  extended by org.graffiti.plugin.view.interactive.PopupMenuItem

public class PopupMenuItem
extends Object

Represents an item in a popup menu that is shown by PopupMenuCompatibleProvider. The actual AWT/Swing objects for displaying the menu are automatically created by the tool system and transparent to the views and tools. PopupMenuItem employs the composite pattern and represents single items as well as complete submenus. If this has no children, it will be automatically treated as a leaf. Creators of PopupMenuItem may either pass an ActionListener that is directly called once the item is selected by the user, or else a PopupMenuSelectionGesture that allows for dynamic processing by the tool system will be created.

Version:
$Revision$ $Date$
Author:
Andreas Gleißner
See Also:
PopupMenuCompatibleProvider, PopupMenuSelectionGesture

Field Summary
static String SEPARATOR_ID
          PopupMenuItems with that id represent menu separators.
 
Constructor Summary
PopupMenuItem()
          Constructs a PopupMenuItem.
PopupMenuItem(String label)
          Constructs a PopupMenuItem and initializes its label with the specified text.
PopupMenuItem(String label, ActionListener actionListener)
          Constructs a PopupMenuItem and initializes its label with the specified text.
 
Method Summary
 void add(int index, PopupMenuItem child)
          Inserts the specified menu item into this submenu at the specified position.
 void addLast(PopupMenuItem child)
          Adds the specified menu item to the end of this submenu.
static PopupMenuItem createSeparator()
          Constructs a PopupMenuItem representing a menu separator.
 ActionListener getActionListener()
          Returns the ActionListener attached to this menu item.
 Collection<PopupMenuItem> getChildren()
          Returns the children of this submenu.
 String getId()
          Returns the id of this menu item.
 String getLabel()
          Returns the text of this menu item.
 SlotMap getSlots()
          Returns the slots attached to this menu item.
 boolean hasChildren()
          Returns if this has children.
 boolean isSeparator()
          Returns if this represents a menu separator.
 void setId(String id)
          Sets the id of this menu item.
 void setLabel(String label)
          Sets the text of this menu item.
 void setSlots(SlotMap slots)
          Sets the slots passed through this item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR_ID

public static final String SEPARATOR_ID
PopupMenuItems with that id represent menu separators.

See Also:
setId(String), Constant Field Values
Constructor Detail

PopupMenuItem

public PopupMenuItem()
Constructs a PopupMenuItem. As no ActionListener is specified, selecting this menu item will lead to the creation of a PopupMenuSelectionGesture.


PopupMenuItem

public PopupMenuItem(String label)
Constructs a PopupMenuItem and initializes its label with the specified text. As no ActionListener is specified, selecting this menu item will lead to the creation of a PopupMenuSelectionGesture.

Parameters:
label - the text of this menu item.

PopupMenuItem

public PopupMenuItem(String label,
                     ActionListener actionListener)
Constructs a PopupMenuItem and initializes its label with the specified text. When the user selects this item, the specified ActionListener will be activated.

Parameters:
label - the text of this menu item.
actionListener - the ActionListener to be activated when the user selects this menu item.
Method Detail

createSeparator

public static PopupMenuItem createSeparator()
Constructs a PopupMenuItem representing a menu separator.

Returns:
a new PopupMenuItem representing a menu separator.

setId

public void setId(String id)
Sets the id of this menu item. If id equals "SEPARATOR_ID", this represents a menu separator. Otherwise, its id will be used by the PopupMenuSelectionGesture for identification purposes.

See Also:
getId()

setLabel

public void setLabel(String label)
Sets the text of this menu item.

Parameters:
label - the text of this menu item.

getId

public String getId()
Returns the id of this menu item. If id equals "SEPARATOR_ID", this represents a menu separator. Otherwise, its id will be used by the PopupMenuSelectionGesture for identification purposes.

Returns:
the id of this menu item.

isSeparator

public boolean isSeparator()
Returns if this represents a menu separator.

Returns:
true if this represents a menu separator.

getLabel

public String getLabel()
Returns the text of this menu item.

Returns:
the text of this menu item.

getSlots

public SlotMap getSlots()
Returns the slots attached to this menu item. They will be passed to the tools system via a new PopupMenuSelectionGesture when the user selects this item. To understand their utility, suppose there is a view where new nodes are created by right-clicking somewhere in the view and then selecting "Create Node" in a popup menu. The output slot of the MouseTrigger carrying the mouse position cannot directly be connected to the input slot of a CreateNode action, as the mouse click should not immediately lead to the node creation but rather to displaying the menu, but on the other hand, the mouse position should determine the position of the node that is potentially created afterwards. To address this problem, connect the position slot of the mouse trigger with the input slot of this PopupMenuItem and the output slot of a trigger matching the respective PopupMenuSelectionGesture with the input slot of the CreateNode action.

Returns:
the slots connected to this menu items.

setSlots

public void setSlots(SlotMap slots)
Sets the slots passed through this item.

Parameters:
slots - the slots passed through this item.
See Also:
getSlots()

hasChildren

public boolean hasChildren()
Returns if this has children.

Returns:
true if this has children, i.e. represents a submenu.

addLast

public void addLast(PopupMenuItem child)
Adds the specified menu item to the end of this submenu.

Parameters:
child - the item to be added to this submenu.

add

public void add(int index,
                PopupMenuItem child)
Inserts the specified menu item into this submenu at the specified position.

Parameters:
index - the position of the specified item in this submenu. The index is not interpreted as an absolute position but rather used as a sorting key.
child - the item to be added to this submenu.

getChildren

public Collection<PopupMenuItem> getChildren()
Returns the children of this submenu.

Returns:
the children of this submenu. The returned collection must not be modified outside this class.

getActionListener

public ActionListener getActionListener()
Returns the ActionListener attached to this menu item.

Returns:
the ActionListener attached to this menu item. If there is no such ActionListener, null is returned and selecting this menu item leads to the creation of a PopupMenuSelectionGesture.


Generated at 2012-05-30 11:00:36 PM CEST