I have a JTextPane with styled content, when I apply undo/redo I don't want the different Color Highlighting to be added to Undo/Redo queue of UndoManager. How can I? My Undo Listener and Actions looks like below:
protected class RulesUndoableEditListener implements UndoableEditListener {
RuleExpressionUndo undoAction;
RedoRuleExpression redoAction;
UndoManager undoMgr;
public RulesUndoableEditListener(RuleExpressionUndo undoAction,
RedoRuleExpression redoAction, UndoManager undoMgr)
{
this.undoAction = undoAction;
this.redoAction = redoAction;
this.undoMgr = undoMgr;
}
public void undoableEditHappened(UndoableEditEvent e) {
undoMgr.addEdit(e.getEdit());
undoAction.updateUndoState();
redoAction.updateRedoState();
}
}
class RuleExpressionUndo extends AbstractAction {
RedoRuleExpression redoAction;
UndoManager undo;
public RuleExpressionUndo(UndoManager undo) {
super("Undo");
this.undo = undo;
setEnabled(false);
}
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");
}
}
/**
* @param redoAction the redoAction to set
*/
public void setRedoAction(RedoRuleExpression redoAction)
{
this.redoAction = redoAction;
}
}
class RedoRuleExpression extends AbstractAction {
RuleExpressionUndo undoAction;
UndoManager undo;
public RedoRuleExpression(UndoManager undo) {
super("Redo");
this.undo = undo;
setEnabled(false);
}
public void actionPerformed(ActionEvent e) {
try {
undo.redo();
} catch (CannotRedoException ex) {
System.out.println("Unable to redo: " + ex);
ex.printStackTrace();
}
updateRedoState();
undoAction.updateUndoState();
}
protected void updateRedoState() {
if (undo.canRedo()) {
setEnabled(true);
putValue(Action.NAME, undo.getRedoPresentationName());
} else {
setEnabled(false);
putValue(Action.NAME, "Redo");
}
}
/**
* @param undoAction the undoAction to set
*/
public void setUndoAction(RuleExpressionUndo undoAction)
{
this.undoAction = undoAction;
}
}