Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/PropertySystem/PropertySpec.cs @ 13400

Last change on this file since 13400 was 2768, checked in by mkommend, 15 years ago

added solution folders and sources for the netron library (ticket #867)

File size: 18.3 KB
Line 
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Drawing.Design;
5namespace Netron.Diagramming.Core
6{
7  /// <summary>
8  /// Represents the description of a property and is a transitional construction to the actual property descriptor of a property.
9    /// This class is a modification of the original idea presented by Tony Allowatt (http://www.codeproject.com/cs/miscctrl/bending_property.asp) and used in
10    /// a previous version of the graph library.
11  /// </summary>
12  [Serializable] public class PropertySpec
13  {
14    #region Fields
15    private Attribute[] attributes;
16    private string category;
17    private object defaultValue;
18    private string description;
19    private string editor;
20    private string name;
21    private string type;
22    private string typeConverter;
23
24    #endregion
25
26    #region Properties
27    /// <summary>
28    /// Gets or sets a collection of additional Attributes for this property.  This can
29    /// be used to specify attributes beyond those supported intrinsically by the
30    /// PropertySpec class, such as ReadOnly and Browsable.
31    /// </summary>
32    public Attribute[] Attributes
33    {
34      get { return attributes; }
35      set { attributes = value; }
36    }
37
38    /// <summary>
39    /// Gets or sets the category name of this property.
40    /// </summary>
41    public string Category
42    {
43      get { return category; }
44      set { category = value; }
45    }
46
47    /// <summary>
48    /// Gets or sets the fully qualified name of the type converter
49    /// type for this property.
50    /// </summary>
51    public string ConverterTypeName
52    {
53      get { return typeConverter; }
54      set { typeConverter = value; }
55    }
56
57    /// <summary>
58    /// Gets or sets the default value of this property.
59    /// </summary>
60    public object DefaultValue
61    {
62      get { return defaultValue; }
63      set { defaultValue = value; }
64    }
65
66    /// <summary>
67    /// Gets or sets the help text description of this property.
68    /// </summary>
69    public string Description
70    {
71      get { return description; }
72      set { description = value; }
73    }
74
75    /// <summary>
76    /// Gets or sets the fully qualified name of the editor type for
77    /// this property.
78    /// </summary>
79    public string EditorTypeName
80    {
81      get { return editor; }
82      set { editor = value; }
83    }
84
85    /// <summary>
86    /// Gets or sets the name of this property.
87    /// </summary>
88    public string Name
89    {
90      get { return name; }
91      set { name = value; }
92    }
93
94    /// <summary>
95    /// Gets or sets the fully qualfied name of the type of this
96    /// property.
97    /// </summary>
98    public string TypeName
99    {
100      get { return type; }
101      set { type = value; }
102    }
103    #endregion
104
105    #region Constructors
106    /// <summary>
107    /// Initializes a new instance of the PropertySpec class.
108    /// </summary>
109    /// <param name="name">The name of the property displayed in the property grid.</param>
110    /// <param name="type">The fully qualified name of the type of the property.</param>
111    public PropertySpec(string name, string type) : this(name, type, null, null, null) { }
112
113    /// <summary>
114    /// Initializes a new instance of the PropertySpec class.
115    /// </summary>
116    /// <param name="name">The name of the property displayed in the property grid.</param>
117    /// <param name="type">A Type that represents the type of the property.</param>
118    public PropertySpec(string name, Type type) :
119      this(name, type.AssemblyQualifiedName, null, null, null) { }
120
121    /// <summary>
122    /// Initializes a new instance of the PropertySpec class.
123    /// </summary>
124    /// <param name="name">The name of the property displayed in the property grid.</param>
125    /// <param name="type">The fully qualified name of the type of the property.</param>
126    /// <param name="category">The category under which the property is displayed in the
127    /// property grid.</param>
128    public PropertySpec(string name, string type, string category) : this(name, type, category, null, null) { }
129
130    /// <summary>
131    /// Initializes a new instance of the PropertySpec class.
132    /// </summary>
133    /// <param name="name">The name of the property displayed in the property grid.</param>
134    /// <param name="type">A Type that represents the type of the property.</param>
135    /// <param name="category"></param>
136    public PropertySpec(string name, Type type, string category) :
137      this(name, type.AssemblyQualifiedName, category, null, null) { }
138
139    /// <summary>
140    /// Initializes a new instance of the PropertySpec class.
141    /// </summary>
142    /// <param name="name">The name of the property displayed in the property grid.</param>
143    /// <param name="type">The fully qualified name of the type of the property.</param>
144    /// <param name="category">The category under which the property is displayed in the
145    /// property grid.</param>
146    /// <param name="description">A string that is displayed in the help area of the
147    /// property grid.</param>
148    public PropertySpec(string name, string type, string category, string description) :
149      this(name, type, category, description, null) { }
150
151    /// <summary>
152    /// Initializes a new instance of the PropertySpec class.
153    /// </summary>
154    /// <param name="name">The name of the property displayed in the property grid.</param>
155    /// <param name="type">A Type that represents the type of the property.</param>
156    /// <param name="category">The category under which the property is displayed in the
157    /// property grid.</param>
158    /// <param name="description">A string that is displayed in the help area of the
159    /// property grid.</param>
160    public PropertySpec(string name, Type type, string category, string description) :
161      this(name, type.AssemblyQualifiedName, category, description, null) { }
162
163    /// <summary>
164    /// Initializes a new instance of the PropertySpec class.
165    /// </summary>
166    /// <param name="name">The name of the property displayed in the property grid.</param>
167    /// <param name="type">The fully qualified name of the type of the property.</param>
168    /// <param name="category">The category under which the property is displayed in the
169    /// property grid.</param>
170    /// <param name="description">A string that is displayed in the help area of the
171    /// property grid.</param>
172    /// <param name="defaultValue">The default value of the property, or null if there is
173    /// no default value.</param>
174    public PropertySpec(string name, string type, string category, string description, object defaultValue)
175    {
176      this.name = name;
177      this.type = type;
178      this.category = category;
179      this.description = description;
180      this.defaultValue = defaultValue;
181      this.attributes = null;
182    }
183
184    /// <summary>
185    /// Initializes a new instance of the PropertySpec class.
186    /// </summary>
187    /// <param name="name">The name of the property displayed in the property grid.</param>
188    /// <param name="type">A Type that represents the type of the property.</param>
189    /// <param name="category">The category under which the property is displayed in the
190    /// property grid.</param>
191    /// <param name="description">A string that is displayed in the help area of the
192    /// property grid.</param>
193    /// <param name="defaultValue">The default value of the property, or null if there is
194    /// no default value.</param>
195    public PropertySpec(string name, Type type, string category, string description, object defaultValue) :
196      this(name, type.AssemblyQualifiedName, category, description, defaultValue) { }
197
198    /// <summary>
199    /// Initializes a new instance of the PropertySpec class.
200    /// </summary>
201    /// <param name="name">The name of the property displayed in the property grid.</param>
202    /// <param name="type">The fully qualified name of the type of the property.</param>
203    /// <param name="category">The category under which the property is displayed in the
204    /// property grid.</param>
205    /// <param name="description">A string that is displayed in the help area of the
206    /// property grid.</param>
207    /// <param name="defaultValue">The default value of the property, or null if there is
208    /// no default value.</param>
209    /// <param name="editor">The fully qualified name of the type of the editor for this
210    /// property.  This type must derive from UITypeEditor.</param>
211    /// <param name="typeConverter">The fully qualified name of the type of the type
212    /// converter for this property.  This type must derive from TypeConverter.</param>
213    public PropertySpec(string name, string type, string category, string description, object defaultValue,
214      string editor, string typeConverter) : this(name, type, category, description, defaultValue)
215    {
216      this.editor = editor;
217      this.typeConverter = typeConverter;
218    }
219
220    /// <summary>
221    /// Initializes a new instance of the PropertySpec class.
222    /// </summary>
223    /// <param name="name">The name of the property displayed in the property grid.</param>
224    /// <param name="type">A Type that represents the type of the property.</param>
225    /// <param name="category">The category under which the property is displayed in the
226    /// property grid.</param>
227    /// <param name="description">A string that is displayed in the help area of the
228    /// property grid.</param>
229    /// <param name="defaultValue">The default value of the property, or null if there is
230    /// no default value.</param>
231    /// <param name="editor">The fully qualified name of the type of the editor for this
232    /// property.  This type must derive from UITypeEditor.</param>
233    /// <param name="typeConverter">The fully qualified name of the type of the type
234    /// converter for this property.  This type must derive from TypeConverter.</param>
235    public PropertySpec(string name, Type type, string category, string description, object defaultValue,
236      string editor, string typeConverter) :
237      this(name, type.AssemblyQualifiedName, category, description, defaultValue, editor, typeConverter) { }
238
239    /// <summary>
240    /// Initializes a new instance of the PropertySpec class.
241    /// </summary>
242    /// <param name="name">The name of the property displayed in the property grid.</param>
243    /// <param name="type">The fully qualified name of the type of the property.</param>
244    /// <param name="category">The category under which the property is displayed in the
245    /// property grid.</param>
246    /// <param name="description">A string that is displayed in the help area of the
247    /// property grid.</param>
248    /// <param name="defaultValue">The default value of the property, or null if there is
249    /// no default value.</param>
250    /// <param name="editor">The Type that represents the type of the editor for this
251    /// property.  This type must derive from UITypeEditor.</param>
252    /// <param name="typeConverter">The fully qualified name of the type of the type
253    /// converter for this property.  This type must derive from TypeConverter.</param>
254    public PropertySpec(string name, string type, string category, string description, object defaultValue,
255      Type editor, string typeConverter) :
256      this(name, type, category, description, defaultValue, editor.AssemblyQualifiedName,
257      typeConverter) { }
258
259    /// <summary>
260    /// Initializes a new instance of the PropertySpec class.
261    /// </summary>
262    /// <param name="name">The name of the property displayed in the property grid.</param>
263    /// <param name="type">A Type that represents the type of the property.</param>
264    /// <param name="category">The category under which the property is displayed in the
265    /// property grid.</param>
266    /// <param name="description">A string that is displayed in the help area of the
267    /// property grid.</param>
268    /// <param name="defaultValue">The default value of the property, or null if there is
269    /// no default value.</param>
270    /// <param name="editor">The Type that represents the type of the editor for this
271    /// property.  This type must derive from UITypeEditor.</param>
272    /// <param name="typeConverter">The fully qualified name of the type of the type
273    /// converter for this property.  This type must derive from TypeConverter.</param>
274    public PropertySpec(string name, Type type, string category, string description, object defaultValue,
275      Type editor, string typeConverter) :
276      this(name, type.AssemblyQualifiedName, category, description, defaultValue,
277      editor.AssemblyQualifiedName, typeConverter) { }
278
279    /// <summary>
280    /// Initializes a new instance of the PropertySpec class.
281    /// </summary>
282    /// <param name="name">The name of the property displayed in the property grid.</param>
283    /// <param name="type">The fully qualified name of the type of the property.</param>
284    /// <param name="category">The category under which the property is displayed in the
285    /// property grid.</param>
286    /// <param name="description">A string that is displayed in the help area of the
287    /// property grid.</param>
288    /// <param name="defaultValue">The default value of the property, or null if there is
289    /// no default value.</param>
290    /// <param name="editor">The fully qualified name of the type of the editor for this
291    /// property.  This type must derive from UITypeEditor.</param>
292    /// <param name="typeConverter">The Type that represents the type of the type
293    /// converter for this property.  This type must derive from TypeConverter.</param>
294    public PropertySpec(string name, string type, string category, string description, object defaultValue,
295      string editor, Type typeConverter) :
296      this(name, type, category, description, defaultValue, editor, typeConverter.AssemblyQualifiedName) { }
297
298    /// <summary>
299    /// Initializes a new instance of the PropertySpec class.
300    /// </summary>
301    /// <param name="name">The name of the property displayed in the property grid.</param>
302    /// <param name="type">A Type that represents the type of the property.</param>
303    /// <param name="category">The category under which the property is displayed in the
304    /// property grid.</param>
305    /// <param name="description">A string that is displayed in the help area of the
306    /// property grid.</param>
307    /// <param name="defaultValue">The default value of the property, or null if there is
308    /// no default value.</param>
309    /// <param name="editor">The fully qualified name of the type of the editor for this
310    /// property.  This type must derive from UITypeEditor.</param>
311    /// <param name="typeConverter">The Type that represents the type of the type
312    /// converter for this property.  This type must derive from TypeConverter.</param>
313    public PropertySpec(string name, Type type, string category, string description, object defaultValue,
314      string editor, Type typeConverter) :
315      this(name, type.AssemblyQualifiedName, category, description, defaultValue, editor,
316      typeConverter.AssemblyQualifiedName) { }
317
318    /// <summary>
319    /// Initializes a new instance of the PropertySpec class.
320    /// </summary>
321    /// <param name="name">The name of the property displayed in the property grid.</param>
322    /// <param name="type">The fully qualified name of the type of the property.</param>
323    /// <param name="category">The category under which the property is displayed in the
324    /// property grid.</param>
325    /// <param name="description">A string that is displayed in the help area of the
326    /// property grid.</param>
327    /// <param name="defaultValue">The default value of the property, or null if there is
328    /// no default value.</param>
329    /// <param name="editor">The Type that represents the type of the editor for this
330    /// property.  This type must derive from UITypeEditor.</param>
331    /// <param name="typeConverter">The Type that represents the type of the type
332    /// converter for this property.  This type must derive from TypeConverter.</param>
333    public PropertySpec(string name, string type, string category, string description, object defaultValue,
334      Type editor, Type typeConverter) :
335      this(name, type, category, description, defaultValue, editor.AssemblyQualifiedName,
336      typeConverter.AssemblyQualifiedName) { }
337
338    /// <summary>
339    /// Initializes a new instance of the PropertySpec class.
340    /// </summary>
341    /// <param name="name">The name of the property displayed in the property grid.</param>
342    /// <param name="type">A Type that represents the type of the property.</param>
343    /// <param name="category">The category under which the property is displayed in the
344    /// property grid.</param>
345    /// <param name="description">A string that is displayed in the help area of the
346    /// property grid.</param>
347    /// <param name="defaultValue">The default value of the property, or null if there is
348    /// no default value.</param>
349    /// <param name="editor">The Type that represents the type of the editor for this
350    /// property.  This type must derive from UITypeEditor.</param>
351    /// <param name="typeConverter">The Type that represents the type of the type
352    /// converter for this property.  This type must derive from TypeConverter.</param>
353    public PropertySpec(string name, Type type, string category, string description, object defaultValue,
354      Type editor, Type typeConverter) :
355      this(name, type.AssemblyQualifiedName, category, description, defaultValue,
356      editor.AssemblyQualifiedName, typeConverter.AssemblyQualifiedName) { }
357
358
359    #endregion
360
361        #region Methods
362        /// <summary>
363        /// Converts this specification to an  property descriptor.
364        /// </summary>
365        /// <returns></returns>
366        internal PropertySpecDescriptor ToPropertyDescriptor()
367        {
368            ArrayList attrs = new ArrayList();
369            // If a category, description, editor, or type converter are specified
370            // in the thisSpec, create attributes to define that relationship.
371            if(this.Category != null)
372                attrs.Add(new CategoryAttribute(this.Category));
373
374            if(this.Description != null)
375                attrs.Add(new DescriptionAttribute(this.Description));
376
377            if(this.EditorTypeName != null)
378                attrs.Add(new EditorAttribute(this.EditorTypeName, typeof(UITypeEditor)));
379
380            if(this.ConverterTypeName != null)
381                attrs.Add(new TypeConverterAttribute(this.ConverterTypeName));
382
383            // Additionally, append the custom attributes associated with the
384            // thisSpec, if any.
385            if(this.Attributes != null)
386                attrs.AddRange(this.Attributes);
387
388            Attribute[] attrArray = (Attribute[]) attrs.ToArray(typeof(Attribute));
389
390            // Create a new this descriptor for the this item, and add
391            // it to the list.
392            return new PropertySpecDescriptor(this, attrArray);
393        }
394            #endregion
395   
396        }
397
398}
Note: See TracBrowser for help on using the repository browser.