/// <summary> /// Deserialization constructor /// </summary> /// <param name="info"></param> /// <param name="context"></param> public GraphAbstract(SerializationInfo info, StreamingContext context) { #region Version test //test the version, warn if the build or major is different Version currentversion = Assembly.GetExecutingAssembly().GetName().Version; Version fileversion = new Version(info.GetString("NetronGraphLibVersion")); int diff = currentversion.CompareTo(fileversion); if (fileversion.Minor != currentversion.Minor || fileversion.Major != currentversion.Major) { DialogResult res = MessageBox.Show("The graph was saved in version " + fileversion.ToString() + " while the current graph library has version " + currentversion.ToString() + ". It is not guaranteed that the graph will appeare as it was when saved. Are you sure you want to open the graph?", "Different version", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (res == DialogResult.No) { return; } } #endregion Init(); this.mShapes = info.GetValue("mShapes", typeof(ShapeCollection)) as ShapeCollection; this.mConnections = info.GetValue("mConnections", typeof(ConnectionCollection)) as ConnectionCollection; this.mGraphInformation = info.GetValue("mGraphInformation", typeof(GraphInformation)) as GraphInformation; this.mLayers = info.GetValue("mLayers", typeof(GraphLayerCollection)) as GraphLayerCollection; }
/// <summary> /// Deserialization constructor /// </summary> /// <param name="info"></param> /// <param name="context"></param> public GraphAbstract(SerializationInfo info, StreamingContext context) { #region Version test //test the version, warn if the build or major is different Version currentversion = Assembly.GetExecutingAssembly().GetName().Version; Version fileversion = new Version(info.GetString("NetronGraphLibVersion")); int diff = currentversion.CompareTo(fileversion); if (fileversion.Minor != currentversion.Minor || fileversion.Major != currentversion.Major) { DialogResult res = MessageBox.Show("The graph was saved in version " + fileversion.ToString() + " while the current graph library has version " + currentversion.ToString() + ". It is not guaranteed that the graph will appeare as it was when saved. Are you sure you want to open the graph?", "Different version", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (res == DialogResult.No) { return; } } #endregion this.mShapes = info.GetValue("mShapes", typeof(ShapeCollection)) as ShapeCollection; this.mConnections = info.GetValue("mConnections", typeof(ConnectionCollection)) as ConnectionCollection; this.mGraphInformation = info.GetValue("mGraphInformation", typeof(GraphInformation)) as GraphInformation; this.mLayers = info.GetValue("mLayers", typeof(GraphLayerCollection)) as GraphLayerCollection; if (mLayers != null) { GraphLayer layer = mLayers["Default"]; if (layer == null) { layer = new GraphLayer("Default", Color.WhiteSmoke, 100); layer.UseColor = false; //use colors only for upper layers layer.Visible = false; mLayers.Add(layer); } // foreach (GraphLayer tLayer in mLayers) // { // if (tLayer != null && tLayer.Visible) // { // mCurrentLayer = tLayer; // break; // } // } // if (mCurrentLayer == null) // { // mCurrentLayer = DefaultLayer; // } // if (mCurrentLayer != null) mCurrentLayer.Visible = true; mLayers.ClearComplete += new EventHandler(Layers_ClearComplete); } BindEntityCollectionEvents(); }
private void Init() { //the shape layers mLayers = new GraphLayerCollection(); mLayers.ClearComplete += new EventHandler(Layers_ClearComplete); //the default layer mDefaultLayer = new GraphLayer("Default", Color.WhiteSmoke, 100); mDefaultLayer.UseColor = false; //use colors only for upper layers BindEntityCollectionEvents(); }
/// <summary> /// Adds a collection range to this collection /// </summary> /// <param name="col"></param> public void AddRange(GraphLayerCollection col) { InnerList.AddRange(col); }
/// <summary> /// Implements the dropdown style for selecting layers /// </summary> /// <param name="context"></param> /// <param name="provider"></param> /// <param name="value"></param> /// <returns></returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { // Uses the IWindowsFormsEditorService to display a drop-down UI if (edSvc == null) { edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); } if (edSvc != null) { if (listbox == null) { listbox = new ListBox(); listbox.BorderStyle = BorderStyle.None; listbox.SelectedIndexChanged += new EventHandler(OnListBoxChanged); } GraphLayerAttribute attr = context.PropertyDescriptor.Attributes[typeof(GraphLayerAttribute)] as GraphLayerAttribute; GraphLayerCollection values = new GraphLayerCollection(); //attributes are the only way to pass info from the context to the property grid //A UITypeDescriptor is supposed to be independent of the context/application //There is no way you can get access to the canvas starting from the grid or from this class if (attr != null && !attr.IsDefaultAttribute()) { values.AddRange(attr.Layers); } //GraphLayer dl = new GraphLayer("Default"); values.Add(GraphAbstract.DefaultLayer); //this is only for design-time support: //ISelectionService serv = (ISelectionService )provider.GetService(typeof(ISelectionService )); listbox.Items.Clear(); int width = 0; Font font = listbox.Font; // Add the standard values in the list box and // measure the text at the same time. using (Graphics g = listbox.CreateGraphics()) { foreach (GraphLayer layer in values) { if (!listbox.Items.Contains(layer)) { // if (!editor.ShowPreviewOnly) width = (int)Math.Max(width, g.MeasureString(layer.ToString(), font).Width); listbox.Items.Add(layer); } } } listbox.SelectedItem = value; listbox.Height = Math.Max(font.Height + 2, Math.Min(200, listbox.PreferredHeight)); listbox.Width = Math.Max(width, 100); edSvc.DropDownControl(listbox); if (listbox.SelectedItem != null) { return(listbox.SelectedItem); } else { return(value); } } return(value); }