File: KeywordsRegistry.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (495 lines) | stat: -rw-r--r-- 15,363 bytes parent folder | download | duplicates (6)
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
//-------------------------------------------------------------
// <copyright company=Microsoft Corporation>
//   Copyright  Microsoft Corporation. All Rights Reserved.
// </copyright>
//-------------------------------------------------------------
// @owner=alexgor, deliant
//=================================================================
//  File:		KeywordsRegistry.cs
//
//  Namespace:	System.Web.UI.WebControls[Windows.Forms].Charting.Utilities
//
//	Classes:	KeywordsRegistry, KeywordInfo
//
//  Purpose:	A registry that keeps track of all available 
//				keywords and name of the objects and properties
//				where they can be used.
//
//  Formatting Keywords Overview:
//  -----------------------------
//  A Formatting Keyword is a specially formatted character sequence 
//  that gets replaced by an associated Chart Series value, or 
//  calculated value. Keywords can be used with most string properties 
//  of Series and DataPoint objects. 
//  
//  Here is an example of setting series labels so that the first 
//  line will display the Y value and the second line displays 
//  the X value. 
//      
//      Chart1.Series["Series1"].Label = "Y = #VALY\nX = #VALX";
//  
//  Series label in this case will look like this: 
//  
//  	Y = 45.78
//  	X = 456
//  
//  An optional format string can be added after the keyword. 
//  For example, when you set the Format option to Percent for 
//  the first Y value, the resulting keyword produced is "#VALY{P}".  
//  You can also apply format strings in code-behind using the same 
//  nomenclature; you do this by following the keyword with a format 
//  specifier enclosed in braces.  For information concerning the 
//  types of formatting that can be used, see the Formatting Types 
//  topic in the MSDN library.
//
//	Reviewed:	AG - Microsoft 5, 2007
//
//===================================================================


#region Used Namespaces

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;

#if Microsoft_CONTROL
    using System.Windows.Forms.DataVisualization.Charting;
    using System.Windows.Forms.DataVisualization.Charting.ChartTypes;
#else
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.DataVisualization.Charting.ChartTypes;
#endif

#endregion

#if Microsoft_CONTROL
    namespace System.Windows.Forms.DataVisualization.Charting.Utilities
#else // Microsoft_CONTROL
	namespace System.Web.UI.DataVisualization.Charting.Utilities
