//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010 huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/god4j
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : god4j@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.god4j.jgraph.event;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoableEdit;

import org.huihoo.god4j.jgraph.XPDLJGraph;
import org.jgraph.graph.GraphUndoManager;

/**
 * ProcessEditor undo manager.
 */
public class XPDLJGraphUndoManager extends GraphUndoManager
{
	protected XPDLJGraph graph;
	
	public XPDLJGraphUndoManager(XPDLJGraph graph)
	{
		this.graph=graph;
	}
	
	/**
	 * Gets all edits.
	 */
	public Vector getEdits()
	{
		return edits;
	}
	/**
	 * Adds edits to the existing ones.
	 */
	public void addEdits(Vector e)
	{
		Iterator it = e.iterator();
		while (it.hasNext())
		{
			addEdit((UndoableEdit) it.next());
		}
	}
	/**
	 * Gets last edit.
	 */
	public UndoableEdit lastEdit()
	{
		return super.lastEdit();
	}
	/**
	 * Gets edit to be undone.
	 */
	protected UndoableEdit editToBeUndone()
	{
		return super.editToBeUndone();
	}
	/**
	 * Undoes all changes from indexOfNextAdd up to edit. Updates indexOfNextAdd accordingly.
	 */
	public void undoUpTo(UndoableEdit edit) throws CannotUndoException
	{
		boolean done = false;
		UndoableEdit next = null;
		while (!done)
		{
			next = nextEditToBeUndone(next);
			done = next == edit;
			if (!done)
			{
				undoTo(next);
			}
		}
	}
	/**
	 * Redoes all changes from indexOfNextAdd to edit. Updates indexOfNextAdd accordingly.
	 */
	public void redoUpTo(UndoableEdit edit) throws CannotRedoException
	{
		redoTo(edit);
	}
}