org.malai.action
Class ActionsRegistry

java.lang.Object
  extended by org.malai.action.ActionsRegistry

public final class ActionsRegistry
extends java.lang.Object

A register of actions.

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.1
Author:
Arnaud Blouin

Field Summary
private  java.util.List<Action> actions
          The saved actions.
private  java.util.List<ActionHandler> handlers
          The actions handlers.
static ActionsRegistry INSTANCE
          The register of actions.
private  int sizeMax
          The max number of actions that can contains the register.
 
Constructor Summary
private ActionsRegistry()
          Creates and initialises a register.
 
Method Summary
 void abortAction(Action action)
          Aborts the given action, i.e. the action is aborted then remove from the register.
 void addAction(Action action, ActionHandler actionHanndler)
          Adds an action to the register.
 void addHandler(ActionHandler handler)
          Adds an action handler.
 void cancelActions(Action action)
          Removes and flushes actions from the register using a given action.
<T extends Action>
T
getAction(java.lang.Class<T> clazz)
           
 java.util.List<Action> getActions()
           
 int getSizeMax()
           
 void onActionDone(Action action)
          Notifies handlers that an action ends.
 void onActionExecuted(Action action)
          Notifies handlers that an action has been executed.
 void removeAction(Action action)
          Removes the action from the register.
 void removeAllHandlers()
          Removes all the action handlers.
 void removeHandler(ActionHandler handler)
          Removes the given handler.
 void setSizeMax(int sizeMax)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

actions

private java.util.List<Action> actions
The saved actions.


handlers

private java.util.List<ActionHandler> handlers
The actions handlers.


sizeMax

private int sizeMax
The max number of actions that can contains the register.


INSTANCE

public static final ActionsRegistry INSTANCE
The register of actions.

Constructor Detail

ActionsRegistry

private ActionsRegistry()
Creates and initialises a register.

Since:
0.1
Method Detail

onActionExecuted

public void onActionExecuted(Action action)
Notifies handlers that an action has been executed.

Parameters:
action - The executed action.
Since:
0.2

onActionDone

public void onActionDone(Action action)
Notifies handlers that an action ends.

Parameters:
action - The action that ends.
Since:
0.2

getActions

public java.util.List<Action> getActions()
Returns:
The stored actions. Cannot be null.
Since:
0.1

cancelActions

public void cancelActions(Action action)
Removes and flushes actions from the register using a given action.

Parameters:
action - The action that may cancels others.
Since:
0.1

addAction

public void addAction(Action action,
                      ActionHandler actionHanndler)
Adds an action to the register. Before being added, the given action is used to cancel actions already added. Handlers are notified of the add of the given action. If Undoable, the action is added to the undo collector as well.

Parameters:
action - The action to add. Cannot be null.
actionHanndler - The handler that produced or is associated to the action. Cannot be null.
Since:
0.2

removeAction

public void removeAction(Action action)
Removes the action from the register. The action is then flushes.

Parameters:
action - The action to remove.
Since:
0.1

addHandler

public void addHandler(ActionHandler handler)
Adds an action handler.

Parameters:
handler - The handler to add.
Since:
0.1

removeHandler

public void removeHandler(ActionHandler handler)
Removes the given handler.

Parameters:
handler - The handler to remove.
Since:
0.2

removeAllHandlers

public void removeAllHandlers()
Removes all the action handlers.

Since:
0.2

getAction

public <T extends Action> T getAction(java.lang.Class<T> clazz)
Parameters:
clazz - The reference class.
Returns:
The first action of the exact same class of the given class.
Since:
0.1

abortAction

public void abortAction(Action action)
Aborts the given action, i.e. the action is aborted then remove from the register. Handlers are then notified. The action is finally flushes.

Parameters:
action - The action to abort.
Since:
0.1

getSizeMax

public int getSizeMax()
Returns:
The max number of actions that can contains the register.
Since:
0.2

setSizeMax

public void setSizeMax(int sizeMax)
Parameters:
sizeMax - The max number of actions that can contains the register. Must be equal or greater than 0.
Since:
0.2