[kepler-dev] Kepler actionListeners/Actions
Matthew Brooke
brooke at nceas.ucsb.edu
Tue Feb 28 10:35:12 PST 2006
Here's how to write Action classes for Kepler (This allows your code to
be reusable and easily incorporated into the new menu framework when the
time comes):
1) Write a public Action 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 AddToLibAction
2) add the action to your button (or whatever is going to trigger it) by
calling the "setAction(myAction) method in your code:
Action addToLibAction = new AddToLibAction Action(basicGraphFrame);
//see example code below for AddToLibAction
JButton addButton = new JButton();
addButton.setAction(addToLibAction);
That's it! Note that the button/component will take its Label text from
the action (see below)
================================================
// Example code for AddToLibAction
public class AddToLibAction extends FigureAction {
// Display Text pulled from resourcebundle:
private static String DISPLAY_NAME
= StaticResources.getDisplayString("actions.addtolib.displayName", "");
private static String TOOLTIP
= StaticResources.getDisplayString("actions.addtolib.tooltip", "");
/**
* Constructor
*
* @param parent the "frame" (derived from ptolemy.gui.Top)
* where the menu is being added.
*/
public AddToLibAction (TableauFrame parent) {
super("");
this.parent = parent;
this.putValue(Action.NAME, DISPLAY_NAME);
this.putValue("tooltip", TOOLTIP);
}
/**
* 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);
//...etc
}
--
---------------------------------------------
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
---------------------------------------------
More information about the Kepler-dev
mailing list