ptolemy.vergil.toolbox
Class FigureAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by ptolemy.vergil.toolbox.FigureAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action
Direct Known Subclasses:
ActorController.ListenToActorAction, ActorController.LookInsideAction, ActorController.OpenInstanceAction, ActorController.SaveInLibraryAction, ActorEditorGraphController.NewRelationAction, ActorInstanceController.ConvertToClassAction, BasicGraphController.OpenBaseClassAction, CaseGraphFrame.AddCaseAction, CaseGraphFrame.AddCaseAction, CaseGraphFrame.RemoveCaseAction, CaseGraphFrame.RemoveCaseAction, ClassDefinitionController.ConvertToInstanceAction, ClassDefinitionController.CreateInstanceAction, ClassDefinitionController.CreateSubclassAction, ConfigureAction, ConfigureUnitsAction, CustomizeDocumentationAction, DependencyHighlighter.HighlightDependents, EditIconAction, FmvAutomatonGraphController.NewFmvStateAction, FmvAutomatonGraphController.NewFmvStateAction, FSMGraphController.NewStateAction, FSMGraphController.NewStateAction, GetDocumentationAction, GTFrame.ConfigureIngredientsAction, HierarchicalModeController.AddRefinementAction, HierarchicalModeController.RemoveRefinementAction, HierarchicalStateController.AddRefinementAction, HierarchicalStateController.AddRefinementAction, HierarchicalStateController.RemoveRefinementAction, HierarchicalStateController.RemoveRefinementAction, ListenToAction, MatchResultViewer.CloseAction, MatchResultViewer.NextAction, MatchResultViewer.NextFileAction, MatchResultViewer.PreviousAction, MatchResultViewer.PreviousFileAction, MatchResultViewer.TransformAction, MatchResultViewer.TransformUntilFixpointAction, ModalTransitionController.AddRefinementAction, ModalTransitionController.AddRefinementAction, ModalTransitionController.RemoveRefinementAction, ModalTransitionController.RemoveRefinementAction, MoveAction, PortDialogAction, PteraGraphController.NewEventAction, RemoveCustomDocumentationAction, RemoveIconAction, RenameDialogAction, RotateOrFlipPorts, RunnableGraphController.ButtonFigureAction, StateController.EditIconAction, StateController.EditIconAction, StateController.LookInsideAction, StateController.LookInsideAction, StateController.RemoveIconAction, StateController.RemoveIconAction, TransformationAttributeController.LookInsideAction, TransformationEditor.MatchAction, TransformationEditor.MatchingAttributeAction, TransitionController.LookInsideAction, TransitionController.LookInsideAction, WithIconGraphController.NewPortAction

public class FigureAction
extends javax.swing.AbstractAction

An action that is attached to a figure on a named object. Such an action is fired in one of several ways. The first way is through an ActionInteractor that is attached to the figure. The second way is through a context menu that is created on the figure. A third way is through a hotkey. Unfortunately, the source of the event is different in these cases. This class makes it easier to write an action that is triggered by any mechanism. Such an action would be derived from this class, and would invoke super.actionPerformed() first in its own actionPerformed() method.

Since:
Ptolemy II 1.0
Version:
$Id: FigureAction.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Steve Neuendorffer and Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (eal)

Nested Class Summary
static class FigureAction.SourceType
          The source of the action.
 
Field Summary
private  Figure _figure
           
private  java.awt.Frame _frame
           
private  FigureAction.SourceType _sourceType
           
private  NamedObj _target
           
private  int _x
           
private  int _y
           
static FigureAction.SourceType CANVAS_TYPE
          When the action was fired from a canvas interactor.
static FigureAction.SourceType CONTEXTMENU_TYPE
          When the action was fired from a context menu.
static FigureAction.SourceType HOTKEY_TYPE
          When the action was fired from a hotkey.
static FigureAction.SourceType MENUBAR_TYPE
          When the action was fired from a menubar.
static int PASTE_OFFSET
          Offset used when pasting objects.
