[Jsxe-cvs] SF.net SVN: jsxe: [1118] trunk/jsxe/src/net/sourceforge/jsxe/gui
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-08-08 04:21:09
|
Revision: 1118 Author: ian_lewis Date: 2006-08-07 21:20:55 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1118&view=rev Log Message: ----------- Added undo for changing node names, values, and prefixes Modified Paths: -------------- trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java trunk/jsxe/src/net/sourceforge/jsxe/dom/XMLDocument.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveEdit.java trunk/jsxe/src/net/sourceforge/jsxe/gui/TabbedView.java Added Paths: ----------- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-08 02:53:51 UTC (rev 1117) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-08 04:20:55 UTC (rev 1118) @@ -26,16 +26,12 @@ package net.sourceforge.jsxe.dom; //{{{ imports -/* -All classes are listed explicitly so -it is easy to see which package it -belongs to. -*/ //{{{ jsXe classes import net.sourceforge.jsxe.jsXe; import net.sourceforge.jsxe.util.Log; import net.sourceforge.jsxe.util.MiscUtilities; +import net.sourceforge.jsxe.dom.undo.*; import net.sourceforge.jsxe.dom.completion.*; //}}} @@ -281,8 +277,9 @@ * NAMESPACE_ERR: Raised if the specified prefix is malformed per the Namespaces in XML specification, if the namespaceURI of this node is null, if the specified prefix is "xml" and the namespaceURI of this node is different from "http://www.w3.org/XML/1998/namespace", if this node is an attribute and the specified prefix is "xmlns" and the namespaceURI of this node is different from " http://www.w3.org/2000/xmlns/", or if this node is an attribute and the qualifiedName of this node is "xmlns" . */ public void setNSPrefix(String prefix) throws DOMException { + String oldPrefix = getNSPrefix(); m_domNode.setPrefix(prefix); - fireNamespaceChanged(this); + fireNamespaceChanged(this, oldPrefix, prefix); }//}}} //{{{ getNodeName() @@ -317,10 +314,10 @@ } if (!MiscUtilities.equals(oldPrefix, prefix)) { - fireNamespaceChanged(this); + fireNamespaceChanged(this, oldPrefix, prefix); } if (!MiscUtilities.equals(oldLocalName, localName)) { - fireLocalNameChanged(this); + fireLocalNameChanged(this, oldLocalName, localName); } }//}}} @@ -345,11 +342,12 @@ if (m_domNode.getNodeType() == Node.ELEMENT_NODE) { //Verify that this really is a change - if (!m_domNode.getLocalName().equals(localName)) { + String oldLocalName = m_domNode.getLocalName(); + if (!oldLocalName.equals(localName)) { renameElementNode(getNSPrefix(), localName); - fireLocalNameChanged(this); + fireLocalNameChanged(this, oldLocalName, localName); } } else { if (m_domNode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { @@ -398,8 +396,9 @@ public void setNodeValue(String str) throws DOMException { // Make sure there is a change. if (str != null && !str.equals(m_domNode.getNodeValue())) { + String oldValue = getNodeValue(); m_domNode.setNodeValue(str); - fireNodeValueChanged(this); + fireNodeValueChanged(this, oldValue, str); } }//}}} @@ -965,7 +964,9 @@ }//}}} //{{{ fireLocalNameChanged() - private void fireLocalNameChanged(AdapterNode source) { + private void fireLocalNameChanged(AdapterNode source, String oldValue, String newValue) { + getOwnerDocument().addUndoableEdit(new NodeNameChange(this, oldValue, newValue)); + ListIterator iterator = m_listeners.listIterator(); while (iterator.hasNext()) { AdapterNodeListener listener = (AdapterNodeListener)iterator.next(); @@ -975,7 +976,9 @@ }//}}} //{{{ fireNamespaceChanged() - private void fireNamespaceChanged(AdapterNode source) { + private void fireNamespaceChanged(AdapterNode source, String oldValue, String newValue) { + getOwnerDocument().addUndoableEdit(new NodePrefixChange(this, oldValue, newValue)); + ListIterator iterator = m_listeners.listIterator(); while (iterator.hasNext()) { AdapterNodeListener listener = (AdapterNodeListener)iterator.next(); @@ -985,7 +988,10 @@ }//}}} //{{{ fireNodeValueChanged() - private void fireNodeValueChanged(AdapterNode source) { + private void fireNodeValueChanged(AdapterNode source, String oldValue, String newValue) { + + getOwnerDocument().addUndoableEdit(new NodeValueChange(this, oldValue, newValue)); + ListIterator iterator = m_listeners.listIterator(); while (iterator.hasNext()) { AdapterNodeListener listener = (AdapterNodeListener)iterator.next(); Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/XMLDocument.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-08-08 02:53:51 UTC (rev 1117) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/XMLDocument.java 2006-08-08 04:20:55 UTC (rev 1118) @@ -198,19 +198,19 @@ //{{{ addUndoableEdit() /** - * Allows views and editors to add additional undoable events. Generally - * the edits added by classes that are not this class, classes in this - * package, or a subclass will not be significant. - * + * Allows subclasses to add additional undoable events. * @return true if the edit was added successfully */ - public boolean addUndoableEdit(UndoableEdit edit) { - if (insideCompoundEdit()) { - m_addedToCompoundEdits = true; - return ((CompoundEdit)m_compoundEdits.peek()).addEdit(edit); - } else { - return m_undoManager.addEdit(edit); + protected boolean addUndoableEdit(UndoableEdit edit) { + if (!getFlag(UNDO_IN_PROGRESS)) { + if (insideCompoundEdit()) { + m_addedToCompoundEdits = true; + return ((CompoundEdit)m_compoundEdits.peek()).addEdit(edit); + } else { + return m_undoManager.addEdit(edit); + } } + return false; }//}}} //{{{ beginCompoundEdit() @@ -235,10 +235,11 @@ return; } Log.log(Log.DEBUG, this, "end compound edit"); + CompoundEdit edit = (CompoundEdit)m_compoundEdits.pop(); + edit.end(); if (m_addedToCompoundEdits) { - CompoundEdit edit = (CompoundEdit)m_compoundEdits.pop(); - edit.end(); m_undoManager.addEdit(edit); + m_addedToCompoundEdits = false; } }//}}} @@ -285,6 +286,14 @@ } }//}}} + //{{{ clearUndo() + /** + * Clears all edits from the undo manager. + */ + public void clearUndo() { + m_undoManager.discardAllEdits(); + }//}}} + //}}} //{{{ Property methods Added: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java (rev 0) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java 2006-08-08 04:20:55 UTC (rev 1118) @@ -0,0 +1,86 @@ +/* +NodeNameChange.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package net.sourceforge.jsxe.dom.undo; + +//{{{ imports + +//{{{ jsXe classes +import net.sourceforge.jsxe.dom.AdapterNode; +import net.sourceforge.jsxe.util.Log; +//}}} + +//{{{ Swing classes +import javax.swing.undo.*; +//}}} + +//{{{ DOM classes +import org.w3c.dom.DOMException; +//}}} + +//}}} + +/** + * An undoable edit sigifying a change of an AdapterNode's local name. + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + * @see net.sourceforge.jsxe.dom.XMLDocument + * @see net.sourceforge.jsxe.dom.AdapterNode + */ +public class NodeNameChange extends AbstractUndoableEdit { + + AdapterNode m_node; + String m_oldValue; + String m_newValue; + + //{{{ NodeNameChange constructor + public NodeNameChange(AdapterNode node, String oldValue, String newValue) { + m_node = node; + m_oldValue = oldValue; + m_newValue = newValue; + }//}}} + + //{{{ undo() + + public void undo() throws CannotUndoException { + super.undo(); + try { + m_node.setNodeName(m_oldValue); + } catch (DOMException ioe) { + throw new CannotUndoException(); + } + }//}}} + + //{{{ redo() + + public void redo() throws CannotRedoException { + super.redo(); + try { + m_node.setNodeName(m_newValue); + } catch (DOMException ioe) { + throw new CannotRedoException(); + } + }//}}} + +} \ No newline at end of file Property changes on: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeNameChange.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java (rev 0) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java 2006-08-08 04:20:55 UTC (rev 1118) @@ -0,0 +1,86 @@ +/* +NodePrefixChange.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package net.sourceforge.jsxe.dom.undo; + +//{{{ imports + +//{{{ jsXe classes +import net.sourceforge.jsxe.dom.AdapterNode; +import net.sourceforge.jsxe.util.Log; +//}}} + +//{{{ Swing classes +import javax.swing.undo.*; +//}}} + +//{{{ DOM classes +import org.w3c.dom.DOMException; +//}}} + +//}}} + +/** + * An undoable edit sigifying a change of an AdapterNode's namespace prefix. + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + * @see net.sourceforge.jsxe.dom.XMLDocument + * @see net.sourceforge.jsxe.dom.AdapterNode + */ +public class NodePrefixChange extends AbstractUndoableEdit { + + AdapterNode m_node; + String m_oldValue; + String m_newValue; + + //{{{ NodePrefixChange constructor + public NodePrefixChange(AdapterNode node, String oldValue, String newValue) { + m_node = node; + m_oldValue = oldValue; + m_newValue = newValue; + }//}}} + + //{{{ undo() + + public void undo() throws CannotUndoException { + super.undo(); + try { + m_node.setNSPrefix(m_oldValue); + } catch (DOMException ioe) { + throw new CannotUndoException(); + } + }//}}} + + //{{{ redo() + + public void redo() throws CannotRedoException { + super.redo(); + try { + m_node.setNSPrefix(m_newValue); + } catch (DOMException ioe) { + throw new CannotRedoException(); + } + }//}}} + +} \ No newline at end of file Property changes on: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodePrefixChange.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java (rev 0) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java 2006-08-08 04:20:55 UTC (rev 1118) @@ -0,0 +1,86 @@ +/* +NodeValueChange.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package net.sourceforge.jsxe.dom.undo; + +//{{{ imports + +//{{{ jsXe classes +import net.sourceforge.jsxe.dom.AdapterNode; +import net.sourceforge.jsxe.util.Log; +//}}} + +//{{{ Swing classes +import javax.swing.undo.*; +//}}} + +//{{{ DOM classes +import org.w3c.dom.DOMException; +//}}} + +//}}} + +/** + * An undoable edit sigifying a change of an AdapterNode's value. + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + * @see net.sourceforge.jsxe.dom.XMLDocument + * @see net.sourceforge.jsxe.dom.AdapterNode + */ +public class NodeValueChange extends AbstractUndoableEdit { + + AdapterNode m_node; + String m_oldValue; + String m_newValue; + + //{{{ NodeValueChange constructor + public NodeValueChange(AdapterNode node, String oldValue, String newValue) { + m_node = node; + m_oldValue = oldValue; + m_newValue = newValue; + }//}}} + + //{{{ undo() + + public void undo() throws CannotUndoException { + super.undo(); + try { + m_node.setNodeValue(m_oldValue); + } catch (DOMException ioe) { + throw new CannotUndoException(); + } + }//}}} + + //{{{ redo() + + public void redo() throws CannotRedoException { + super.redo(); + try { + m_node.setNodeValue(m_newValue); + } catch (DOMException ioe) { + throw new CannotRedoException(); + } + }//}}} + +} \ No newline at end of file Property changes on: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/NodeValueChange.java ___________________________________________________________________ Name: svn:executable + * Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveEdit.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveEdit.java 2006-08-08 02:53:51 UTC (rev 1117) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveEdit.java 2006-08-08 04:20:55 UTC (rev 1118) @@ -77,7 +77,7 @@ try { m_document.removeText(m_offset, m_text.length()); } catch (IOException ioe) { - throw new CannotUndoException(); + throw new CannotRedoException(); } }//}}} Modified: trunk/jsxe/src/net/sourceforge/jsxe/gui/TabbedView.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/gui/TabbedView.java 2006-08-08 02:53:51 UTC (rev 1117) +++ trunk/jsxe/src/net/sourceforge/jsxe/gui/TabbedView.java 2006-08-08 04:20:55 UTC (rev 1118) @@ -788,6 +788,7 @@ DocumentBuffer buffer = getDocumentBuffer(); try { + buffer.clearUndo(); // clear undo since it's view specific DocumentView view = m_view.newDocumentView(buffer); setDocumentView(view); } catch (IOException ioe) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |