http://www.jpicedt.org

jpicedt.graphic.toolkit
Class PEAbstractAction<T>

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by jpicedt.graphic.toolkit.PEAbstractAction<T>
All Implemented Interfaces:
ActionListener, Serializable, Cloneable, EventListener, Action
Direct Known Subclasses:
PEAction, PEConvexZoneAction

public abstract class PEAbstractAction<T>
extends AbstractAction

An abstract subclass of Swing's AbstractAction that can (but may as well not) be shared across multiple PECanvas.

This implementation uses the same set of properties as AbstractAction.

The constructor gives a convenient way of automatically building localized properties associated with this PEAbstractAction from a simple String (the "actionName" parameter), using a user-provided ActionLocalizer.
Note : if an ActionLocalizer is provided to the constructor, and some of its methods return null values, the corresponding properties are set to null. However, all jPicEdt components (e.g. PEMenu, PEToolBar,...), like Swing components, are guaranteed to handle this case properly w/o throwing an exception.
For instance, simply setting the NAME property to null and filling the SMALL_ICON property create a JButton without text under the component's Icon (this is the standard Swing behaviour).

Since:
jPicEdt 1.6
Version:
$Id: PEAbstractAction.java,v 1.2 2013/03/27 06:57:06 vincentb1 Exp $
Author:
Vincent Belaïche
See Also:
Serialized Form

Field Summary
protected  T targetElement
           
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
PEAbstractAction(ActionDispatcher actionDispatcher, String actionName, ActionLocalizer localizer)
          Constructor to be used either : when the target board is not known in advance (e.g.
 
Method Summary
 void actionPerformed(ActionEvent e)
          This is a default implementation of the "actionPerformed" method suited for undoable actions : we first call "beginUndoableUpdate" with "actionName" as the presentation name, then delegate to "undoableActionPerformed", finally mark the undoable-update as ended.
protected  PECanvas getCanvas()
          Returns the PECanvas this Action acts upon, as specified by the ActionDispatcher provided in the constructor.
protected  Drawing getDrawing()
          Returns the Drawing that serves as a model for the target PECanvas (this is a convenience call to getCanvas().
protected  EditorKit getEditorKit()
          Returns the EditorKit associated with the target PECanvas (this is a convenience call to getCanvas().
protected abstract  Iterator<T> getIterator()
           
protected  T getSelectedObject()
          Returns the selected graphic element in the target board ; if setSelectedObject() has been previously called with a non-null argument, it's returned here.
 void setSelectedObject(T e)
          Sets the selected graphic element "by hand".
protected  void undoableActionPerformed(ActionEvent e)
          called by "actionPerformed" ; default implementation does nothing.
 
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

targetElement

protected T targetElement
Constructor Detail

PEAbstractAction

public PEAbstractAction(ActionDispatcher actionDispatcher,
                        String actionName,
                        ActionLocalizer localizer)
Constructor to be used either :

Parameters:
actionDispatcher - the ActionDispatcher that provides a target when this Action gets invoked. If set to null, then subclasses may want to simply override actionPerformed().
actionName - the actionName of this Action that serve to build this Action's properties using the given ActionLocalizer (if non-null) ; in any case, actionName is used to fill the ACTION_COMMAND_KEY property.
localizer - the ActionLocalizer that feeds this Action with localized properties ; if null, the Action's NAME property is simply initialized to actionName, but other properties are not set (this allow a subclass to set these properties manually).
Method Detail

actionPerformed

public void actionPerformed(ActionEvent e)
This is a default implementation of the "actionPerformed" method suited for undoable actions : we first call "beginUndoableUpdate" with "actionName" as the presentation name, then delegate to "undoableActionPerformed", finally mark the undoable-update as ended.

Action that don't want to be undoable should simply override this method as usual.


undoableActionPerformed

protected void undoableActionPerformed(ActionEvent e)
called by "actionPerformed" ; default implementation does nothing. Action that want to be undoable override this method instead of "actionPerformed".

Note : this is not an abstract method, since this would force all PEAbstractAction's, including those we don't want to be undoable, to implement this method.


getCanvas

protected PECanvas getCanvas()
Returns the PECanvas this Action acts upon, as specified by the ActionDispatcher provided in the constructor.

Returns:
a null reference if no suitable canvas is found by the ActionDispatcher.

getDrawing

protected Drawing getDrawing()
Returns the Drawing that serves as a model for the target PECanvas (this is a convenience call to getCanvas().


getEditorKit

protected EditorKit getEditorKit()
Returns the EditorKit associated with the target PECanvas (this is a convenience call to getCanvas().


getSelectedObject

protected T getSelectedObject()
Returns the selected graphic element in the target board ; if setSelectedObject() has been previously called with a non-null argument, it's returned here.

Returns:
null if there's no selected graphic element, OR more than one.

setSelectedObject

public void setSelectedObject(T e)
Sets the selected graphic element "by hand". Set it to null to revert to the standard behavior.


getIterator

protected abstract Iterator<T> getIterator()

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org