• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Undo!

 
eLL Pascual
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you pls help me do undo...

I already have a complete and working code of undo and undoAction but the problem is it is so confusing and I can't understand the importance of each code. Maybe you can give me the steps on how to do it and I will just compare it to the codes I have...

Please help me...

Thanks!
 
Maneesh Godbole
Saloon Keeper
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by eLL Pascual:
Maybe you can give me the steps on how to do it and I will just compare it to the codes I have...


Maybe you can post your code and we can walk you through it.
 
eLL Pascual
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Maneesh Godbole
Saloon Keeper
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Always use CODE tags. It makes your code a lot easier to read and understand.
2) Please use proper naming conventions in your code. it should be
Thisis a good place to pick up pointers on coding styles.
3) What is ? Is that your constructor or a method?
4)
I already have a complete and working code of undo and undoAction
Is the code you posted part of your working code? I doubt.
5)
but the problem is it is so confusing and I can't understand the importance of each code
Which part did you not understand
[ June 11, 2008: Message edited by: Maneesh Godbole ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic