Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Only Undo/Redo Editing but No Syntax Highlighting

843806Jan 7 2008 — edited Jan 7 2008
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;
		}
    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2008
Added on Jan 7 2008
1 comment
100 views