//============================================================================ //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 text title and its associated font /// properties /// /// /// John Champion /// $Revision: 3.2 $ $Date: 2007/03/11 02:08:16 $ [Serializable] public class Label : ICloneable, ISerializable { /// /// private field that stores the text for this label /// internal string _text; /// /// private field that stores the font properties for this label /// internal FontSpec _fontSpec; /// /// private field that determines if this label will be displayed. /// internal bool _isVisible; #region Constructors /// /// Constructor to build an 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 Label( string text, string fontFamily, float fontSize, Color color, bool isBold, bool isItalic, bool isUnderline ) { _text = ( text == null ) ? string.Empty : text; _fontSpec = new FontSpec( fontFamily, fontSize, color, isBold, isItalic, isUnderline ); _isVisible = true; } /// /// Constructor that builds a from a text /// and a instance. /// /// /// public Label( string text, FontSpec fontSpec ) { _text = (text == null) ? string.Empty : text; _fontSpec = fontSpec; _isVisible = true; } /// /// Copy constructor /// /// the instance to be copied. public Label( Label rhs ) { if (rhs._text != null) _text = (string)rhs._text.Clone(); else _text = string.Empty; _isVisible = rhs._isVisible; if ( rhs._fontSpec != null ) _fontSpec = rhs._fontSpec.Clone(); else _fontSpec = null; } /// /// 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 Label Clone() { return new Label( this ); } #endregion #region Properties /// /// The text to be displayed /// public string Text { get { return _text; } set { _text = value; } } /// /// A instance representing the font properties /// for the displayed text. /// public FontSpec FontSpec { get { return _fontSpec; } set { _fontSpec = value; } } /// /// Gets or sets a boolean value that determines whether or not this label will be displayed. /// public bool IsVisible { get { return _isVisible; } set { _isVisible = value; } } #endregion #region Serialization /// /// Current schema value that defines the version of the serialized file /// public const int schema = 10; /// /// Constructor for deserializing objects /// /// A instance that defines the serialized data /// /// A instance that contains the serialized data /// protected Label( SerializationInfo info, StreamingContext 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 sch = info.GetInt32( "schema" ); _text = info.GetString( "text" ); _isVisible = info.GetBoolean( "isVisible" ); _fontSpec = (FontSpec) info.GetValue( "fontSpec", typeof( FontSpec ) ); } /// /// 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 virtual void GetObjectData( SerializationInfo info, StreamingContext context ) { info.AddValue( "schema", schema ); info.AddValue( "text", _text ); info.AddValue( "isVisible", _isVisible ); info.AddValue( "fontSpec", _fontSpec ); } #endregion } }