This is my code... but it is not yet a
SSCCE...
code:
----------------------------------------------------------------------------
public class notepad
{
HashMap<Object, Action> actions;
protected UndoAction undoAction;
protected RedoAction redoAction;
protected UndoManager undo = new UndoManager();
public constructor(){
actions = createActionTable(textArea);
}
class UndoAction extends AbstractAction {
public UndoAction() {
super("Undo");
setEnabled(true);
}
public void actionPerformed(ActionEvent e) {
try {
undo.undo();
}
catch (CannotUndoException ex) {
System.out.println("Unable to undo: " + ex);
ex.printStackTrace();
}
updateUndoState();
redoAction.updateRedoState();
}
protected void updateUndoState() {
if (undo.canUndo()) {
setEnabled(true);
putValue(Action.NAME, undo.getUndoPresentationName());
} else {
setEnabled(false);
putValue(Action.NAME, "Undo");
}
}
}
protected class MyUndoableEditListener implements UndoableEditListener {
public void undoableEditHappened(UndoableEditEvent e) {
undo.addEdit(e.getEdit());
undoAction.updateUndoState();
redoAction.updateRedoState();
}
}
private HashMap<Object, Action> createActionTable(JTextComponent textComponent) {
HashMap<Object, Action> actions = new HashMap<Object, Action>();
Action[] actionsArray = textComponent.getActions();
for (int i = 0; i < actionsArray.length; i++) {
Action a = actionsArray[i];
actions.put(a.getValue(Action.NAME), a);
}
return actions;
}
private Action getActionByName(
String name) {
return actions.get(name);
}
}
----------------------------------------------------------------------------
[ June 11, 2008: Message edited by: eLL Pascual ]