20 package net.sf.gridarta.textedit.scripteditor;
22 import java.util.HashMap;
24 import javax.swing.Action;
25 import javax.swing.event.UndoableEditListener;
26 import javax.swing.text.Document;
27 import javax.swing.undo.CannotRedoException;
28 import javax.swing.undo.CannotUndoException;
29 import javax.swing.undo.UndoManager;
30 import javax.swing.undo.UndoableEdit;
32 import net.
sf.japi.swing.action.ActionBuilder;
33 import net.
sf.japi.swing.action.ActionBuilderFactory;
34 import net.
sf.japi.swing.action.ActionMethod;
35 import org.jetbrains.annotations.NotNull;
36 import org.jetbrains.annotations.Nullable;
48 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
66 private final Map<Document, UndoManager>
undo =
new HashMap<>();
89 assert !
undo.containsKey(document);
91 undo.put(document,
new UndoManager());
99 assert
undo.containsKey(document);
100 undo.remove(document);
111 public void resetUndo(@NotNull
final Document document) {
122 if (undoManager !=
null && undoManager.canUndo()) {
126 }
catch (
final CannotUndoException ignored) {
138 if (undoManager !=
null && undoManager.canRedo()) {
142 }
catch (
final CannotRedoException ignored) {
152 final boolean canUndo = undoManager !=
null && undoManager.canUndo();
153 aUndo.setEnabled(canUndo);
155 aUndo.putValue(Action.NAME,
ACTION_BUILDER.format(
"scriptEditUndo.name", undoManager.getUndoPresentationName()));
160 final boolean canRedo = undoManager !=
null && undoManager.canRedo();
161 aRedo.setEnabled(canRedo);
163 aRedo.putValue(Action.NAME,
ACTION_BUILDER.format(
"scriptEditRedo.name", undoManager.getRedoPresentationName()));
187 final UndoManager result =
undo.get(document);
188 assert result !=
null;