[kepler-dev] Adding new menu context-menu items and graph frame selections

Matthew Brooke brooke at nceas.ucsb.edu
Wed Apr 19 09:42:00 PDT 2006

Hey Shawn -

Thanks for the info about graph selections - very useful.  As for the
context menus, it's a pretty straightforward 2-step process (I'm cc-ing 
this to kepler-dev, too, so we have a record of it for everyone):

1) Write a class that extends ptolemy.vergil.toolbox.FigureAction, and
add your actual action code to the method:

public void actionPerformed(ActionEvent e)

(this is an abstract method, so it must be implemented in your class)

- See example code below for ShawnsAction

2) Edit the file:


and add a mapping (note that the order in the file is the same order as 
on the menu).

Specifically, look in the documentation at the beginning of that file, 

A sample entry looks like:

ACTOR->Shawns\ Menu\ Item=org.kepler.whatever.ShawnsAction

where ACTOR is the right-clickable visual component that will show this 
menu item. Also note that spaces need to be escaped. Again, be sure to 
read the documentation at the beginning of the config file

Don't forget to do a clean build for the changes to show up!

Finally, note that new context menu entries should always be run by 
Laura to ensure they fit with the current design

Let me know if any of this doesn't make sense or doesn't work


// code snippet for ShawnsAction class:

public class ShawnsAction extends FigureAction {

   /** REQUIRED *****
    * Constructor
    * @param parent the "frame" (derived from ptolemy.gui.Top)
    * where the menu is being added.
    * NOTE this parameter is automatically passed to your
    * constructor by the menu system at runtime
   public ShawnsAction (TableauFrame parent) {
     this.parent = parent;

   /** REQUIRED *****
    * Invoked when an action occurs.
    *@param  e  ActionEvent
   public void actionPerformed(ActionEvent e) {

     //YOUR CODE GOES HERE - like:
     //dialog = new MyDialog(parent);
     //dialog .setVisible(true);


Matthew Brooke, Ph.D.
Marine Sciences Research Building, Room #3407
University of California
Santa Barbara, CA  93106-6150
ph: (805) 893-7108   fx: 805-893-8062
brooke at nceas.ucsb.edu

Shawn Bowers wrote:
> Hi Matthew,
> I was wondering how I can add new context menu items in Kepler now ...
> Is there documentation/examples of how this currently works? Or, can you 
> send insructions?
> Also, here is the scoop on figuring out what is selected in a graph 
> frame.  It is pretty convoluted (but, we should expect as much in ptolemy).
> Basically you do the following. Given an ActorGraphFrame _owner object:
> // get the tableau:
> ActorGraphTableau tmpTableau = (ActorGraphTableau)_owner.getTableau();
> // get the controller:
> BasicGraphFrame tmpParent = (BasicGraphFrame)tmpTableau.getFrame();
> // get the tableau's graph:
> JGraph tmpJGraph = tmpParent.getJGraph();
> // get the graph's pane:
> GraphPane tmpGraphPane = tmpJGraph.getGraphPane();
> // get the graph controller for the pane:
> _controller = (GraphController)tmpGraphPane.getGraphController();
> // get the selection model:
> _selectionModel = _controller.getSelectionModel();
> Given the selection model (diva.canvas.interactor.SelectionModel) there 
> are various methods that can be used to get the selections. For example, 
> getFirstSelection() or getSelection(), etc.
> The above code is used in org.kepler.sms.gui.WorkflowTypeCheckerDialog, 
> which I took from ptolemy.actor.gui.UnitSolverDialog.
> Thanks,
> -shawn

More information about the Kepler-dev mailing list