#endif // Microsoft_CONTROL
{
    /// <summary>
    /// KeywordName class contains constant strings defining
    /// names of all keywords used in the data point and series classes.
    /// </summary>
        internal static class KeywordName
        {
            #region Keyword Names

            internal const string Index = "#INDEX";
            internal const string ValX = "#VALX";
            internal const string ValY = "#VALY";
            internal const string Val = "#VAL";
            internal const string Total = "#TOTAL";
            internal const string Percent = "#PERCENT";
            internal const string Label = "#LABEL";
            internal const string AxisLabel = "#AXISLABEL";
            internal const string LegendText = "#LEGENDTEXT";
            internal const string SeriesName = "#SERIESNAME";
            internal const string Ser = "#SER";
            internal const string Avg = "#AVG";
            internal const string Max = "#MAX";
            internal const string Min = "#MIN";
            internal const string Last = "#LAST";
            internal const string First = "#FIRST";
            internal const string CustomProperty = "#CUSTOMPROPERTY";

            #endregion // Keyword Names
        }

	/// <summary>
    /// KeywordRegistry class stores information about all 
    /// chart formatting keywords. It automatically registers 
    /// all known keywords when object is constructed. This 
    /// data is exposed as ArrayList through the registeredKeywords 
    /// field. Each item in this ArrayList is a KeywordInfo 
    /// object which describes a single formatting keyword.
	/// </summary>
	internal class KeywordsRegistry : IServiceProvider
	{
		#region Fields

		// List of registered keywords
		internal	ArrayList		registeredKeywords = new ArrayList();

		#endregion

		#region Constructor and Services

		/// <summary>
		/// Keywords registry public constructor.
		/// </summary>
		public KeywordsRegistry()
		{
			// Register Keywords used in the chart
			RegisterKeywords();
		}

		/// <summary>
		/// Returns Keywords registry service object.
		/// </summary>
		/// <param name="serviceType">Service type to get.</param>
		/// <returns>Custom properties registry service.</returns>
		[EditorBrowsableAttribute(EditorBrowsableState.Never)]
		object IServiceProvider.GetService(Type serviceType)
		{
			if(serviceType == typeof(KeywordsRegistry))
			{
				return this;
			}
			throw (new ArgumentException( SR.ExceptionKeywordsRegistryUnsupportedType(serviceType.ToString())));
		}

		#endregion

		#region Keywords Registering methods

		/// <summary>
		/// Registers all chart formatting keywords.
		/// </summary>
		private void RegisterKeywords()
		{
            string seriesPointSupportedProperties = "Text,Label,LabelMapAreaAttributes,ToolTip,Url,LabelToolTip,MapAreaAttributes,AxisLabel,LegendToolTip,LegendMapAreaAttributes,LegendUrl,LegendText";

			// #INDEX keyword
			this.Register(
                SR.DescriptionKeyWordNameIndexDataPoint,
				KeywordName.Index,
				string.Empty,
                SR.DescriptionKeyWordIndexDataPoint2,
				"DataPoint",
				seriesPointSupportedProperties,
				false,
				false);

			// #VALX keyword
			this.Register(
                SR.DescriptionKeyWordNameXValue,
				KeywordName.ValX,
				string.Empty,
                SR.DescriptionKeyWordXValue,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				true,
				false);

			// #VALY keyword
			this.Register(
                SR.DescriptionKeyWordNameYValue,
				KeywordName.Val,
				string.Empty,
                SR.DescriptionKeyWordYValue,
				"Series,DataPoint,Annotation,LegendCellColumn,LegendCellColumn",
				seriesPointSupportedProperties,
				true,
				true);

			// #TOTAL keyword
			this.Register(
                SR.DescriptionKeyWordNameTotalYValues,
				KeywordName.Total,
				string.Empty,
                SR.DescriptionKeyWordTotalYValues,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				true,
				false);

			// #PERCENT keyword
			this.Register(
                SR.DescriptionKeyWordNameYValuePercentTotal,
				KeywordName.Percent,
				string.Empty,
                SR.DescriptionKeyWordYValuePercentTotal,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				true,
				true);

			// #INDEX keyword
			this.Register(
                SR.DescriptionKeyWordNameIndexTheDataPoint,
				KeywordName.Index,
				string.Empty,
                SR.DescriptionKeyWordIndexDataPoint,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				false,
				false);

			// #LABEL keyword
			this.Register(
                SR.DescriptionKeyWordNameLabelDataPoint,
				KeywordName.Label,
				string.Empty,
                SR.DescriptionKeyWordLabelDataPoint,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				false,
				false);

			// #AXISLABEL keyword
			this.Register(
                SR.DescriptionKeyWordNameAxisLabelDataPoint,
				KeywordName.AxisLabel,
				string.Empty,
                SR.DescriptionKeyWordAxisLabelDataPoint,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				false,
				false);

			// #LEGENDTEXT keyword
			this.Register(
                SR.DescriptionKeyWordNameLegendText,
				KeywordName.LegendText,
				string.Empty,
                SR.DescriptionKeyWordLegendText,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				false,
				false);

			// #SERIESNAME keyword
			this.Register(
                SR.DescriptionKeyWordNameSeriesName,
				KeywordName.SeriesName,
				KeywordName.Ser,
                SR.DescriptionKeyWordSeriesName,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				false,
				false);

			// *************** NEW KEYWORDS in version 5.5 ***************

			// #AVG keyword
			this.Register(
                SR.DescriptionKeyWordNameAverageYValues,
				KeywordName.Avg,
				string.Empty,
                SR.DescriptionKeyWordAverageYValues,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				true,
				true);

			// #MAX keyword
			this.Register(
                SR.DescriptionKeyWordNameMaximumYValues,
				KeywordName.Max,
				string.Empty,
                SR.DescriptionKeyWordMaximumYValues,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				true,
				true);

			// #MIN keyword
			this.Register(
                SR.DescriptionKeyWordNameMinimumYValues,
				KeywordName.Min,
				string.Empty,
                SR.DescriptionKeyWordMinimumYValues,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				true,
				true);

			// #LAST keyword
			this.Register(
                SR.DescriptionKeyWordNameLastPointYValue,
				KeywordName.Last,
				string.Empty,
                SR.DescriptionKeyWordLastPointYValue,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				true,
				true);

			// #FIRST keyword
			this.Register(
                SR.DescriptionKeyWordNameFirstPointYValue,
				KeywordName.First,
				string.Empty,
                SR.DescriptionKeyWordFirstPointYValue,
				"Series,DataPoint,Annotation,LegendCellColumn",
				seriesPointSupportedProperties,
				true,
				true);
		}

		#endregion // Keywords Registering methods

		#region Registry methods

        /// <summary>
        /// Adds keyword information into the registry.
        /// </summary>
        /// <param name="name">Keyword full name.</param>
        /// <param name="keyword">Keyword text.</param>
        /// <param name="keywordAliases">Keyword alternative text.</param>
        /// <param name="description">Keyword description.</param>
        /// <param name="appliesToTypes">Comma separated list of applicable classes</param>
        /// <param name="appliesToProperties">Comma separated list of applicable properties.</param>
        /// <param name="supportsFormatting">True if formatting is supported.</param>
        /// <param name="supportsValueIndex">True if different point Y values are supported.</param>
		public void Register(
			string name,
			string keyword,
			string keywordAliases,
			string description,
			string appliesToTypes,
			string appliesToProperties,
			bool supportsFormatting,
			bool supportsValueIndex)
		{
			// Create new keyword information object
			KeywordInfo keywordInfo = new KeywordInfo(
				name,
				keyword,
				keywordAliases,
				description,
				appliesToTypes,
				appliesToProperties,
				supportsFormatting,
				supportsValueIndex);

			// Add keyword information to the hash table
			registeredKeywords.Add(keywordInfo);
		}

		#endregion
	}

	/// <summary>
    /// KeywordInfo class stores information about a single 
    /// formatting keyword. This information includes Name, 
    /// Description, list of data types and properties it 
    /// applies to and other information.
	/// </summary>
    internal class KeywordInfo
	{
		#region Public Fields

		/// <summary>
		/// Keyword full name.
		/// </summary>
		public	string				Name = String.Empty;

		/// <summary>
		/// String that represent this keyword in the property (keyword).
		/// </summary>
		public	string				Keyword = String.Empty;

		/// <summary>
		/// Comma separated strings that may alternatively represent this 
		/// keyword in the property.
		/// </summary>
		public	string				KeywordAliases = String.Empty;

		/// <summary>
		/// Keyword description.
		/// </summary>
		public	string				Description = String.Empty;

		/// <summary>
		/// Comma separated names of classes this keyword applies to.
		/// </summary>
		public	string				AppliesToTypes = String.Empty;

		/// <summary>
		/// Comma separated names of properties this keyword applies to.
		/// </summary>
		public	string				AppliesToProperties = String.Empty;

		/// <summary>
		/// True if keyword value can be formatted.
		/// </summary>
		public	bool				SupportsFormatting = false;

		/// <summary>
		/// True if keyword can be used with different point Y values.
		/// </summary>
		public	bool				SupportsValueIndex = false;

		#endregion // Public Fields

		#region Constructor

        /// <summary>
        /// Keyword information object constructor
        /// </summary>
        /// <param name="name">Keyword full name.</param>
        /// <param name="keyword">Keyword text.</param>
        /// <param name="keywordAliases">Keyword alternative text.</param>
        /// <param name="description">Keyword description.</param>
        /// <param name="appliesToTypes">Comma separated list of applicable classes</param>
        /// <param name="appliesToProperties">Comma separated list of applicable properties.</param>
        /// <param name="supportsFormatting">True if formatting is supported.</param>
        /// <param name="supportsValueIndex">True if different point Y values are supported.</param>
		public KeywordInfo(
			string name,
			string keyword,
			string keywordAliases,
			string description,
			string appliesToTypes,
			string appliesToProperties,
			bool supportsFormatting,
			bool supportsValueIndex)
		{
			this.Name = name;
			this.Keyword = keyword;
			this.KeywordAliases = keywordAliases;
			this.Description = description;
			this.AppliesToTypes = appliesToTypes;
			this.AppliesToProperties = appliesToProperties;
			this.SupportsFormatting = supportsFormatting;
			this.SupportsValueIndex = supportsValueIndex;
		}

		#endregion // Constructor

		#region Methods

		/// <summary>
		/// Returns a String that represents the current keyword Information.
		/// </summary>
		/// <returns>Returns keyword name.</returns>
		public override string ToString()
		{
			return this.Name;
		}
		/// <summary>
		/// Gets an array of keywords names including the aliases.
		/// </summary>
		/// <returns>A string array of keyword names that represent this keyword.</returns>
		public string[] GetKeywords()
		{
            // NOTE: Each keyword has a unique name. In addition the keyword may have an
            // alternative names (aliases). 
            // Most common scenario for a keyword aliase is when keyword has a long and
            // short form. For example, KeywordName.Ser and "#SERIES".
            
			// Fill array of possible names for that keyword
			if(this.KeywordAliases.Length > 0)
			{
				string[] keywordAliases = this.KeywordAliases.Split(',');
				string[] keywordNames = new string[keywordAliases.Length + 1];
				keywordNames[0] = this.Keyword;
				keywordAliases.CopyTo(keywordNames, 1);
				return keywordNames;
			}
			else
			{
				return new string[] { this.Keyword };
			}
		}

		#endregion // Methods
	}
}