[Jsxe-cvs] SF.net SVN: jsxe: [1123] trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AttributeChange.ja
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-08-08 20:15:30
|
Revision: 1123 Author: ian_lewis Date: 2006-08-08 13:15:25 -0700 (Tue, 08 Aug 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1123&view=rev Log Message: ----------- Added undo/redo support for attributes Added Paths: ----------- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AttributeChange.java Added: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AttributeChange.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AttributeChange.java (rev 0) +++ trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AttributeChange.java 2006-08-08 20:15:25 UTC (rev 1123) @@ -0,0 +1,106 @@ +/* +AttributeChange.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; +//}}} + +//{{{ Swing classes +import javax.swing.undo.*; +//}}} + +//{{{ DOM classes +import org.w3c.dom.DOMException; +//}}} + +//}}} + +/** + * An undoable edit sigifying a change to an attribute into an element + * 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 AttributeChange extends AbstractUndoableEdit { + + private AdapterNode m_node; + private String m_name; + private String m_oldValue; + private String m_newValue; + + //{{{ AttributeChange constructor + /** + * @param name The qualified name of the attribute. + * @param oldValue The old value of the attribute. If null then the attribute was added. + * @param newValue The new value of the attribute. If null then the attribute was removed + */ + public AttributeChange(AdapterNode node, String name, String oldValue, String newValue) { + m_node = node; + m_name = name; + m_oldValue = oldValue; + m_newValue = newValue; + }//}}} + + //{{{ undo() + + public void undo() throws CannotUndoException { + super.undo(); + try { + if (m_oldValue != null) { + m_node.setAttribute(m_name, m_oldValue); + } else { + //if the old value is null then the attribute was added. + //we need to remove it here. + m_node.removeAttribute(m_name); + } + } catch (DOMException e) { + throw new CannotUndoException(); + } + }//}}} + + //{{{ redo() + + public void redo() throws CannotRedoException { + super.redo(); + try { + if (m_newValue != null) { + m_node.setAttribute(m_name, m_newValue); + } else { + //if the new value is null then the attribute was removed + //we need to remove it here. + m_node.removeAttribute(m_name); + } + } catch (DOMException e) { + throw new CannotRedoException(); + } + }//}}} + +} \ No newline at end of file Property changes on: trunk/jsxe/src/net/sourceforge/jsxe/dom/undo/AttributeChange.java ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |