//============================================================================
//ZedGraph Class Library - A Flexible Line Graph/Bar Graph Library in C#
//Copyright ?2004  John Champion
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//This library 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
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//=============================================================================
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
#endregion
namespace DrawGraph
{
	/// 
	/// A LIFO stack of prior  objects, used to allow zooming out to prior
	/// states (of scale range settings).
	/// 
	///  John Champion 
	///  $Revision: 3.1 $ $Date: 2006/06/24 20:26:44 $ 
	public class ZoomStateStack : List, ICloneable
	{
		/// 
		/// Default Constructor
		/// 
		public ZoomStateStack()
		{
		}
		/// 
		/// The Copy Constructor
		/// 
		/// The  object from which to copy
		public ZoomStateStack( ZoomStateStack rhs )
		{
			foreach ( ZoomState state in rhs )
			{
				Add( new ZoomState( state ) );
			}
		}
		/// 
		/// Implement the  interface in a typesafe manner by just
		/// calling the typed version of 
		/// 
		/// A deep copy of this object
		object ICloneable.Clone()
		{
			return this.Clone();
		}
		/// 
		/// Typesafe, deep-copy clone method.
		/// 
		/// A new, independent copy of this class
		public ZoomStateStack Clone()
		{
			return new ZoomStateStack( this );
		}
		/// 
		/// Public readonly property that indicates if the stack is empty
		/// 
		/// true for an empty stack, false otherwise
		public bool IsEmpty
		{
			get { return this.Count == 0; }
		}
		/// 
		/// Add the scale range information from the specified  object as a
		/// new  entry on the stack.
		/// 
		/// The  object from which the scale range
		/// information should be copied.
		/// A  enumeration that indicates whether this
		/// state is the result of a zoom or pan operation.
		/// The resultant  object that was pushed on the stack.
		public ZoomState Push( GraphPane pane, ZoomState.StateType type )
		{
			ZoomState state = new ZoomState( pane, type );
			this.Add( state );
			return state;
		}
		/// 
		/// Add the scale range information from the specified  object as a
		/// new  entry on the stack.
		/// 
		/// The  object to be placed on the stack.
		/// The  object (same as the 
		/// parameter).
		public ZoomState Push( ZoomState state )
		{
			this.Add( state );
			return state;
		}
		/// 
		/// Pop a  entry from the top of the stack, and apply the properties
		/// to the specified  object.
		/// 
		/// The  object to which the scale range
		/// information should be copied.
		/// The  object that was "popped" from the stack and applied
		/// to the specified .  null if no  was
		/// available (the stack was empty).
		public ZoomState Pop( GraphPane pane )
		{
			if ( !this.IsEmpty )
			{
				ZoomState state = (ZoomState) this[ this.Count - 1 ];
				this.RemoveAt( this.Count - 1 );
				state.ApplyState( pane );
				return state;
			}
			else
				return null;
		}
		/// 
		/// Pop the  entry from the bottom of the stack, and apply the properties
		/// to the specified  object.  Clear the stack completely.
		/// 
		/// The  object to which the scale range
		/// information should be copied.
		/// The  object at the bottom of the stack that was applied
		/// to the specified .  null if no  was
		/// available (the stack was empty).
		public ZoomState PopAll( GraphPane pane )
		{
			if ( !this.IsEmpty )
			{
				ZoomState state = (ZoomState) this[ 0 ];
				this.Clear();
				state.ApplyState( pane );
				return state;
			}
			else
				return null;
		}
		/// 
		/// Gets a reference to the  object at the top of the stack,
		/// without actually removing it from the stack.
		/// 
		/// A  object reference, or null if the stack is empty.
		public ZoomState Top
		{
			get
			{
				if ( !this.IsEmpty )
					return (ZoomState) this[ this.Count - 1 ];
				else
					return null;
			}
		}
	}
}