91 lines
1.9 KiB
Java
91 lines
1.9 KiB
Java
package dev.kske.undoredo.core;
|
|
|
|
import java.util.*;
|
|
|
|
/**
|
|
* A change manager keeps track of subsequent changes and allows un- and redoing them. A specific
|
|
* change can be marked using {@link #mark()} to keep track of a saved state in the application that
|
|
* uses the manager.
|
|
* <p>
|
|
* If you intend to listen to the state of a change manager, consider writing a wrapper
|
|
* implementation for an existing change manager that adds the necessary hooks. If you use JavaFX,
|
|
* take a look at the {@code dev.kske.undoredo.javafx} module.
|
|
*
|
|
* @param <C> the change type to store in this change manager
|
|
* @author Maximilian Käfer
|
|
* @author Kai S. K. Engelbart
|
|
* @since 0.0.1
|
|
*/
|
|
public interface ChangeManager<C extends Change> {
|
|
|
|
/**
|
|
* Applies the given change and appends it to the change list.
|
|
*
|
|
* @param change the change to add
|
|
* @since 0.0.1
|
|
*/
|
|
void addChange(C change);
|
|
|
|
/**
|
|
* @return the change that was applied last
|
|
* @since 0.0.1
|
|
*/
|
|
Optional<C> getLastChange();
|
|
|
|
/**
|
|
* Undoes the current change.
|
|
*
|
|
* @return whether an action was performed
|
|
* @since 0.1.0
|
|
*/
|
|
boolean undo();
|
|
|
|
/**
|
|
* Applies the change that was undone before.
|
|
*
|
|
* @return whether an action was performed
|
|
* @since 0.0.1
|
|
*/
|
|
boolean redo();
|
|
|
|
/**
|
|
* Marks the current change.
|
|
*
|
|
* @since 0.0.1
|
|
*/
|
|
void mark();
|
|
|
|
/**
|
|
* Resets the marked index so that no change is marked.
|
|
*
|
|
* @since 0.0.1
|
|
*/
|
|
void unmark();
|
|
|
|
/**
|
|
* @return whether the current change is marked
|
|
* @since 0.0.1
|
|
*/
|
|
boolean isAtMarkedChange();
|
|
|
|
/**
|
|
* @return whether a change is present that can be undone
|
|
* @since 0.0.1
|
|
*/
|
|
boolean isUndoAvailable();
|
|
|
|
/**
|
|
* @return whether a change is present that can be redone
|
|
* @since 0.0.1
|
|
*/
|
|
boolean isRedoAvailable();
|
|
|
|
/**
|
|
* Provides an unmodifiable view of the changes stored in this change manager.
|
|
*
|
|
* @return all stored changes
|
|
* @since 0.0.1
|
|
*/
|
|
List<C> getChanges();
|
|
}
|