org.bs.mdi
Class CompositeAction

java.lang.Object
  extended byorg.bs.mdi.Action
      extended byorg.bs.mdi.CompositeAction

public class CompositeAction
extends Action

A CompositeAction object consists of one or more single Action objects, and can be handled like a single Action object. Use this class for grouping similar actions to logical units, which the user should be able to undo/redo at once.

Think of a text editor for example. It usually won't let you undo a single keystroke, but rather just whole words or lines. The single keystrokes are somehow "glued together" to bigger units. You can use this class to simulate this behaviour.


Constructor Summary
CompositeAction(ActionObservable observable)
          Creates a new CompositeAction.
CompositeAction(ActionObservable observable, String overrideName)
          Creates a new CompositeAction and overrides its name.
 
Method Summary
 void add(Action action)
          Add an action to this CompositeAction.
 void applyTo(Data data)
          Applies this action to a Data object.
 void applyTo(View view)
          Applies this action to a View object.
 boolean clustersWith(Action a)
          Returns true if this action should be clustered together with the action given as the parameter.
 Action getFirstAction()
          Returns the first action of this CompositeAction.
 Action getLastAction()
          Returns the last action of this CompositeAction
 String getName()
          Returns the name of the action type.
 boolean isUndoable()
          Returns true if the action can be made undone.
 void remove(Action action)
          Remove the given action from this CompositeAction.
 String toString()
          Returns a string representation of this action.
 void undoFrom(Data data)
          Undoes this Action from a Data object.
 void undoFrom(View view)
          Undoes this Action from a View object.
 
Methods inherited from class org.bs.mdi.Action
getSource, isRetarded, setRetarded
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompositeAction

public CompositeAction(ActionObservable observable)
Creates a new CompositeAction. Note that you should at least add one action (using add(org.bs.mdi.Action)) before this CompositeAction can be considered fully functional.

Parameters:
observable - the source where this CompositeAction originated from

CompositeAction

public CompositeAction(ActionObservable observable,
                       String overrideName)
Creates a new CompositeAction and overrides its name.

Parameters:
observable - the source where this CompositeAction originated from
overrideName - the name to override the default name with
Method Detail

applyTo

public void applyTo(Data data)
Description copied from class: Action
Applies this action to a Data object. Subclasses of Action should implement this method to initiate a state change on the given data object.

Specified by:
applyTo in class Action
Parameters:
data - the Data object

applyTo

public void applyTo(View view)
Description copied from class: Action
Applies this action to a View object. Subclasses of Action should implement this method to initiate a state change on the given view object.

Specified by:
applyTo in class Action
Parameters:
view - the View object

undoFrom

public void undoFrom(Data data)
Description copied from class: Action
Undoes this Action from a Data object. Subclasses of Action should implement this method to initiate a state change on the given data object.

Specified by:
undoFrom in class Action
Parameters:
data - the Data object

undoFrom

public void undoFrom(View view)
Description copied from class: Action
Undoes this Action from a View object. Subclasses of Action should implement this method to initiate a state change on the given view object.

Specified by:
undoFrom in class Action
Parameters:
view - the View object

add

public void add(Action action)
Add an action to this CompositeAction. Note that nesting CompositeActions has not been tested yet, but is supposed to work.

Parameters:
action - the action to be added

remove

public void remove(Action action)
Remove the given action from this CompositeAction.

Parameters:
action - the action to be removed

clustersWith

public boolean clustersWith(Action a)
Description copied from class: Action
Returns true if this action should be clustered together with the action given as the parameter. This mechanism allows you to "glue" similar consecutive actions together to one "action cluster". This is done by combining them to a CompositeAction. The actual clustering is done by the RootData object. The usual calling convention is: oldAction.clustersWith(newAction).

Overrides:
clustersWith in class Action
Parameters:
a - the Action to be tested whether it can be clustered or not
Returns:
true if clustering is desirable, false otherwise

getFirstAction

public Action getFirstAction()
Returns the first action of this CompositeAction.

Returns:
the first action

getLastAction

public Action getLastAction()
Returns the last action of this CompositeAction

Returns:
the last action

isUndoable

public boolean isUndoable()
Description copied from class: Action
Returns true if the action can be made undone. An action should identify itself as non-undoable if it includes too few information in order to be able to undo the changes.

Overrides:
isUndoable in class Action
Returns:
true if this action is undoable

getName

public String getName()
Description copied from class: Action
Returns the name of the action type. If this action performs text insertion in a text editor for example, this method should return something like "text insertion".

Specified by:
getName in class Action
Returns:
the name this action type

toString

public String toString()
Description copied from class: Action
Returns a string representation of this action. The returned string should describe exactly what this action does.

Specified by:
toString in class Action
Returns:
the string representation of this action.