[Jsxe-cvs] SF.net SVN: jsxe: [1129] trunk/jsxe/src/net/sourceforge/jsxe/dom
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-08-09 21:53:17
|
Revision: 1129 Author: ian_lewis Date: 2006-08-09 14:53:09 -0700 (Wed, 09 Aug 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1129&view=rev Log Message: ----------- Added back undo for adding and removing nodes from the tree Modified Paths: -------------- trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java Added Paths: ----------- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java Modified: trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-09 21:51:10 UTC (rev 1128) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/AdapterNode.java 2006-08-09 21:53:09 UTC (rev 1129) @@ -541,7 +541,7 @@ } int index = index(node); m_children.remove(node); - // addUndoableEdit(new RemoveNodeChange(this, node, index)); + addUndoableEdit(new RemoveNodeChange(this, node, index)); } else { //Remove from previous parent AdapterNode previousParent = node.getParentNode(); @@ -942,9 +942,9 @@ if (node != null) { int index = index(node); m_children.remove(node); - // if (index != -1) { - // addUndoableEdit(new RemoveNodeChange(this, node, index)); - // } + if (index != -1) { + addUndoableEdit(new RemoveNodeChange(this, node, index)); + } } }//}}} @@ -994,7 +994,7 @@ //{{{ fireNodeAdded() private void fireNodeAdded(AdapterNode source, AdapterNode child, int index) { - // addUndoableEdit(new AddNodeChange(source, child, index)); + addUndoableEdit(new AddNodeChange(source, child, index)); ListIterator iterator = m_listeners.listIterator(); while (iterator.hasNext()) { @@ -1006,7 +1006,7 @@ //{{{ fireNodeRemoved() private void fireNodeRemoved(AdapterNode source, AdapterNode child, int index) { - // addUndoableEdit(new RemoveNodeChange(source, child, index)); + addUndoableEdit(new RemoveNodeChange(source, child, index)); ListIterator iterator = m_listeners.listIterator(); while (iterator.hasNext()) { Added: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java (rev 0) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java 2006-08-09 21:53:09 UTC (rev 1129) @@ -0,0 +1,90 @@ +/* +AddNodeChange.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 an addition of a child to an AdapterNode. + * @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 AddNodeChange extends AbstractUndoableEdit { + + private AdapterNode m_node; + private AdapterNode m_child; + private int m_index; + + //{{{ AddNodeChange constructor + public AddNodeChange(AdapterNode node, AdapterNode child, int index) { + m_node = node; + m_child = child; + m_index = index; + }//}}} + + //{{{ undo() + + public void undo() throws CannotUndoException { + super.undo(); + try { + Log.log(Log.DEBUG, this, "undo()"); + m_node.remove(m_child); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); + throw new CannotUndoException(); + } + }//}}} + + //{{{ redo() + + public void redo() throws CannotRedoException { + super.redo(); + try { + Log.log(Log.DEBUG, this, "redo()"); + m_node.addAdapterNodeAt(m_child, m_index); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); + throw new CannotRedoException(); + } + }//}}} + +} \ No newline at end of file Property changes on: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AddNodeChange.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java (rev 0) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java 2006-08-09 21:53:09 UTC (rev 1129) @@ -0,0 +1,90 @@ +/* +RemoveNodeChange.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 removal of a child from an AdapterNode. + * @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 RemoveNodeChange extends AbstractUndoableEdit { + + private AdapterNode m_node; + private AdapterNode m_child; + private int m_index; + + //{{{ RemoveNodeChange constructor + public RemoveNodeChange(AdapterNode node, AdapterNode child, int index) { + m_node = node; + m_child = child; + m_index = index; + }//}}} + + //{{{ undo() + + public void undo() throws CannotUndoException { + super.undo(); + try { + Log.log(Log.DEBUG, this, "undo()"); + m_node.addAdapterNodeAt(m_child, m_index); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); + throw new CannotUndoException(); + } + }//}}} + + //{{{ redo() + + public void redo() throws CannotRedoException { + super.redo(); + try { + Log.log(Log.DEBUG, this, "redo()"); + m_node.remove(m_child); + } catch (DOMException e) { + Log.log(Log.ERROR, this, e); + throw new CannotRedoException(); + } + }//}}} + +} \ No newline at end of file Property changes on: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/RemoveNodeChange.java ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |