can i have more then one JTextArea and JTextField for one inner class (MyUndoableEditListener())?
.
.
MainTabbed mPane = new MainTabbed();
.
.
.
mPane.area.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.locField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.dateField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.ndBuddyField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.depthField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.firstBuddy.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.weightField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.timeInField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.tOutField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.startTimeField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.sTimeField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.bTimeField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.startField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.finishField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.airField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.surfaceField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.bottomField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.equipmentArea.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.waterTypeField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.visiField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.diveLogField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
mPane.diveNoField.getDocument().addUndoableEditListener(new MyUndoableEditListener());
.
.
.
class UndoAction extends AbstractAction{
public UndoAction(){
super("Undo");
setEnabled(false);
}
public void updateUndoState(){
if (undo.canUndo()){
setEnabled(true);
putValue(Action.NAME, undo.getUndoPresentationName());
}
else {
setEnabled(false);
putValue(Action.NAME, "Undo");
}
}
public void actionPerformed(ActionEvent e){
try{
undo.undo();
}
catch (CannotUndoException ex){}
updateUndoState();
redoAction.updateRedoState();
}
}
class RedoAction extends AbstractAction{
public RedoAction() {
super("Redo");
setEnabled(false);
}
public void actionPerformed(ActionEvent e){
try{
undo.redo();
}
catch(CannotRedoException ex){}
updateRedoState();
undoAction.updateUndoState();
}
protected void updateRedoState() {
if (undo.canRedo()) {
setEnabled(true);
putValue(Action.NAME, undo.getRedoPresentationName());
}
else {
setEnabled(false);
putValue(Action.NAME, "Redo");
}
}
}
class MyUndoableEditListener implements UndoableEditListener {
public void undoableEditHappened(UndoableEditEvent e) {
//Remember the edit and update the menus.
undo.addEdit(e.getEdit());
undoAction.updateUndoState();
redoAction.updateRedoState();
}
}
it seems doesn't work @@a, it only works for the first JTextArea but the second JTextArea cant work.
or should i go and create a new inner class (MyUndoableEditListener()) for each JTextArea ?
and is this undo manager working for JTextField ?