org.jhotdraw.draw.action
Class AbstractSelectedAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.jhotdraw.draw.action.AbstractSelectedAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action, Disposable
Direct Known Subclasses:
AlignAction, ApplyAttributesAction, AttributeAction, BringToFrontAction, CombineAction, DefaultAttributeAction, FontChooserHandler, GroupAction, IncreaseHandleDetailLevelAction, MoveAction, MoveConstrainedAction, PickAttributesAction, SelectSameAction, SendToBackAction

public abstract class AbstractSelectedAction
extends javax.swing.AbstractAction
implements Disposable

This abstract class can be extended to implement an Action that acts on behalf of the selected figures of a DrawingView.

By default the enabled state of this action reflects the enabled state of the active DrawingView. If no drawing view is active, this action is disabled. When many actions listen to the enabled state of the active drawing views this can considerably slow down the editor. If updating the enabled state is not necessary, you can prevent the action from doing so using setUpdateEnabledState(boolean).

AbstractDrawingEditorAction listens using a WeakPropertyChangeListener on the DrawingEditor and thus may become garbage collected if it is not referenced by any other object.

Version:
$Id: AbstractSelectedAction.java 534 2009-06-13 14:54:19Z rawcoder $
Author:
Werner Randelshofer
See Also:
Serialized Form

Nested Class Summary
private  class AbstractSelectedAction.EventHandler
           
 
Field Summary
private  DrawingView activeView
           
private  DrawingEditor editor
           
private  AbstractSelectedAction.EventHandler eventHandler
           
protected  ResourceBundleUtil labels
           
 
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
AbstractSelectedAction(DrawingEditor editor)
          Creates an action which acts on the selected figures on the current view of the specified editor.
 
Method Summary
 void dispose()
          Disposes of all resources held by this object so that they can be garbage collected.
protected  void fireUndoableEditHappened(javax.swing.undo.UndoableEdit edit)
           
protected  Drawing getDrawing()
           
 DrawingEditor getEditor()
           
protected  DrawingView getView()
           
 boolean isUpdatEnabledState()
          Returns true, if this action automatically updates its enabled state to reflect the enabled state of the active DrawingView.
private  void registerEventHandler()
          Registers the event handler from the drawing editor and the active drawing view.
 void setEditor(DrawingEditor editor)
           
 void setUpdateEnabledState(boolean newValue)
          By default, the enabled state of this action is updated to reflect the enabled state of the active DrawingView.
private  void unregisterEventHandler()
          Unregisters the event handler from the drawing editor and the active drawing view.
protected  void updateEnabledState()
          Updates the enabled state of this action to reflect the enabled state of the active DrawingView.
 
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
 
Methods inherited from interface java.awt.event.ActionListener
actionPerformed
 

Field Detail

editor

private DrawingEditor editor

activeView

private transient DrawingView activeView

labels

protected ResourceBundleUtil labels

eventHandler

private AbstractSelectedAction.EventHandler eventHandler
Constructor Detail

AbstractSelectedAction

public AbstractSelectedAction(DrawingEditor editor)
Creates an action which acts on the selected figures on the current view of the specified editor.

Method Detail

updateEnabledState

protected void updateEnabledState()
Updates the enabled state of this action to reflect the enabled state of the active DrawingView. If no drawing view is active, this action is disabled.


dispose

public void dispose()
Description copied from interface: Disposable
Disposes of all resources held by this object so that they can be garbage collected.

Specified by:
dispose in interface Disposable

setEditor

public void setEditor(DrawingEditor editor)

getEditor

public DrawingEditor getEditor()

getView

protected DrawingView getView()

getDrawing

protected Drawing getDrawing()

fireUndoableEditHappened

protected void fireUndoableEditHappened(javax.swing.undo.UndoableEdit edit)

setUpdateEnabledState

public void setUpdateEnabledState(boolean newValue)
By default, the enabled state of this action is updated to reflect the enabled state of the active DrawingView. Since this is not always necessary, and since many listening actions may considerably slow down the drawing editor, you can switch this behavior off here.

Parameters:
newValue - Specify false to prevent automatic updating of the enabled state.

isUpdatEnabledState

public boolean isUpdatEnabledState()
Returns true, if this action automatically updates its enabled state to reflect the enabled state of the active DrawingView.


unregisterEventHandler

private void unregisterEventHandler()
Unregisters the event handler from the drawing editor and the active drawing view.


registerEventHandler

private void registerEventHandler()
Registers the event handler from the drawing editor and the active drawing view.