package jaxe; import javax.swing.undo.CannotRedoException; import javax.swing.undo.CannotUndoException; import javax.swing.undo.UndoManager; import javax.swing.undo.UndoableEdit; /** * UndoManager to recognise a modified document * @author Kykal */ public class JaxeUndoManager extends UndoManager { /** * Creates the UndoManager * */ public JaxeUndoManager() { _count = 0; _edited = false; } /** * Adds an edit and increases the counter * @see javax.swing.undo.UndoManager#addEdit(javax.swing.undo.UndoableEdit) */ public synchronized boolean addEdit(UndoableEdit anEdit) { _count++; return super.addEdit(anEdit); } /** * Does an undo and decreases the counter * @see javax.swing.undo.UndoManager#undo() */ public synchronized void undo() throws CannotUndoException { super.undo(); _count--; } /** * Does a redo and increases the counter again * @see javax.swing.undo.UndoManager#redo() */ public synchronized void redo() throws CannotRedoException { super.redo(); _count++; } /** * Sets the edited flag */ public void setEdited() { _edited = true; } /** * Is document edited? * @return true, if any edit has added to UndoManager or edit flag is set */ public boolean isEdited() { return _edited || _count > 0; } /** * Edit flag */ private boolean _edited; /** * Edit counter */ private int _count; }