ptolemy.vergil.toolbox
Class MoveAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by ptolemy.vergil.toolbox.FigureAction
          extended by ptolemy.vergil.toolbox.MoveAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action

public class MoveAction
extends FigureAction

An action to move an object up or down in its list. This can be used, for example, to move icon elements towards the foreground or to control the order in which attributes or ports appear.

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

Nested Class Summary
private static class MoveAction.MoveType
          For a type-safe enumeration.
 
Nested classes/interfaces inherited from class ptolemy.vergil.toolbox.FigureAction
FigureAction.SourceType
 
Field Summary
private  MoveAction.MoveType _type
          The type of move.
static MoveAction.MoveType DOWN
          Indicator for move down.
static MoveAction.MoveType TO_FIRST
          Indicator for move to first.
static MoveAction.MoveType TO_LAST
          Indicator for move to last.
static MoveAction.MoveType UP
          Indicator for move up.
 
Fields inherited from class ptolemy.vergil.toolbox.FigureAction
CANVAS_TYPE, CONTEXTMENU_TYPE, HOTKEY_TYPE, MENUBAR_TYPE, PASTE_OFFSET, TOOLBAR_TYPE
 
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
MoveAction(java.lang.String description, MoveAction.MoveType type)
          Construct a new action.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          Perform the move action and register the undo action.
static void move(java.util.List targets, MoveAction.MoveType type, NamedObj context)
          Move the objects in the specified list up or down in the list of similar objects in their container, as specified by the move type.
 
Methods inherited from class ptolemy.vergil.toolbox.FigureAction
getFigure, getFrame, getSourceType, getTarget, getX, getY, offsetFigure
 
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

DOWN

public static final MoveAction.MoveType DOWN
Indicator for move down.


TO_FIRST

public static final MoveAction.MoveType TO_FIRST
Indicator for move to first.


TO_LAST

public static final MoveAction.MoveType TO_LAST
Indicator for move to last.


UP

public static final MoveAction.MoveType UP
Indicator for move up.


_type

private MoveAction.MoveType _type
The type of move.

Constructor Detail

MoveAction

public MoveAction(java.lang.String description,
                  MoveAction.MoveType type)
Construct a new action. The type of move is specified by the public fields DOWN, TO_FIRST, TO_LAST, and UP.

Parameters:
description - A description.
type - Indicator of the type of move.
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Perform the move action and register the undo action.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Overrides:
actionPerformed in class FigureAction
Parameters:
event - The event.

move

public static void move(java.util.List targets,
                        MoveAction.MoveType type,
                        NamedObj context)
Move the objects in the specified list up or down in the list of similar objects in their container, as specified by the move type. If the type is TO_FIRST or UP, then the objects in the specified list are processed in reverse order, under the assumption that they will already be sorted into the order in which they appear in the list of similar objects in their container. This is factored out as a separate static method so that it can be called in the redo action and so that it can be used elsewhere. The context is what is used to register an undo action. It should be a common container, or if there is only one target, then the target itself.

Parameters:
targets - The list of objects to move.
type - One of DOWN, TO_FIRST, TO_LAST, and UP.
context - The context.