eTextReader.actions
Class CurrentAnnotationAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by eTextReader.actions.BaseAction
          extended by eTextReader.actions.CurrentAnnotationAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action
Direct Known Subclasses:
CurrentAnnotationListingAction, DeleteAnnotationAction

public abstract class CurrentAnnotationAction
extends BaseAction

An Action object that tracks the currently selected annotation. Sub-classes can retrieve the current annotation by calling the method getCurrentNotation. Sub-classes can perform custom actions based on the current annotation by overriding the notationEntered, notationSelected and notationExited methods.

The method configureActionOnEnter can be used to alter the way the action presents itself in menus, buttons, etc. These properties are set to reasonable values by this class, making custom configuration unnecessary in most cases.

An implementation can specify whether not it can handle annotations of a specific type using the isEnabledForType method, which by default includes all types of annotations.

Author:
mcfall
See Also:
Serialized Form

Nested Class Summary
(package private)  class CurrentAnnotationAction.NotationHandler
          Listens for NotationEvents to be generated by the content pane associated with this CurrentAnnotationAction
 
Nested classes/interfaces inherited from class eTextReader.actions.BaseAction
BaseAction.Key
 
Field Summary
protected  CurrentAnnotationAction.NotationHandler notationHandler
           
 
Fields inherited from class eTextReader.actions.BaseAction
instances
 
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
protected CurrentAnnotationAction(ContentContainer contentPane)
          Constructs a new CurrentAnnotationAction associated with the specified content pane.
protected CurrentAnnotationAction(ContentContainer contentPane, java.lang.String filename)
          Constructs a new CurrentAnnotationAction associated with the specified content pane and using the specified icon
 
Method Summary
protected  void configureActionOnEnter()
           Configures the name and short description (tool-tip text) properties of this action when the notation is entered.
abstract  java.lang.String getActionText()
          Returns the verb that should be used to describe the action taken by this Action.
protected  Notation getCurrentNotation()
          Retrieves the current notation being worked with in the content pane associated with this CurrentAnnotationAction
protected  boolean isEnabledForType(Notation.AnnotationType type)
          Determines whether this action is enabled for the given type of annotation.
protected  void notationEntered(NotationEvent ne)
          Called when a notation is entered.
protected  void notationExited(NotationEvent ne)
          Called when a notation is exited.
protected  void notationSelected(NotationEvent ne)
          Called when a notation is selected.
 
Methods inherited from class eTextReader.actions.BaseAction
getAcceleratorKeyStrokeFromPreferences, getInstance, propertyChange
 
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

notationHandler

protected CurrentAnnotationAction.NotationHandler notationHandler
Constructor Detail

CurrentAnnotationAction

protected CurrentAnnotationAction(ContentContainer contentPane)
Constructs a new CurrentAnnotationAction associated with the specified content pane. No icon is specified for the action

Parameters:
contentPane - the content pane whose NotationEvents should be listened to

CurrentAnnotationAction

protected CurrentAnnotationAction(ContentContainer contentPane,
                                  java.lang.String filename)
Constructs a new CurrentAnnotationAction associated with the specified content pane and using the specified icon

Parameters:
contentPane - the content pane whose NotationEvents should be listened to
filename - the filename of the icon used to represent the action
Method Detail

getCurrentNotation

protected Notation getCurrentNotation()
Retrieves the current notation being worked with in the content pane associated with this CurrentAnnotationAction

Returns:
a Notation object represeting the currently entered or selected annotation, or null if there is no current annotation

getActionText

public abstract java.lang.String getActionText()
Returns the verb that should be used to describe the action taken by this Action. The verb is used to set the Action property appropriately as the current annotation changes

Returns:

configureActionOnEnter

protected void configureActionOnEnter()

Configures the name and short description (tool-tip text) properties of this action when the notation is entered.

The default implementation sets the NAME property of the action to getActionText(), a space, and the type of the annotation. The SHORT_DESCRIPTION property is set to getActionText(), " this ", and the type of the annotation. Sub-classes can override this method to change these default values


notationEntered

protected void notationEntered(NotationEvent ne)
Called when a notation is entered. Sub-classes can override this method to perform custom handling whenever the current annotation is changed. This default implementation does nothing. This method should not be used to change the displayed text/tooltip text of the action, since it is called BEFORE configureActionOnEnter. Use that method to change the display properties of the action.

Parameters:
ne - the NotationEvent representing the entering of the notation
See Also:
configureActionOnEnter()

notationSelected

protected void notationSelected(NotationEvent ne)
Called when a notation is selected. Sub-classes can override this method to perform custom handling whenever an annotation is selected. This default implementation does nothing. This method should not be used to change the displayed text/tooltip text of the action, since it is called BEFORE configureActionOnEnter. Use that method to change the display properties of the action.

Parameters:
ne - the NotationEvent representing the selection of the notation
See Also:
configureActionOnEnter()

notationExited

protected void notationExited(NotationEvent ne)
Called when a notation is exited. Sub-classes can override this method to perform custom handling whenever the current annotation is exited. This default implementation does nothing.

Parameters:
ne - the NotationEvent representing the exiting of the notation

isEnabledForType

protected boolean isEnabledForType(Notation.AnnotationType type)
Determines whether this action is enabled for the given type of annotation. Sub-classes can override this method to only be enabled when the current annotation is of a specific type. The default implementation enables the action for all types

Parameters:
type - the type of annotation in question
Returns:
true if this action should be enabled for this annotation, false otherwise