using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.ComponentModel;
using System.Text;
namespace Volian.Svg.Library
{
///
///
/// A collection that stores objects.
///
///
///
[Serializable()]
[TypeConverter(typeof(SVGPartsConverter))]
public partial class SvgParts : CollectionBase, ICustomTypeDescriptor
{
/// Notifies when the collection has been modified.
public event EventHandler OnItemsChanged;
/// Notifies that an item has been added.
public event SVGPartHandler OnItemAdd;
/// Notifies that items have been added.
public event SVGPartHandler OnItemsAdd;
/// Notifies that an item has been removed.
public event SVGPartHandler OnItemRemove;
///
///
/// Initializes a new instance of .
///
///
public SvgParts()
{
}
///
///
/// Initializes a new instance of based on another .
///
///
///
/// A from which the contents are copied
///
public SvgParts(SvgParts value)
{
this.AddRange(value);
}
///
///
/// Initializes a new instance of containing any array of objects.
///
///
///
/// A array of objects with which to intialize the collection
///
public SvgParts(SvgPart[] value)
{
this.AddRange(value);
}
///
/// Represents the entry at the specified index of the .
///
/// The zero-based index of the entry to locate in the collection.
///
/// The entry at the specified index of the collection.
///
/// is outside the valid range of indexes for the collection.
public SvgPart this[int index]
{
get { return ((SvgPart)(List[index])); }
set { List[index] = value; }
}
//#region SetupInheritance
//internal void SetupInheritance(SvgInheritedSettings myParentsSettings)
//{
// foreach (SvgPart svgPart in List)
// svgPart.SetupInheritance(myParentsSettings);
//}
//#endregion
#region Dictionary of Parts
internal void AddLookup(Dictionary lookUp)
{
foreach (SvgPart svgPart in List)
svgPart.AddLookup(lookUp);
}
#endregion
internal static void ShowException(Exception ex)
{
StringBuilder sb = new StringBuilder();
string sep = "";
for (Exception ex1 = ex; ex1 != null; ex1 = ex1.InnerException)
{
sb.Append(sep + string.Format("ShowException {0} - {1}", ex1.GetType().Name, ex1.Message));
sep = "\r\n";
}
Console.WriteLine(sb);
}
///
/// Adds a with the specified value to the
/// .
///
/// The to add.
///
/// The index at which the new element was inserted.
///
///
public int Add(SvgPart value)
{
int ndx = List.Add(value);
if (OnItemAdd != null) { OnItemAdd(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
return ndx;
}
///
/// Copies the elements of an array to the end of the .
///
///
/// An array of type containing the objects to add to the collection.
///
///
/// None.
///
///
public void AddRange(SvgPart[] value)
{
for (int i = 0; i < value.Length; i++)
{
this.Add(value[i]);
}
if (OnItemsAdd != null) { OnItemsAdd(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
}
///
///
/// Adds the contents of another to the end of the collection.
///
///
///
/// A containing the objects to add to the collection.
///
///
/// None.
///
///
public void AddRange(SvgParts value)
{
for (int i = 0; i < value.Count; i++)
{
this.Add(value[i]);
}
if (OnItemsAdd != null) { OnItemsAdd(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
}
///
/// Gets a value indicating whether the
/// contains the specified .
///
/// The to locate.
///
/// if the is contained in the collection;
/// otherwise, .
///
///
public bool Contains(SvgPart value)
{
return List.Contains(value);
}
///
/// Copies the values to a one-dimensional instance at the
/// specified index.
///
/// The one-dimensional that is the destination of the values copied from .
/// The index in where copying begins.
///
/// None.
///
/// is multidimensional. -or- The number of elements in the is greater than the available space between and the end of .
/// is .
/// is less than 's lowbound.
///
public void CopyTo(SvgPart[] array, int index)
{
List.CopyTo(array, index);
}
///
/// Returns the index of a in
/// the .
///
/// The to locate.
///
/// The index of the of in the
/// , if found; otherwise, -1.
///
///
public int IndexOf(SvgPart value)
{
return List.IndexOf(value);
}
///
/// Inserts a into the at the specified index.
///
/// The zero-based index where should be inserted.
/// The to insert.
/// None.
///
public void Insert(int index, SvgPart value)
{
List.Insert(index, value);
if (OnItemAdd != null) { OnItemAdd(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
}
///
/// Removes a specific from the
/// .
///
/// The to remove from the .
/// None.
/// is not found in the Collection.
public void Remove(SvgPart value)
{
List.Remove(value);
if (OnItemRemove != null) { OnItemRemove(this, new SVGPartArgs(value)); }
if (OnItemsChanged != null) { OnItemsChanged(value, EventArgs.Empty); }
}
#region ICustomTypeDescriptor impl
public String GetClassName()
{ return TypeDescriptor.GetClassName(this, true); }
public AttributeCollection GetAttributes()
{ return TypeDescriptor.GetAttributes(this, true); }
public String GetComponentName()
{ return TypeDescriptor.GetComponentName(this, true); }
public TypeConverter GetConverter()
{ return TypeDescriptor.GetConverter(this, true); }
public EventDescriptor GetDefaultEvent()
{ return TypeDescriptor.GetDefaultEvent(this, true); }
public PropertyDescriptor GetDefaultProperty()
{ return TypeDescriptor.GetDefaultProperty(this, true); }
public object GetEditor(Type editorBaseType)
{ return TypeDescriptor.GetEditor(this, editorBaseType, true); }
public EventDescriptorCollection GetEvents(Attribute[] attributes)
{ return TypeDescriptor.GetEvents(this, attributes, true); }
public EventDescriptorCollection GetEvents()
{ return TypeDescriptor.GetEvents(this, true); }
public object GetPropertyOwner(PropertyDescriptor pd)
{ return this; }
///
/// Called to get the properties of this type. Returns properties with certain
/// attributes. this restriction is not implemented here.
///
///
///
public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
{ return GetProperties(); }
///
/// Called to get the properties of this type.
///
///
public PropertyDescriptorCollection GetProperties()
{
// Create a collection object to hold property descriptors
PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
// Iterate the list
for (int i = 0; i < this.Count; i++)
{
// Create a property descriptor for the item and add to the property descriptor collection
SvgPartsPropertyDescriptor pd = new SvgPartsPropertyDescriptor(this, i);
pds.Add(pd);
}
// return the property descriptor collection
return pds;
}
#endregion
/// Event arguments for the SVGParts collection class.
public class SVGPartArgs : EventArgs
{
private SvgParts t;
/// Default constructor.
public SVGPartArgs()
{
t = new SvgParts();
}
/// Initializes with a SVGPart.
/// Data object.
public SVGPartArgs(SvgPart t)
: this()
{
this.t.Add(t);
}
/// Initializes with a collection of SVGPart objects.
/// Collection of data.
public SVGPartArgs(SvgParts ts)
: this()
{
this.t.AddRange(ts);
}
/// Initializes with an array of SVGPart objects.
/// Array of data.
public SVGPartArgs(SvgPart[] ts)
: this()
{
this.t.AddRange(ts);
}
/// Gets or sets the data of this argument.
public SvgParts SVGParts
{
get { return t; }
set { t = value; }
}
}
/// SVGParts event handler.
public delegate void SVGPartHandler(object sender, SVGPartArgs e);
#region Property Descriptor
///
/// Summary description for CollectionPropertyDescriptor.
///
public partial class SvgPartsPropertyDescriptor : vlnListPropertyDescriptor
{
private SvgPart Item { get { return (SvgPart)_Item; } }
public SvgPartsPropertyDescriptor(SvgParts collection, int index) : base(collection, index) { ;}
public override string DisplayName
{ get { return Item.GetType().Name; } }
}
#endregion
[Serializable()]
public partial class vlnListPropertyDescriptor : PropertyDescriptor
{
protected object _Item = null;
public vlnListPropertyDescriptor(System.Collections.IList collection, int index)
: base("#" + index.ToString(), null)
{ _Item = collection[index]; }
public override bool CanResetValue(object component)
{ return true; }
public override Type ComponentType
{ get { return _Item.GetType(); } }
public override object GetValue(object component)
{ return _Item; }
public override bool IsReadOnly
{ get { return false; } }
public override Type PropertyType
{ get { return _Item.GetType(); } }
public override void ResetValue(object component)
{ ;}
public override bool ShouldSerializeValue(object component)
{ return true; }
public override void SetValue(object component, object value)
{ /*_Item = value*/;}
//public override AttributeCollection Attributes
//{ get { return new AttributeCollection(null); } }
public override string DisplayName
{ get { return _Item.ToString(); } }
public override string Description
{ get { return _Item.ToString(); } }
public override string Name
{ get { return _Item.ToString(); } }
} // Class
#region Converter
internal class SVGPartsConverter : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is SvgParts)
{
// Return department and department role separated by comma.
return ((SvgParts)value).List.Count.ToString() + " SVG Drawing Parts";
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
}
}