org.malai.undo
Class UndoCollector

java.lang.Object
  extended by org.malai.undo.UndoCollector

public final class UndoCollector
extends java.lang.Object

Defines a collector of undone/redone objects.
This file is part of libMalai. Copyright (c) 2009-2012 Arnaud BLOUIN libMalan 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. libMalan 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
static java.lang.String EMPTY_REDO
          The label display when there is no redo possible
static java.lang.String EMPTY_UNDO
          The label display when there is no undo possible
private  java.util.List<UndoHandler> handlers
          The handlers that handles the collector.
static UndoCollector INSTANCE
          The default undo/redo collector.
private  java.util.Deque<Undoable> redo
          Contains the redoable objects.
private  java.util.Deque<UndoHandler> redoHandlers
          Contains the handlers of each undoable of the redo stack
private  int sizeMax
          The maximal number of undo.
private  java.util.Deque<Undoable> undo
          Contains the undoable objects.
private  java.util.Deque<UndoHandler> undoHandlers
          Contains the handlers of each undoable of the undo stack
 
Constructor Summary
private UndoCollector()
          The constructor by default.
 
Method Summary
 void add(Undoable undoable, UndoHandler undoHandler)
          Adds an undoable object to the collector.
 void addHandler(UndoHandler handler)
          Adds a handler to the collector.
 void clear()
          Removes all the undoable objects of the collector.
 Undoable getLastRedo()
           
 java.lang.String getLastRedoMessage()
           
 Undoable getLastUndo()
           
 java.lang.String getLastUndoMessage()
           
 java.util.Deque<Undoable> getRedo()
           
 int getSizeMax()
           
 java.util.Deque<Undoable> getUndo()
           
 void redo()
          Redoes the last undoable object.
 void removeHandler(UndoHandler handler)
          Removes the given handler from the collector.
 void setSizeMax(int max)
           
 void undo()
          Undoes the last undoable object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final UndoCollector INSTANCE
The default undo/redo collector.


EMPTY_REDO

public static final java.lang.String EMPTY_REDO
The label display when there is no redo possible

See Also:
Constant Field Values

EMPTY_UNDO

public static final java.lang.String EMPTY_UNDO
The label display when there is no undo possible

See Also:
Constant Field Values

undoHandlers

private java.util.Deque<UndoHandler> undoHandlers
Contains the handlers of each undoable of the undo stack


redoHandlers

private java.util.Deque<UndoHandler> redoHandlers
Contains the handlers of each undoable of the redo stack


undo

private java.util.Deque<Undoable> undo
Contains the undoable objects.


redo

private java.util.Deque<Undoable> redo
Contains the redoable objects.


sizeMax

private int sizeMax
The maximal number of undo.


handlers

private java.util.List<UndoHandler> handlers
The handlers that handles the collector.

Constructor Detail

UndoCollector

private UndoCollector()
The constructor by default.

Method Detail

addHandler

public void addHandler(UndoHandler handler)
Adds a handler to the collector.

Parameters:
handler - The handler to add. Must not be null.

removeHandler

public void removeHandler(UndoHandler handler)
Removes the given handler from the collector.

Parameters:
handler - The handler to remove. Must not be null.

clear

public void clear()
Removes all the undoable objects of the collector.


add

public void add(Undoable undoable,
                UndoHandler undoHandler)
Adds an undoable object to the collector.

Parameters:
undoable - The undoable object to add.
undoHandler - The handler that produced or is associated to the undoable object.

undo

public void undo()
Undoes the last undoable object.


redo

public void redo()
Redoes the last undoable object.


getLastUndoMessage

public java.lang.String getLastUndoMessage()
Returns:
The last undoable object name.

getLastRedoMessage

public java.lang.String getLastRedoMessage()
Returns:
The last redoable object name.

getLastUndo

public Undoable getLastUndo()
Returns:
The last undoable object.

getLastRedo

public Undoable getLastRedo()
Returns:
The last redoable object.

getSizeMax

public int getSizeMax()
Returns:
The max number of saved undoable objects.

setSizeMax

public void setSizeMax(int max)
Parameters:
max - The max number of saved undoable objects. Must be great than 0.

getUndo

public java.util.Deque<Undoable> getUndo()
Returns:
The stack of saved undoable objects.
Since:
0.1

getRedo

public java.util.Deque<Undoable> getRedo()
Returns:
The stack of saved redoable objects
Since:
0.1