//----------------------------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 javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.undo.UndoableEdit;

import org.huihoo.god4j.GOD4JFactory;
import org.huihoo.god4j.jgraph.XPDLJGraph;
/**
 * @author roger
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class XPDLJGraphUndoableListener implements UndoableEditListener
{
	private boolean addEdits = true;
	private XPDLJGraph graph;
	
	public XPDLJGraphUndoableListener(XPDLJGraph graph, boolean addEdits)
	{
		this.addEdits = addEdits;
		this.graph = graph;
	}
	
	public void setAddEdits(boolean addEdits)
	{
		this.addEdits=addEdits;
	}
	
	public boolean getAddEdits()
	{
		return addEdits;
	}
		
	/**
	 * Messaged when the Document has created an edit, the edit is
				 * added to <code>undoMgr</code>, an instance of UndoManager.
	 */
	public void undoableEditHappened(UndoableEditEvent e)
	{
		UndoableEdit ue = e.getEdit();
		if (addEdits)
		{
			graph.getUndoManager().addEdit(ue);
			GOD4JFactory.getGOD4J().getActionMap().getAction("undo").update();
			GOD4JFactory.getGOD4J().getActionMap().getAction("redo").update();
		}
	}
}
