//============================================================================ //ZedGraph Class Library - A Flexible Line Graph/Bar Graph Library in C# //Copyright ?2006 John Champion // //This library is free software; you can redistribute it and/or //modify it under the terms of the GNU Lesser General Public //License as published by the Free Software Foundation; either //version 2.1 of the License, or (at your option) any later version. // //This library is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //Lesser General Public License for more details. // //You should have received a copy of the GNU Lesser General Public //License along with this library; if not, write to the Free Software //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //============================================================================= using System; using System.Drawing; using System.Text; using System.Runtime.Serialization; using System.Security.Permissions; namespace DrawGraph { /// /// Class that handles the data associated with a text title and its associated font /// properties. Inherits from , and adds the /// property for use by the and objects. /// /// /// John Champion /// $Revision: 3.1 $ $Date: 2006/06/24 20:26:44 $ [Serializable] public class GapLabel : Label, ICloneable, ISerializable { internal float _gap; #region Constructors /// /// Constructor to build a from the text and the /// associated font properties. /// /// The representing the text to be /// displayed /// The font family name /// The size of the font in points and scaled according /// to the logic. /// The instance representing the color /// of the font /// true for a bold font face /// true for an italic font face /// true for an underline font face public GapLabel( string text, string fontFamily, float fontSize, Color color, bool isBold, bool isItalic, bool isUnderline ) : base( text, fontFamily, fontSize, color, isBold, isItalic, isUnderline ) { _gap = Default.Gap; } /// /// Copy constructor /// /// the instance to be copied. public GapLabel( GapLabel rhs ) : base( rhs ) { _gap = rhs._gap; } /// /// Implement the interface in a typesafe manner by just /// calling the typed version of /// /// A deep copy of this object object ICloneable.Clone() { return this.Clone(); } /// /// Typesafe, deep-copy clone method. /// /// A new, independent copy of this class public new GapLabel Clone() { return new GapLabel( this ); } #endregion #region Properties /// /// Gets or sets the gap factor between this label and the opposing /// or . /// /// /// This value is expressed as a fraction of the character height for the . /// public float Gap { get { return _gap; } set { _gap = value; } } /// /// Calculate the size of the based on the /// height, in pixel units and scaled according to . /// /// The scaling factor to be applied public float GetScaledGap( float scaleFactor ) { return _fontSpec.GetHeight( scaleFactor ) * _gap; } #endregion #region Serialization /// /// Current schema value that defines the version of the serialized file /// public const int schema2 = 10; /// /// Constructor for deserializing objects /// /// A instance that defines the serialized data /// /// A instance that contains the serialized data /// protected GapLabel( SerializationInfo info, StreamingContext context ) : base( info, context ) { // The schema value is just a file version parameter. You can use it to make future versions // backwards compatible as new member variables are added to classes int sch2 = info.GetInt32( "schema2" ); _gap = info.GetSingle( "gap" ); } /// /// Populates a instance with the data needed to serialize the target object /// /// A instance that defines the serialized data /// A instance that contains the serialized data [SecurityPermissionAttribute( SecurityAction.Demand, SerializationFormatter = true )] public override void GetObjectData( SerializationInfo info, StreamingContext context ) { base.GetObjectData( info, context ); info.AddValue( "schema2", schema2 ); info.AddValue( "gap", _gap ); } #endregion #region Default /// /// A simple struct that defines the /// default property values for the class. /// public struct Default { /// /// The default setting. /// public static float Gap = 0.3f; } #endregion } }