KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > UndoHandler


1 package org.enhydra.jawe;
2
3 import javax.swing.undo.*;
4 import javax.swing.event.*;
5
6 /**
7  * Class that manages <B>undo</B> and <B>redo</B>
8  */

9 class UndoHandler implements UndoableEditListener {
10    private AbstractEditor editor;
11    protected boolean addEdits = true;
12
13    public UndoHandler(AbstractEditor editor,boolean addEdits) {
14       this.addEdits = addEdits;
15       this.editor=editor;
16    }
17
18    /**
19     * Messaged when the Document has created an edit, the edit is
20     * added to <code>undo</code>, an instance of UndoManager.
21     */

22    public void undoableEditHappened(UndoableEditEvent e) {
23       UndoableEdit ue=e.getEdit();
24       if (addEdits) {
25          editor.getUndoManager().addEdit(ue);
26       }
27       editor.getUndo().update();
28       editor.getRedo().update();
29    }
30 }
31
Popular Tags