Selection.cs
8.2 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
//============================================================================
//ZedGraph Class Library - A Flexible Line Graph/Bar Graph Library in C#
//Copyright ?2007 John Champion and JCarpenter
//
//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
//=============================================================================
using System;
using System.Drawing;
using System.Collections;
namespace ZedGraph
{
/// <summary>
/// </summary>
/// <remarks>
/// </remarks>
///
/// <author> John Champion and JCarpenter </author>
/// <version> $Revision: 3.5 $ $Date: 2007/03/11 02:08:16 $ </version>
public class Selection : CurveList
{
// Revision: JCarpenter 10/06
/// <summary>
/// Subscribe to this event to receive notice
/// that the list of selected CurveItems has changed
/// </summary>
public event EventHandler SelectionChangedEvent;
#region static properties
/// <summary>
/// The <see cref="Border" /> type to be used for drawing "selected"
/// <see cref="PieItem" />, <see cref="BarItem" />, <see cref="HiLowBarItem" />,
/// <see cref="OHLCBarItem" />, and <see cref="JapaneseCandleStickItem" /> item types.
/// </summary>
public static Border Border = new Border( Color.Gray, 1.0f );
/// <summary>
/// The <see cref="Fill" /> type to be used for drawing "selected"
/// <see cref="PieItem" />, <see cref="BarItem" />, <see cref="HiLowBarItem" />,
/// and <see cref="JapaneseCandleStickItem" /> item types.
/// </summary>
public static Fill Fill = new Fill( Color.Gray );
/// <summary>
/// The <see cref="Line" /> type to be used for drawing "selected"
/// <see cref="LineItem" /> and <see cref="StickItem" /> types
/// </summary>
public static Line Line = new Line( Color.Gray );
// public static ErrorBar ErrorBar = new ErrorBar( Color.Gray );
/// <summary>
/// The <see cref="Symbol" /> type to be used for drawing "selected"
/// <see cref="LineItem" /> and <see cref="ErrorBarItem" /> types.
/// </summary>
public static Symbol Symbol = new Symbol( SymbolType.Circle, Color.Gray );
//public static Color SelectedSymbolColor = Color.Gray;
#endregion
#region Methods
/// <summary>
/// Place a <see cref="CurveItem" /> in the selection list, removing all other
/// items.
/// </summary>
/// <param name="master">The <see cref="MasterPane" /> that is the "owner"
/// of the <see cref="CurveItem" />'s.</param>
/// <param name="ci">The <see cref="CurveItem" /> to be added to the list.</param>
public void Select( MasterPane master, CurveItem ci )
{
//Clear the selection, but don't send the event,
//the event will be sent in "AddToSelection" by calling "UpdateSelection"
ClearSelection( master, false );
AddToSelection( master, ci );
}
/// <summary>
/// Place a list of <see cref="CurveItem" />'s in the selection list, removing all other
/// items.
/// </summary>
/// <param name="master">The <see cref="MasterPane" /> that is the "owner"
/// of the <see cref="CurveItem" />'s.</param>
/// <param name="ciList">The list of <see cref="CurveItem" /> to be added to the list.</param>
public void Select( MasterPane master, CurveList ciList )
{
//Clear the selection, but don't send the event,
//the event will be sent in "AddToSelection" by calling "UpdateSelection"
ClearSelection( master, false );
AddToSelection( master, ciList );
}
/// <summary>
/// Add a <see cref="CurveItem" /> to the selection list.
/// </summary>
/// <param name="master">The <see cref="MasterPane" /> that is the "owner"
/// of the <see cref="CurveItem" />'s.</param>
/// <param name="ci">The <see cref="CurveItem" /> to be added to the list.</param>
public void AddToSelection( MasterPane master, CurveItem ci )
{
if ( this.Contains( ci ) == false )
Add( ci );
UpdateSelection( master );
}
/// <summary>
/// Add a list of <see cref="CurveItem" />'s to the selection list.
/// </summary>
/// <param name="master">The <see cref="MasterPane" /> that is the "owner"
/// of the <see cref="CurveItem" />'s.</param>
/// <param name="ciList">The list of <see cref="CurveItem" />'s to be added to the list.</param>
public void AddToSelection( MasterPane master, CurveList ciList )
{
foreach ( CurveItem ci in ciList )
{
if ( this.Contains( ci ) == false )
this.Add( ci );
}
UpdateSelection( master );
}
#if ( DOTNET1 )
// Define a "Contains" method so that this class works with .Net 1.1 or 2.0
internal bool Contains( CurveItem item )
{
foreach ( CurveItem ci in this )
if ( item == ci )
return true;
return false;
}
#endif
/// <summary>
/// Remove the specified <see cref="CurveItem" /> from the selection list.
/// </summary>
/// <param name="master">The <see cref="MasterPane" /> that is the "owner"
/// of the <see cref="CurveItem" />'s.</param>
/// <param name="ci">The <see cref="CurveItem" /> to be removed from the list.</param>
public void RemoveFromSelection( MasterPane master, CurveItem ci )
{
if ( this.Contains( ci ) )
this.Remove( ci );
UpdateSelection( master );
}
/// <summary>
/// Clear the selection list and trigger a <see cref="SelectionChangedEvent" />.
/// </summary>
/// <param name="master">The <see cref="MasterPane" /> that "owns" the selection list.</param>
public void ClearSelection( MasterPane master )
{
ClearSelection( master, true );
}
/// <summary>
/// Clear the selection list and optionally trigger a <see cref="SelectionChangedEvent" />.
/// </summary>
/// <param name="master">The <see cref="MasterPane" /> that "owns" the selection list.</param>
/// <param name="sendEvent">true to trigger a <see cref="SelectionChangedEvent" />,
/// false otherwise.</param>
public void ClearSelection( MasterPane master, bool sendEvent )
{
this.Clear();
foreach ( GraphPane pane in master.PaneList )
{
foreach ( CurveItem ci in pane.CurveList )
{
ci.IsSelected = false;
}
}
if ( sendEvent )
{
if ( SelectionChangedEvent != null )
SelectionChangedEvent( this, new EventArgs() );
}
}
/// <summary>
/// Mark the <see cref="CurveItem" />'s that are included in the selection list
/// by setting the <see cref="CurveItem.IsSelected" /> property to true.
/// </summary>
/// <param name="master">The <see cref="MasterPane" /> that "owns" the selection list.</param>
public void UpdateSelection( MasterPane master )
{
if ( Count <= 0 )
{
ClearSelection( master );
return;
}
foreach ( GraphPane pane in master.PaneList )
{
foreach ( CurveItem ci in pane.CurveList )
{
//Make it Inactive
ci.IsSelected = false;
}
}
foreach ( CurveItem ci in this )
{
//Make Active
ci.IsSelected = true;
//If it is a line / scatterplot, the selected Curve may be occluded by an unselected Curve
//So, move it to the top of the ZOrder by removing it, and re-adding it.
//Why only do this for Lines? ...Bar and Pie Curves are less likely to overlap,
//and adding and removing Pie elements changes thier display order
if ( ci.IsLine )
{
//I don't know how to get a Pane, from a CurveItem, so I can only do it
//if there is one and only one Pane, based on the assumption that the
//Curve's Pane is MasterPane[0]
//If there is only one Pane
if ( master.PaneList.Count == 1 )
{
GraphPane pane = master.PaneList[0];
pane.CurveList.Remove( ci );
pane.CurveList.Insert( 0, ci );
}
}
}
//Send Selection Changed Event
if ( SelectionChangedEvent != null )
SelectionChangedEvent( this, new EventArgs() );
}
#endregion
}
}