-
Notifications
You must be signed in to change notification settings - Fork 2
/
CollectionPropertyGrid.cs
273 lines (236 loc) · 9.31 KB
/
CollectionPropertyGrid.cs
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// ********************************************************************************************************
// Product Name: DotSpatial.Symbology.Forms.dll
// Description: The core assembly for the DotSpatial 6.0 distribution.
// ********************************************************************************************************
// The contents of this file are subject to the MIT License (MIT)
// you may not use this file except in compliance with the License. You may obtain a copy of the License at
// http://dotspatial.codeplex.com/license
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
// ANY KIND, either expressed or implied. See the License for the specific language governing rights and
// limitations under the License.
//
// The Original Code is DotSpatial.dll
//
// The Initial Developer of this Original Code is Ted Dunsford. Created 4/30/2009 8:55:03 AM
//
// Contributor(s): (Open source contributors should list themselves and their modifications here).
//
// ********************************************************************************************************
using System;
using System.ComponentModel;
using System.Windows.Forms;
using DotSpatial.Data;
namespace DotSpatial.Symbology.Forms
{
/// <summary>
/// CollectionPropertyGrid
/// </summary>
public class CollectionPropertyGrid : Form
{
#region Events
/// <summary>
/// Occurs whenever the apply changes button is clicked, or else when the ok button is clicked.
/// </summary>
public event EventHandler ChangesApplied;
/// <summary>
/// Occurs whenever the add item is clicked. This is because the Collection Property Grid
/// doesn't necessarilly know how to create a default item. (An alternative would be
/// to send in a factory, but I think this will work just as well.)
/// </summary>
public event EventHandler AddItemClicked;
#endregion
private CollectionControl ccItems;
private DialogButtons dialogButtons1;
private Panel panel1;
private PropertyGrid propertyGrid1;
private SplitContainer splitContainer1;
#region Private Variables
/// <summary>
/// Required designer variable.
/// </summary>
private IContainer components = null;
#endregion
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CollectionPropertyGrid));
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.ccItems = new DotSpatial.Symbology.Forms.CollectionControl();
this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
this.panel1 = new System.Windows.Forms.Panel();
this.dialogButtons1 = new DotSpatial.Symbology.Forms.DialogButtons();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// splitContainer1
//
resources.ApplyResources(this.splitContainer1, "splitContainer1");
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
resources.ApplyResources(this.splitContainer1.Panel1, "splitContainer1.Panel1");
this.splitContainer1.Panel1.Controls.Add(this.ccItems);
//
// splitContainer1.Panel2
//
resources.ApplyResources(this.splitContainer1.Panel2, "splitContainer1.Panel2");
this.splitContainer1.Panel2.Controls.Add(this.propertyGrid1);
//
// ccItems
//
resources.ApplyResources(this.ccItems, "ccItems");
this.ccItems.Name = "ccItems";
this.ccItems.SelectedName = null;
this.ccItems.SelectedObject = null;
//
// propertyGrid1
//
resources.ApplyResources(this.propertyGrid1, "propertyGrid1");
this.propertyGrid1.Name = "propertyGrid1";
//
// panel1
//
resources.ApplyResources(this.panel1, "panel1");
this.panel1.Controls.Add(this.dialogButtons1);
this.panel1.Name = "panel1";
//
// dialogButtons1
//
resources.ApplyResources(this.dialogButtons1, "dialogButtons1");
this.dialogButtons1.Name = "dialogButtons1";
//
// CollectionPropertyGrid
//
resources.ApplyResources(this, "$this");
this.AllowDrop = true;
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.panel1);
this.Name = "CollectionPropertyGrid";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
#region Constructors
/// <summary>
/// Creates a new instance of CollectionPropertyGrid
/// </summary>
public CollectionPropertyGrid()
{
InitializeComponent();
Configure();
}
/// <summary>
/// Creates a new instance of CollectionPropertyGrid
/// </summary>
/// <param name="list">The INamedList to display</param>
public CollectionPropertyGrid(INamedList list)
{
InitializeComponent();
NamedList = list;
ccItems.AddClicked += ccItems_AddClicked;
ccItems.SelectedItemChanged += ccItems_SelectedItemChanged;
ccItems_SelectedItemChanged(ccItems, EventArgs.Empty);
ccItems.RemoveClicked += ccItems_RemoveClicked;
Configure();
}
private void Configure()
{
dialogButtons1.OkClicked += btnOk_Click;
dialogButtons1.CancelClicked += btnCancel_Click;
dialogButtons1.ApplyClicked += btnApply_Click;
}
private void ccItems_RemoveClicked(object sender, EventArgs e)
{
propertyGrid1.SelectedObject = ccItems.SelectedObject;
}
#endregion
#region Methods
#endregion
#region Properties
/// <summary>
/// Gets or sets the tool that connects each item with a string name.
/// </summary>
public INamedList NamedList
{
get
{
if (ccItems != null) return ccItems.ItemNames;
return null;
}
set
{
ccItems.ItemNames = value;
}
}
#endregion
#region Events
#endregion
#region Event Handlers
private void ccItems_AddClicked(object sender, EventArgs e)
{
OnAddClicked();
}
private void ccItems_SelectedItemChanged(object sender, EventArgs e)
{
propertyGrid1.SelectedObject = ccItems.SelectedObject;
}
private void btnApply_Click(object sender, EventArgs e)
{
OnApplyChanges();
}
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
private void btnOk_Click(object sender, EventArgs e)
{
OnApplyChanges();
Close();
}
#endregion
#region Protected Methods
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// Occurs when the add button is clicked
/// </summary>
protected virtual void OnAddClicked()
{
if (AddItemClicked != null) AddItemClicked(this, EventArgs.Empty);
}
/// <summary>
/// Fires the ChangesApplied event
/// </summary>
protected virtual void OnApplyChanges()
{
if (ChangesApplied != null) ChangesApplied(this, EventArgs.Empty);
}
#endregion
}
}