Click here to Skip to main content
12,629,684 members (33,272 online)
Click here to Skip to main content

Stats

201.7K views
9.7K downloads
139 bookmarked
Posted

DSGraphEdit: A Reasonable Facsimile of Microsoft's GraphEdit in .NET

, 20 Dec 2007 CPOL
A library for adding DirectShow GraphEdit-like abilities to .NET applications.
WeifenLuo.WinFormsUI.Docking.dll
DaggerLib.dll
DaggerLib.DSGraphEdit.dll
DaggerLib.UI.Windows.dll
DirectShowLib-2005.dll
DSGraphEdit.exe
MediaFoundation.dll
DSGraphEdit
bin
Release
DSIcon.ico
Properties
Referenced Libs
WeifenLuo.WinFormsUI.Docking.dll
RemoteGraphTile.jpg
DaggerLib
bin
Release
Core
Interfaces
Properties
SetGeneric
UI
DaggerLib.DSGraphEdit
DMOParameterControls
DSFilterTreeView
DSGraphEditControls
lib
Properties
ReferencedLibs
DirectShowLib-2005.dll
MediaFoundation.dll
DaggerLib.UI.Windows
AStar
bin
Debug
DaggerPropertyGrid
PropertyGridEx
Properties
namespace PropertyGridEx
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    using System.Xml.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.IO;

	[Serializable()]public class CustomPropertyCollection : System.Collections.CollectionBase, ICustomTypeDescriptor
	{
		#region "Collection related methods"
	
		public virtual int Add(CustomProperty value)
		{
			return base.List.Add(value);
		}
		
		public virtual int Add(string strName, object objValue, bool boolIsReadOnly, string strCategory, string strDescription, bool boolVisible)
		{
			return base.List.Add(new CustomProperty(strName, objValue, boolIsReadOnly, strCategory, strDescription, boolVisible));
		}
		
		public virtual int Add(string strName, ref object objRef, string strProp, bool boolIsReadOnly, string strCategory, string strDescription, bool boolVisible)
		{
			return base.List.Add(new CustomProperty(strName, ref objRef, strProp, boolIsReadOnly, strCategory, strDescription, boolVisible));
		}
		
		public virtual CustomProperty this[int index]
		{
			get
			{
				return ((CustomProperty) base.List[index]);
			}
			set
			{
				base.List[index] = value;
			}
		}
		
		public virtual void Remove(string Name)
		{
			CustomProperty CustomProp;
			foreach (CustomProperty tempLoopVar_CustomProp in base.List)
			{
				CustomProp = tempLoopVar_CustomProp;
				if (CustomProp.Name == Name)
				{
					base.List.Remove(CustomProp);
					return;
				}
			}
		}

        #endregion
    		
	    #region "Implements ICustomTypeDescriptor"
		
		public System.ComponentModel.AttributeCollection GetAttributes()
		{
			return TypeDescriptor.GetAttributes(this, true);
		}
		
		public string GetClassName()
		{
			return TypeDescriptor.GetClassName(this, true);
		}
		
		public string GetComponentName()
		{
			return TypeDescriptor.GetComponentName(this, true);
		}
		
		public System.ComponentModel.TypeConverter GetConverter()
		{
			return TypeDescriptor.GetConverter(this, true);
		}
		
		public System.ComponentModel.EventDescriptor GetDefaultEvent()
		{
			return TypeDescriptor.GetDefaultEvent(this, true);
		}
		
		public System.ComponentModel.PropertyDescriptor GetDefaultProperty()
		{
			return TypeDescriptor.GetDefaultProperty(this, true);
		}
		
		public object GetEditor(System.Type editorBaseType)
		{
			return TypeDescriptor.GetEditor(this, editorBaseType, true);
		}
		
		public System.ComponentModel.EventDescriptorCollection GetEvents()
		{
			return TypeDescriptor.GetEvents(this, true);
		}
		
		public System.ComponentModel.EventDescriptorCollection GetEvents(System.Attribute[] attributes)
		{
			return TypeDescriptor.GetEvents(this, attributes, true);
		}
		
		public System.ComponentModel.PropertyDescriptorCollection GetProperties()
		{
			return TypeDescriptor.GetProperties(this, true);
		}
		
		public System.ComponentModel.PropertyDescriptorCollection GetProperties(System.Attribute[] attributes)
		{
			PropertyDescriptorCollection Properties = new PropertyDescriptorCollection(null);
			CustomProperty CustomProp;
			foreach (CustomProperty tempLoopVar_CustomProp in base.List)
			{
				CustomProp = tempLoopVar_CustomProp;
				if (CustomProp.Visible)
				{
					ArrayList attrs = new ArrayList();
					
					// Expandable Object Converter
					if (CustomProp.IsBrowsable)
					{
						attrs.Add(new TypeConverterAttribute(typeof(BrowsableTypeConverter)));
					}
					
					// The Filename Editor
					if (CustomProp.UseFileNameEditor == true)
					{
						attrs.Add(new EditorAttribute(typeof(UIFilenameEditor), typeof(UITypeEditor)));
					}
					
					// Custom Choices Type Converter
					if (CustomProp.Choices != null)
					{
						attrs.Add(new TypeConverterAttribute(typeof(CustomChoices.CustomChoicesTypeConverter)));
					}
					
					// Password Property
					if (CustomProp.IsPassword)
					{
						attrs.Add(new PasswordPropertyTextAttribute(true));
					}
					
					// Parenthesize Property
					if (CustomProp.Parenthesize)
					{
						attrs.Add(new ParenthesizePropertyNameAttribute(true));
					}
					
					// Datasource
					if (CustomProp.Datasource != null)
					{
						attrs.Add(new EditorAttribute(typeof(UIListboxEditor), typeof(UITypeEditor)));
					}
					
					// Custom Editor
					if (CustomProp.CustomEditor != null)
					{
						attrs.Add(new EditorAttribute(CustomProp.CustomEditor.GetType(), typeof(UITypeEditor)));
					}
					
					// Custom Type Converter
					if (CustomProp.CustomTypeConverter != null)
					{
						attrs.Add(new TypeConverterAttribute(CustomProp.CustomTypeConverter.GetType()));
					}

                    // Is Percentage
                    if (CustomProp.IsPercentage)
                    {
                        attrs.Add(new TypeConverterAttribute(typeof(OpacityConverter)));
                    }
					
					// 3-dots button event delegate
					if (CustomProp.OnClick != null)
					{
						attrs.Add(new EditorAttribute(typeof(UICustomEventEditor), typeof(UITypeEditor)));
					}
					
					// Default value attribute
					if (CustomProp.DefaultValue != null)
					{
						attrs.Add(new DefaultValueAttribute(CustomProp.Type, CustomProp.Value.ToString()));
					}
					else
					{
						// Default type attribute
						if (CustomProp.DefaultType != null)
						{
							attrs.Add(new DefaultValueAttribute(CustomProp.DefaultType, null));
						}
					}
					
					// Extra Attributes
					if (CustomProp.Attributes != null)
					{
						attrs.AddRange(CustomProp.Attributes);
					}
					
					// Add my own attributes
					Attribute[] attrArray =  (System.Attribute[]) attrs.ToArray(typeof(Attribute));
					Properties.Add(new CustomProperty.CustomPropertyDescriptor(CustomProp, attrArray));
				}
			}
			return Properties;
		}
		
		public object GetPropertyOwner(System.ComponentModel.PropertyDescriptor pd)
		{
			return this;
		}			

	#endregion

	    #region "Serialize & Deserialize related methods"
	
	    public void SaveXml(string filename)
	    {
		    XmlSerializer serializer = new XmlSerializer(typeof(CustomPropertyCollection));
		    FileStream writer = new FileStream(filename, FileMode.Create);
		    try
		    {
			    serializer.Serialize(writer, this);
		    }
		    catch (Exception ex)
		    {
			    MessageBox.Show(ex.InnerException.Message);
		    }
		    writer.Close();
	    }
    	
	    public bool LoadXml(string filename)
	    {
		    try
		    {
			    XmlSerializer serializer = new XmlSerializer(typeof(CustomPropertyCollection));
			    FileStream reader = new FileStream(filename, FileMode.Open);
    			
			    CustomPropertyCollection cpc = (CustomPropertyCollection) serializer.Deserialize(reader);
			    foreach (CustomProperty customprop in cpc)
			    {
				    customprop.RebuildAttributes();
				    this.Add(customprop);
			    }
			    cpc = null;
			    reader.Close();
			    return true;
    			
		    }
		    catch (Exception)
		    {
			    return false;
		    }
    		
	    }
    	
	    public void SaveBinary(string filename)
	    {
		    Stream stream = File.Create(filename);
		    BinaryFormatter serializer = new BinaryFormatter();
		    try
		    {
			    serializer.Serialize(stream, this);
		    }
		    catch (Exception ex)
		    {
			    MessageBox.Show(ex.InnerException.Message);
		    }
		    stream.Close();
	    }
    	
	    public bool LoadBinary(string filename)
	    {
		    try
		    {
			    Stream stream = File.Open(filename, FileMode.Open);
			    BinaryFormatter formatter = new BinaryFormatter();
			    if (stream.Length > 0)
			    {
				    CustomPropertyCollection cpc = (CustomPropertyCollection) formatter.Deserialize(stream);
				    foreach (CustomProperty customprop in cpc)
				    {
					    customprop.RebuildAttributes();
					    this.Add(customprop);
				    }
				    cpc = null;
				    stream.Close();
				    return true;
			    }
			    else
			    {
				    stream.Close();
				    return false;
			    }
    			
		    }
		    catch (Exception)
		    {
			    return false;
		    }
        }

        #endregion	    
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

JohnnyLocust
Software Developer (Senior) Haivision Network Video
United States United States
AKA Rich Insley.

I have over 25 years experience in programming, and I'm completely self taught. (Except for one year at California State University Fresno where I had to learn the God awful language Miranda (http://miranda.org.uk/). I've spent 10 years as a Paratrooper in the US Army during the Clinton Administration.

You may also be interested in...

Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 20 Dec 2007
Article Copyright 2007 by JohnnyLocust
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid