ptolemy.vergil.toolbox
Class PtolemyMenuFactory

java.lang.Object
  extended byptolemy.vergil.toolbox.PtolemyMenuFactory
All Implemented Interfaces:
MenuFactory
Direct Known Subclasses:
BasicGraphController.SchematicContextMenuFactory

public class PtolemyMenuFactory
extends java.lang.Object
implements MenuFactory

A menu factory that contains a list of item factories. When asked to create a context menu, This class first takes the figure and finds the ptolemy object associated with it. Then it passes the ptolemy object to each menu item factory that it contains to add the menu items. Lastly, it returns the resulting menu. This seems simple, except for the fact that for different types of figures, and different visual notations, the mapping between figure and the interesting ptolemy object is different. Hence, Node and Edge Controllers will often need subclasses of this factory to get the correct ptolemy object.

Since:
Ptolemy II 1.0
Version:
$Id: PtolemyMenuFactory.java,v 1.19 2004/04/13 05:12:44 cxh Exp $
Author:
Steve Neuendorffer
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (eal)

Constructor Summary
PtolemyMenuFactory(GraphController controller)
          Create a new menu factory that contains no menu item factories.
 
Method Summary
protected  NamedObj _getObjectFromFigure(Figure figure)
          Return the Ptolemy object that the given figure represents.
 void addMenuItemFactory(MenuItemFactory factory)
          Add a menu item factory to this creator.
 JContextMenu create(Figure figure)
          Create an instance of the menu associated with this factory.
 GraphController getController()
          Return the graph controller that created this menu factory.
 java.util.List menuItemFactoryList()
          Return the list of menu item factories.
 void removeMenuItemFactory(MenuItemFactory factory)
          Remove the given menu item factory from the factory list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PtolemyMenuFactory

public PtolemyMenuFactory(GraphController controller)
Create a new menu factory that contains no menu item factories.

Method Detail

addMenuItemFactory

public void addMenuItemFactory(MenuItemFactory factory)
Add a menu item factory to this creator.

Parameters:
factory - The menu item factory to add.

create

public JContextMenu create(Figure figure)
Create an instance of the menu associated with this factory.

Specified by:
create in interface MenuFactory
Parameters:
figure - The figure for which to create a context menu.

getController

public GraphController getController()
Return the graph controller that created this menu factory.


menuItemFactoryList

public java.util.List menuItemFactoryList()
Return the list of menu item factories.

Returns:
An unmodifiable list.

removeMenuItemFactory

public void removeMenuItemFactory(MenuItemFactory factory)
Remove the given menu item factory from the factory list.


_getObjectFromFigure

protected NamedObj _getObjectFromFigure(Figure figure)
Return the Ptolemy object that the given figure represents. In this base class, we assume that the figure is attached to a a diva.graph.model object, and that object is attached to the correct ptolemy object. In many cases, this is not the case, and you will have to override this function.