• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About Undo!

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic