ConvertTo ( ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType ) { Debug.Assert(value != null); Debug.Assert(value is LabelUserSettings); Debug.Assert(destinationType == typeof(String)); AssertValid(); LabelUserSettings oLabelUserSettings = (LabelUserSettings)value; // Use a simple tab-delimited format. Note that newer settings have // been added to the end, so related settings are not all contiguous. // Sample string: // // "Microsoft Sans Serif, 8.25pt\tWhite\tBottomCenter\t2147483647\t // 4294967295\tBlack\ttrue\t200\tBlack\t86\tMiddleCenter"; ColorConverter oColorConverter = new ColorConverter(); return(String.Format(CultureInfo.InvariantCulture, "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}" , FontToInvariantString(oLabelUserSettings.VertexFont), oColorConverter.ConvertToInvariantString( oLabelUserSettings.VertexLabelFillColor), oLabelUserSettings.VertexLabelPosition, oLabelUserSettings.VertexLabelMaximumLength, oLabelUserSettings.EdgeLabelMaximumLength, oColorConverter.ConvertToInvariantString( oLabelUserSettings.EdgeLabelTextColor), oLabelUserSettings.VertexLabelWrapText, oLabelUserSettings.VertexLabelWrapMaxTextWidth, oColorConverter.ConvertToInvariantString( oLabelUserSettings.GroupLabelTextColor), oLabelUserSettings.GroupLabelTextAlpha, oLabelUserSettings.GroupLabelPosition, FontToInvariantString(oLabelUserSettings.EdgeFont), FontToInvariantString(oLabelUserSettings.GroupFont) )); }
//************************************************************************* // Constructor: LabelUserSettingsDialog() // /// <summary> /// Initializes a new instance of the <see /// cref="LabelUserSettingsDialog" /> class. /// </summary> /// /// <param name="labelUserSettings"> /// The object being edited. /// </param> //************************************************************************* public LabelUserSettingsDialog ( LabelUserSettings labelUserSettings ) { Debug.Assert(labelUserSettings != null); labelUserSettings.AssertValid(); m_oLabelUserSettings = labelUserSettings; // Instantiate an object that saves and retrieves the position of this // dialog. Note that the object automatically saves the settings when // the form closes. m_oLabelUserSettingsDialogUserSettings = new LabelUserSettingsDialogUserSettings(this); InitializeComponent(); m_oVertexFont = m_oLabelUserSettings.VertexFont; usrVertexLabelMaximumLength.AccessKey = 'c'; cbxVertexLabelPosition.Populate(); m_oEdgeFont = m_oLabelUserSettings.EdgeFont; usrEdgeLabelMaximumLength.AccessKey = 'T'; m_oGroupFont = m_oLabelUserSettings.GroupFont; nudGroupLabelTextAlpha.Minimum = (Decimal)AlphaConverter.MinimumAlphaWorkbook; nudGroupLabelTextAlpha.Maximum = (Decimal)AlphaConverter.MaximumAlphaWorkbook; cbxGroupLabelPosition.Populate(); DoDataExchange(false); AssertValid(); }
//************************************************************************* // Constructor: LabelUserSettingsDialog() // /// <summary> /// Initializes a new instance of the <see /// cref="LabelUserSettingsDialog" /> class. /// </summary> /// /// <param name="labelUserSettings"> /// The object being edited. /// </param> //************************************************************************* public LabelUserSettingsDialog ( LabelUserSettings labelUserSettings ) { Debug.Assert(labelUserSettings != null); labelUserSettings.AssertValid(); m_oLabelUserSettings = labelUserSettings; m_oFont = m_oLabelUserSettings.Font; // Instantiate an object that saves and retrieves the position of this // dialog. Note that the object automatically saves the settings when // the form closes. m_oLabelUserSettingsDialogUserSettings = new LabelUserSettingsDialogUserSettings(this); InitializeComponent(); usrVertexLabelMaximumLength.AccessKey = 'c'; usrEdgeLabelMaximumLength.AccessKey = 'T'; cbxVertexLabelPosition.Populate(); nudGroupLabelTextAlpha.Minimum = (Decimal)AlphaConverter.MinimumAlphaWorkbook; nudGroupLabelTextAlpha.Maximum = (Decimal)AlphaConverter.MaximumAlphaWorkbook; cbxGroupLabelPosition.Populate(); DoDataExchange(false); AssertValid(); }
Copy() { AssertValid(); LabelUserSettings oCopy = new LabelUserSettings(); //*********** // Vertex //*********** oCopy.VertexFont = this.VertexFont; oCopy.VertexLabelFillColor = this.VertexLabelFillColor; oCopy.VertexLabelPosition = this.VertexLabelPosition; oCopy.VertexLabelMaximumLength = this.VertexLabelMaximumLength; oCopy.VertexLabelWrapText = this.VertexLabelWrapText; oCopy.VertexLabelWrapMaxTextWidth = this.VertexLabelWrapMaxTextWidth; //*********** // Edge //*********** oCopy.EdgeFont = this.EdgeFont; oCopy.EdgeLabelTextColor = this.EdgeLabelTextColor; oCopy.EdgeLabelMaximumLength = this.EdgeLabelMaximumLength; //*********** // Group //*********** oCopy.GroupFont = this.GroupFont; oCopy.GroupLabelTextColor = this.GroupLabelTextColor; oCopy.GroupLabelTextAlpha = this.GroupLabelTextAlpha; oCopy.GroupLabelPosition = this.GroupLabelPosition; return(oCopy); }
ConvertFrom ( ITypeDescriptorContext context, CultureInfo culture, Object value ) { Debug.Assert(value != null); Debug.Assert(value is String); AssertValid(); LabelUserSettings oLabelUserSettings = new LabelUserSettings(); String [] asStrings = ( (String)value ).Split( new Char[] {'\t'} ); Debug.Assert(asStrings.Length >= 5); ColorConverter oColorConverter = new ColorConverter(); oLabelUserSettings.Font = (Font) ( new FontConverter() ).ConvertFromInvariantString(asStrings[0] ); oLabelUserSettings.VertexLabelFillColor = (Color) oColorConverter.ConvertFromInvariantString(asStrings[1] ); oLabelUserSettings.VertexLabelPosition = (VertexLabelPosition) Enum.Parse( typeof(VertexLabelPosition), asStrings[2] ); oLabelUserSettings.VertexLabelMaximumLength = MathUtil.ParseCultureInvariantInt32( asStrings[3] ); oLabelUserSettings.EdgeLabelMaximumLength = MathUtil.ParseCultureInvariantInt32(asStrings[4]); if (asStrings.Length > 5) { // Edge label text color wasn't added until version 1.0.1.154. oLabelUserSettings.EdgeLabelTextColor = (Color) oColorConverter.ConvertFromInvariantString(asStrings[5] ); } if (asStrings.Length > 6) { // Vertex label wrapping wasn't added until version 1.0.1.175. oLabelUserSettings.VertexLabelWrapText = Boolean.Parse( asStrings[6] ); oLabelUserSettings.VertexLabelWrapMaxTextWidth = MathUtil.ParseCultureInvariantDouble( asStrings[7] ); } if (asStrings.Length > 8) { // Group label text color and alpha weren't added until version // 1.0.1.190. oLabelUserSettings.GroupLabelTextColor = (Color) oColorConverter.ConvertFromInvariantString( asStrings[8] ); oLabelUserSettings.GroupLabelTextAlpha = MathUtil.ParseCultureInvariantSingle( asStrings[9] ); } if (asStrings.Length > 10) { // Group label position wasn't added until version 1.0.1.215. oLabelUserSettings.GroupLabelPosition = (VertexLabelPosition) Enum.Parse( typeof(VertexLabelPosition), asStrings[10] ); } return (oLabelUserSettings); }
Copy() { AssertValid(); LabelUserSettings oCopy = new LabelUserSettings(); oCopy.Font = this.Font; oCopy.VertexLabelFillColor = this.VertexLabelFillColor; oCopy.VertexLabelPosition = this.VertexLabelPosition; oCopy.VertexLabelMaximumLength = this.VertexLabelMaximumLength; oCopy.VertexLabelWrapText = this.VertexLabelWrapText; oCopy.VertexLabelWrapMaxTextWidth = this.VertexLabelWrapMaxTextWidth; oCopy.EdgeLabelTextColor = this.EdgeLabelTextColor; oCopy.EdgeLabelMaximumLength = this.EdgeLabelMaximumLength; oCopy.GroupLabelTextColor = this.GroupLabelTextColor; oCopy.GroupLabelTextAlpha = this.GroupLabelTextAlpha; oCopy.GroupLabelPosition = this.GroupLabelPosition; return (oCopy); }
ConvertFrom ( ITypeDescriptorContext context, CultureInfo culture, Object value ) { Debug.Assert(value != null); Debug.Assert(value is String); AssertValid(); LabelUserSettings oLabelUserSettings = new LabelUserSettings(); String [] asStrings = ((String)value).Split(new Char[] { '\t' }); Debug.Assert(asStrings.Length >= 5); ColorConverter oColorConverter = new ColorConverter(); oLabelUserSettings.VertexFont = InvariantStringToFont(asStrings[0]); oLabelUserSettings.VertexLabelFillColor = (Color) oColorConverter.ConvertFromInvariantString(asStrings[1]); oLabelUserSettings.VertexLabelPosition = (VertexLabelPosition) Enum.Parse(typeof(VertexLabelPosition), asStrings[2]); oLabelUserSettings.VertexLabelMaximumLength = MathUtil.ParseCultureInvariantInt32(asStrings[3]); oLabelUserSettings.EdgeLabelMaximumLength = MathUtil.ParseCultureInvariantInt32(asStrings[4]); if (asStrings.Length > 5) { // Edge label text color wasn't added until version 1.0.1.154. oLabelUserSettings.EdgeLabelTextColor = (Color) oColorConverter.ConvertFromInvariantString(asStrings[5]); } if (asStrings.Length > 6) { // Vertex label wrapping wasn't added until version 1.0.1.175. oLabelUserSettings.VertexLabelWrapText = Boolean.Parse(asStrings[6]); oLabelUserSettings.VertexLabelWrapMaxTextWidth = MathUtil.ParseCultureInvariantDouble(asStrings[7]); } if (asStrings.Length > 8) { // Group label text color and alpha weren't added until version // 1.0.1.190. oLabelUserSettings.GroupLabelTextColor = (Color) oColorConverter.ConvertFromInvariantString(asStrings[8]); oLabelUserSettings.GroupLabelTextAlpha = MathUtil.ParseCultureInvariantSingle(asStrings[9]); } if (asStrings.Length > 10) { // Group label position wasn't added until version 1.0.1.215. oLabelUserSettings.GroupLabelPosition = (VertexLabelPosition) Enum.Parse(typeof(VertexLabelPosition), asStrings[10]); } if (asStrings.Length > 11) { // Prior to version 1.0.1.328, there was just one "Font" property // that applied to vertex and edge labels. Group labels used a // hard-coded font. // // In version 1.0.1.328, "Font" was renamed to VertexFont, and // EdgeFone and GroupFont properties were added. oLabelUserSettings.EdgeFont = InvariantStringToFont(asStrings[11]); oLabelUserSettings.GroupFont = InvariantStringToFont(asStrings[12]); } else { // When opening an older workbook, use the old "Font" property // (which is now VertexFont) for both vertex and edge labels. For // group labels, use GeneralUserSettings.DefaultGroupLabelFont, // which is what group labels used prior to version 1.0.1.328. oLabelUserSettings.EdgeFont = (Font)oLabelUserSettings.VertexFont.Clone(); } return(oLabelUserSettings); }