ZoomStateStack.cs
5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//============================================================================
//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 ZedGraph
{
/// <summary>
/// A LIFO stack of prior <see cref="ZoomState"/> objects, used to allow zooming out to prior
/// states (of scale range settings).
/// </summary>
/// <author> John Champion </author>
/// <version> $Revision: 3.1 $ $Date: 2006/06/24 20:26:44 $ </version>
public class ZoomStateStack : List<ZoomState>, ICloneable
{
/// <summary>
/// Default Constructor
/// </summary>
public ZoomStateStack()
{
}
/// <summary>
/// The Copy Constructor
/// </summary>
/// <param name="rhs">The <see cref="ZoomStateStack"/> object from which to copy</param>
public ZoomStateStack( ZoomStateStack rhs )
{
foreach ( ZoomState state in rhs )
{
Add( new ZoomState( state ) );
}
}
/// <summary>
/// Implement the <see cref="ICloneable" /> interface in a typesafe manner by just
/// calling the typed version of <see cref="Clone" />
/// </summary>
/// <returns>A deep copy of this object</returns>
object ICloneable.Clone()
{
return this.Clone();
}
/// <summary>
/// Typesafe, deep-copy clone method.
/// </summary>
/// <returns>A new, independent copy of this class</returns>
public ZoomStateStack Clone()
{
return new ZoomStateStack( this );
}
/// <summary>
/// Public readonly property that indicates if the stack is empty
/// </summary>
/// <value>true for an empty stack, false otherwise</value>
public bool IsEmpty
{
get { return this.Count == 0; }
}
/// <summary>
/// Add the scale range information from the specified <see cref="GraphPane"/> object as a
/// new <see cref="ZoomState"/> entry on the stack.
/// </summary>
/// <param name="pane">The <see cref="GraphPane"/> object from which the scale range
/// information should be copied.</param>
/// <param name="type">A <see cref="ZoomState.StateType"/> enumeration that indicates whether this
/// state is the result of a zoom or pan operation.</param>
/// <returns>The resultant <see cref="ZoomState"/> object that was pushed on the stack.</returns>
public ZoomState Push( GraphPane pane, ZoomState.StateType type )
{
ZoomState state = new ZoomState( pane, type );
this.Add( state );
return state;
}
/// <summary>
/// Add the scale range information from the specified <see cref="ZoomState"/> object as a
/// new <see cref="ZoomState"/> entry on the stack.
/// </summary>
/// <param name="state">The <see cref="ZoomState"/> object to be placed on the stack.</param>
/// <returns>The <see cref="ZoomState"/> object (same as the <see paramref="state"/>
/// parameter).</returns>
public ZoomState Push( ZoomState state )
{
this.Add( state );
return state;
}
/// <summary>
/// Pop a <see cref="ZoomState"/> entry from the top of the stack, and apply the properties
/// to the specified <see cref="GraphPane"/> object.
/// </summary>
/// <param name="pane">The <see cref="GraphPane"/> object to which the scale range
/// information should be copied.</param>
/// <returns>The <see cref="ZoomState"/> object that was "popped" from the stack and applied
/// to the specified <see cref="GraphPane"/>. null if no <see cref="ZoomState"/> was
/// available (the stack was empty).</returns>
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;
}
/// <summary>
/// Pop the <see cref="ZoomState"/> entry from the bottom of the stack, and apply the properties
/// to the specified <see cref="GraphPane"/> object. Clear the stack completely.
/// </summary>
/// <param name="pane">The <see cref="GraphPane"/> object to which the scale range
/// information should be copied.</param>
/// <returns>The <see cref="ZoomState"/> object at the bottom of the stack that was applied
/// to the specified <see cref="GraphPane"/>. null if no <see cref="ZoomState"/> was
/// available (the stack was empty).</returns>
public ZoomState PopAll( GraphPane pane )
{
if ( !this.IsEmpty )
{
ZoomState state = (ZoomState) this[ 0 ];
this.Clear();
state.ApplyState( pane );
return state;
}
else
return null;
}
/// <summary>
/// Gets a reference to the <see cref="ZoomState"/> object at the top of the stack,
/// without actually removing it from the stack.
/// </summary>
/// <value>A <see cref="ZoomState"/> object reference, or null if the stack is empty.</value>
public ZoomState Top
{
get
{
if ( !this.IsEmpty )
return (ZoomState) this[ this.Count - 1 ];
else
return null;
}
}
}
}