static FigureAction.SourceType TOOLBAR_TYPE
          When the action was fired from a toolbar icon.
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
FigureAction(java.lang.String name)
          Construct an action that is attached to a figure on a named object.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Determine the target Ptolemy II object, the originating frame, and the X, Y position of the action, if possible.
 Figure getFigure()
          Return the figure of this action.
 java.awt.Frame getFrame()
          Return the frame responsible for triggering this action, or null if none could be found.
 FigureAction.SourceType getSourceType()
          Return the source type of this action, which is one of CANVAS_TYPE, CONTEXTMENU_TYPE, TOOLBAR_TYPE, MENUBAR_TYPE, HOTKEY_TYPE, or null if none was recognized.
 NamedObj getTarget()
          Return the target Ptolemy II object for this action, or null if none could be found.
 int getX()
          Return the horizontal position of the action, or 0 if this is not relevant (e.g., the action was triggered by a toolbar button).
 int getY()
          Return the vertical position of the action, or 0 if this is not relevant (e.g., the action was triggered by a toolbar button).
static double[] offsetFigure(double x, double y, double xOffset, double yOffset, java.lang.Class<?> figureClass, FigureLayer foregroundLayer, java.awt.geom.Rectangle2D visibleRectangle)
          Determine a new location for a figure if another figure is already at that location.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CANVAS_TYPE

public static final FigureAction.SourceType CANVAS_TYPE
When the action was fired from a canvas interactor.


CONTEXTMENU_TYPE

public static final FigureAction.SourceType CONTEXTMENU_TYPE
When the action was fired from a context menu.


HOTKEY_TYPE

public static final FigureAction.SourceType HOTKEY_TYPE
When the action was fired from a hotkey.


MENUBAR_TYPE

public static final FigureAction.SourceType MENUBAR_TYPE
When the action was fired from a menubar.


PASTE_OFFSET

public static final int PASTE_OFFSET
Offset used when pasting objects. See also OffsetMoMLChangeRequest.

See Also:
Constant Field Values

TOOLBAR_TYPE

public static final FigureAction.SourceType TOOLBAR_TYPE
When the action was fired from a toolbar icon.


_figure

private Figure _figure

_frame

private java.awt.Frame _frame

_sourceType

private FigureAction.SourceType _sourceType

_target

private NamedObj _target

_x

private int _x

_y

private int _y
Constructor Detail

FigureAction

public FigureAction(java.lang.String name)
Construct an action that is attached to a figure on a named object.

Parameters:
name - The name of the object.
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Determine the target Ptolemy II object, the originating frame, and the X, Y position of the action, if possible. After this is invoked, the other public methods can be used to access this data.

Parameters:
e - The event.

getFigure

public Figure getFigure()
Return the figure of this action.

Returns:
The figure of this action.

getFrame

public java.awt.Frame getFrame()
Return the frame responsible for triggering this action, or null if none could be found. This can be used to set the owner of any dialogs triggered by this event. This must be called after actionPerformed(), and is typically called inside the actionPerformed() method of a subclass.

Returns:
The frame that triggered this action.

getSourceType

public FigureAction.SourceType getSourceType()
Return the source type of this action, which is one of CANVAS_TYPE, CONTEXTMENU_TYPE, TOOLBAR_TYPE, MENUBAR_TYPE, HOTKEY_TYPE, or null if none was recognized.

Returns:
The source type of this action.

getTarget

public NamedObj getTarget()
Return the target Ptolemy II object for this action, or null if none could be found. This is typically the object whose icon is the figure on which this action was invoked. This must be called after actionPerformed(), and is typically called inside the actionPerformed() method of a subclass.

Returns:
The object on which this action was invoked.

getX

public int getX()
Return the horizontal position of the action, or 0 if this is not relevant (e.g., the action was triggered by a toolbar button). This must be called after actionPerformed(), and is typically called inside the actionPerformed() method of a subclass.

Returns:
The x position of the action.

getY

public int getY()
Return the vertical position of the action, or 0 if this is not relevant (e.g., the action was triggered by a toolbar button). This must be called after actionPerformed(), and is typically called inside the actionPerformed() method of a subclass.

Returns:
The y position of the action.

offsetFigure

public static double[] offsetFigure(double x,
                                    double y,
                                    double xOffset,
                                    double yOffset,
                                    java.lang.Class<?> figureClass,
                                    FigureLayer foregroundLayer,
                                    java.awt.geom.Rectangle2D visibleRectangle)
Determine a new location for a figure if another figure is already at that location.

Parameters:
x - The x value of the proposed location.
y - The y value of the proposed location.
xOffset - The x offset to be used if a figure is found.
yOffset - The y offset to be used if a figure is found.
figureClass - The Class of the figure to avoid.
foregroundLayer - The layer containing the figures.
visibleRectangle - The rectangle that describe the bounds of the visible pane.
Returns:
An array of two doubles (x and y) that represents either the original location or an offset location that does not obscure an object of class figure.