org.malai.action
Class Action

java.lang.Object
  extended by org.malai.action.Action
Direct Known Subclasses:
ActivateInactivateInstruments, CopyShapes, DrawingAction, Export, InstrumentAction, IOAction, ModifyLatexProperties, ModifyPencilStyle, ModifyValue, MovePoint, OpenWebPage, PositionAction, Redo, Scroll, SetUnit, ShowHideAction, Undo, WidgetAction, WritePreferences

public abstract class Action
extends java.lang.Object

An action is based on the command design pattern: it is an object that encapsulates information to execute a task and to undo/redo it if necessary.

This file is part of Malai.
Copyright (c) 2009-2012 Arnaud BLOUIN

Malai is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Malai is distributed without any warranty; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Since:
0.2
Author:
Arnaud BLOUIN

Nested Class Summary
static class Action.ActionStatus
          Defines the different state of the action.
 
Field Summary
protected  Action.ActionStatus status
          Provides the state of the action.
 
Constructor Summary
Action()
          The default constructor.
 
Method Summary
 void abort()
          Aborts the action.
 boolean cancelledBy(Action action)
          Defines if the given action can cancel the calling action.
abstract  boolean canDo()
           
protected abstract  void doActionBody()
          This method contains the core code to execute when the action is executed.
 boolean doIt()
          Executes the action.
 void done()
          Sets the action to "done".
 void flush()
          When an action is no more useful it can be flushes to release the used data.
 Action.ActionStatus getStatus()
          Provides the state of the action.
 boolean hadEffect()
           
 boolean isDone()
           
abstract  boolean isRegisterable()
          Specifies if the action must be saved in the action register.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

status

protected Action.ActionStatus status
Provides the state of the action.

Constructor Detail

Action

public Action()
The default constructor.

Method Detail

flush

public void flush()
When an action is no more useful it can be flushes to release the used data. Should be overridden.

Since:
0.2

isRegisterable

public abstract boolean isRegisterable()
Specifies if the action must be saved in the action register. For instance, some actions, such as a scroll of the scroll bars, should not be saved nor put in the undo/redo manager. Thus, they must not be registrable.

Returns:
True: the action is registrable.
Since:
0.1

doIt

public boolean doIt()
Executes the action. Should be overridden by sub-class to define stuffs to execute. If the status of the action differs than CREATED or EXECUTED and if the action cannot be done (canDo), the action is not executed.

Returns:
True if the execution is successful. False otherwise.
Since:
0.1

doActionBody

protected abstract void doActionBody()
This method contains the core code to execute when the action is executed.

Since:
0.1

canDo

public abstract boolean canDo()
Returns:
True if the action can be executed.
Since:
0.1

hadEffect

public boolean hadEffect()
Returns:
True if the execution of the action had effects on the target. By default this function return the result of isDone. Should be overridden.
Since:
0.1

cancelledBy

public boolean cancelledBy(Action action)
Defines if the given action can cancel the calling action. Should be overridden. By default, false is returned.

Parameters:
action - The action to test.
Returns:
True if the given action cancels the calling action. By default, false is returned.
Since:
0.1

done

public void done()
Sets the action to "done".

Since:
0.1

isDone

public boolean isDone()
Returns:
True if the action is done.
Since:
0.1

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

abort

public void abort()
Aborts the action.

Since:
0.1

getStatus

public Action.ActionStatus getStatus()
Provides the state of the action.

Returns:
The state of the action.
Since:
0.2