using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Charts.Style
{
    /// 
    /// Represents a SeriesLabelVisualStyle.
    /// 
    [TypeConverter(typeof(VisualStylesConverter))]
    public class SeriesLabelVisualStyle : ContainerVisualStyle
    {
        #region Private variables
        private Color _ConnectorColor = Color.Empty;
        private LinePattern _ConnectorPattern = LinePattern.NotSet;
        private int _ConnectorLength = -1;
        private int _ConnectorThickness = -1;
        private Tbool _DrawConnector = Tbool.NotSet;
        private Tbool _ShowBaseValueLabels = Tbool.NotSet;
        private Size _MaximumSize = Size.Empty;
        private Size _MinimumSize = Size.Empty;
        private Point _Offset;
        private float _Rotation = float.NaN;
        private string _TextFormat;
        #endregion
        #region Public properties
        #region ConnectorColor
        /// 
        /// Gets or sets the style border color.
        /// 
        [Description("Indicates the style Border Color")]
        public Color ConnectorColor
        {
            get { return (_ConnectorColor); }
            set
            {
                if (value != _ConnectorColor)
                {
                    _ConnectorColor = value;
                    OnPropertyChangedEx("ConnectorColor", VisualChangeType.Render);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeConnectorColor()
        {
            return (_ConnectorColor.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetConnectorColor()
        {
            _ConnectorColor = Color.Empty;
        }
        #endregion
        #region ConnectorLength
        /// 
        /// Gets or sets the length of the line connecting the slice
        /// and the slice label.
        /// 
        [DefaultValue(-1), Category("Appearance")]
        [Description("Indicates the length of the line connecting the slice and the slice label.")]
        public int ConnectorLength
        {
            get { return (_ConnectorLength); }
            set
            {
                if (value != _ConnectorLength)
                {
                    if (value < 0)
                        throw new InvalidPropertyValueException("value cannot be negative.");
                    _ConnectorLength = value;
                    OnPropertyChangedEx("ConnectorLength", VisualChangeType.Layout);
                }
            }
        }
        #endregion
        #region ConnectorPattern
        /// 
        /// Gets or sets the style border pattern (Solid, Dash, ...)
        /// 
        [Description("Indicates the style border pattern (Solid, Dash, ...)")]
        [DefaultValue(LinePattern.NotSet)]
        public LinePattern ConnectorPattern
        {
            get { return (_ConnectorPattern); }
            set
            {
                if (value != _ConnectorPattern)
                {
                    _ConnectorPattern = value;
                    OnPropertyChangedEx("ConnectorPattern", VisualChangeType.Render);
                }
            }
        }
        #endregion
        #region ConnectorThickness
        /// 
        /// Gets or sets the style border thickness.
        /// 
        [DefaultValue(-1), Category("Appearance")]
        [Description("Indicates the style border thickness")]
        public int ConnectorThickness
        {
            get { return (_ConnectorThickness); }
            set
            {
                if (value != _ConnectorThickness)
                {
                    _ConnectorThickness = value;
                    OnPropertyChangedEx("ConnectorThickness", VisualChangeType.Layout);
                }
            }
        }
        #endregion
        #region DrawConnector
        ///
        /// Gets or sets whether a connecting line is drawn to the data point.
        ///
        [DefaultValue(Tbool.NotSet), Category("DataLabel")]
        [Description("Indicates whether a connecting line is drawn to the data point.")]
        public Tbool DrawConnector
        {
            get { return (_DrawConnector); }
            set
            {
                if (value != _DrawConnector)
                {
                    _DrawConnector = value;
                    OnPropertyChangedEx("DrawConnector", Style.VisualChangeType.Render);
                }
            }
        }
        #endregion
        #region MaximumSize
        /// 
        /// Gets or sets the maximum size of the label.
        /// 
        [Category("Appearance")]
        [Description("Indicates the maximum size of the label.")]
        public Size MaximumSize
        {
            get { return (_MaximumSize); }
            set
            {
                if (value != _MaximumSize)
                {
                    _MaximumSize = value;
                    OnPropertyChangedEx("MaximumSize", VisualChangeType.Layout);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeCMaximumSize()
        {
            return (_MaximumSize.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetMaximumSize()
        {
            MaximumSize = Size.Empty;
        }
        #endregion
        #region MinimumSize
        /// 
        /// Gets or sets the minimum size of the label.
        /// 
        [Category("Appearance")]
        [Description("Indicates the minimum size of the label.")]
        public Size MinimumSize
        {
            get { return (_MinimumSize); }
            set
            {
                if (value != _MinimumSize)
                {
                    _MinimumSize = value;
                    OnPropertyChangedEx("MinimumSize", VisualChangeType.Layout);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeMinimumSize()
        {
            return (_MinimumSize.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetMinimumSize()
        {
            MinimumSize = Size.Empty;
        }
        #endregion
        #region Offset
        ///
        /// Gets or sets the offset of the label relative to the data point.
        ///
        [Category("Appearance")]
        [Description("Indicates the offset of the label relative to the data point.")]
        public Point Offset
        {
            get { return (_Offset); }
            set
            {
                if (value != _Offset)
                {
                    _Offset = value;
                    OnPropertyChangedEx("Offset", Style.VisualChangeType.Layout);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeOffset()
        {
            return (_Offset.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetOffset()
        {
            Offset = Point.Empty;
        }
        #endregion
        #region Rotation
        ///
        /// Gets or sets the amount to rotate the label body.
        ///
        [DefaultValue(float.NaN), Category("Appearance")]
        [Description("Indicates the amount to rotate the label body.")]
        public float Rotation
        {
            get { return (_Rotation); }
            set
            {
                if (value != _Rotation)
                {
                    _Rotation = value;
                    OnPropertyChangedEx("Rotation", Style.VisualChangeType.Layout);
                }
            }
        }
        #endregion
        #region ShowBaseValueLabels
        ///
        /// Gets or sets whether Labels are shown for Base Values.
        ///
        [DefaultValue(Tbool.NotSet), Category("DataLabel")]
        [Description("Indicates whether Labels are shown for Base Values.")]
        public Tbool ShowBaseValueLabels
        {
            get { return (_ShowBaseValueLabels); }
            set
            {
                if (value != _ShowBaseValueLabels)
                {
                    _ShowBaseValueLabels = value;
                    OnPropertyChangedEx("ShowBaseValueLabels", Style.VisualChangeType.Render);
                }
            }
        }
        #endregion
        #region TextFormat
        ///
        /// Gets or sets the format specifier for the label text.
        ///
        [Category("Appearance")]
        [Description("Indicates the format specifier for the label text.")]
        public string TextFormat
        {
            get { return (_TextFormat); }
            set
            {
                if (value != _TextFormat)
                {
                    _TextFormat = value;
                    OnPropertyChangedEx("TextFormat", Style.VisualChangeType.Layout);
                }
            }
        }
        #endregion
        #region IsEmpty
        /// 
        /// Gets whether the style is logically Empty.
        /// 
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Description("Gets whether the style is logically Empty.")]
        public override bool IsEmpty
        {
            get
            {
                return ((_ConnectorColor == Color.Empty) &&
                    (_ConnectorLength == -1) &&
                    (_ConnectorPattern == LinePattern.NotSet) &&
                    (_ConnectorThickness == -1) &&
                    (_DrawConnector == Tbool.NotSet) &&
                    (_MaximumSize == Size.Empty) &&
                    (_MinimumSize == Size.Empty) &&
                    (_Offset == Point.Empty) &&
                    (_Rotation == float.NaN) &&
                    (_ShowBaseValueLabels == Tbool.NotSet) &&
                    (String.IsNullOrEmpty(_TextFormat)) &&
                    (base.IsEmpty == true));
            }
        }
        #endregion
        #endregion
        #region ApplyStyle
        /// 
        /// Applies the style to instance of this style.
        /// 
        /// Style to apply.
        public void ApplyStyle(SeriesLabelVisualStyle style)
        {
            if (style != null)
            {
                base.ApplyStyle(style);
                if (style.ConnectorColor != Color.Empty)
                    _ConnectorColor = style.ConnectorColor;
                if (style.ConnectorLength != -1)
                    _ConnectorLength = style.ConnectorLength;
                if (style.ConnectorPattern != LinePattern.NotSet)
                    _ConnectorPattern = style.ConnectorPattern;
                if (style.ConnectorThickness != -1)
                    _ConnectorThickness = style.ConnectorThickness;
                if (style.DrawConnector != Tbool.NotSet)
                    _DrawConnector = style.DrawConnector;
                if (style.MaximumSize != Size.Empty)
                    _MaximumSize = style.MaximumSize;
                if (style.MinimumSize != Size.Empty)
                    _MinimumSize = style.MinimumSize;
                if (style.Offset != Point.Empty)
                    _Offset = style.Offset;
                if (style.Rotation == float.NaN)
                    _Rotation = style.Rotation;
                if (style.ShowBaseValueLabels == Tbool.NotSet)
                    _ShowBaseValueLabels = style.ShowBaseValueLabels;
                if (String.IsNullOrEmpty(style.TextFormat) == false)
                    _TextFormat = style.TextFormat;
            }
        }
        #endregion
        #region Copy
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        public new SeriesLabelVisualStyle Copy()
        {
            SeriesLabelVisualStyle style = new SeriesLabelVisualStyle();
            CopyTo(style);
            return (style);
        }
        #endregion
        #region CopyTo
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        public void CopyTo(SeriesLabelVisualStyle style)
        {
            base.CopyTo(style);
            style.ConnectorColor = _ConnectorColor;
            style.ConnectorLength = _ConnectorLength;
            style.ConnectorPattern = _ConnectorPattern;
            style.ConnectorThickness = _ConnectorThickness;
            style.DrawConnector = _DrawConnector;
            style.MaximumSize = _MaximumSize;
            style.MinimumSize = _MinimumSize;
            style.Offset = _Offset;
            style.Rotation = _Rotation;
            style.ShowBaseValueLabels = _ShowBaseValueLabels;
            style.TextFormat = _TextFormat;
        }
        #endregion
        #region GetSerialData
        internal override SerialElementCollection GetSerialData(string serialName)
        {
            SerialElementCollection sec = new SerialElementCollection();
            if (serialName != null)
            {
                if (serialName.Equals("") == true)
                    serialName = "SeriesLabelVisualStyle";
                sec.AddStartElement(serialName);
            }
            sec.AddValue("ConnectorColor", ConnectorColor, Color.Empty);
            sec.AddValue("ConnectorLength", ConnectorLength, -1);
            sec.AddValue("ConnectorPattern", ConnectorPattern, LinePattern.NotSet);
            sec.AddValue("ConnectorThickness", ConnectorThickness, -1);
            sec.AddValue("DrawConnector", DrawConnector, Tbool.NotSet);
            sec.AddValue("MaximumSize", MaximumSize, Size.Empty);
            sec.AddValue("MinimumSize", MinimumSize, Size.Empty);
            sec.AddValue("Offset", Offset, Point.Empty);
            sec.AddValue("Rotation", Rotation, float.NaN);
            sec.AddValue("ShowBaseValueLabels", ShowBaseValueLabels, Tbool.NotSet);
            sec.AddValue("TextFormat", TextFormat, null);
            sec.AddElement(base.GetSerialData(null));
            if (serialName != null)
                sec.AddEndElement(serialName);
            return (sec);
        }
        #endregion
        #region PutSerialData
        #region ProcessValue
        internal override void ProcessValue(SerialElement se)
        {
            switch (se.Name)
            {
                case "ConnectorColor":
                    ConnectorColor = se.GetValueColor();
                    break;
                case "ConnectorLength":
                    ConnectorLength = int.Parse(se.StringValue);
                    break;
                case "ConnectorPattern":
                    ConnectorPattern = (LinePattern)se.GetValueEnum(typeof(LinePattern));
                    break;
                case "ConnectorThickness":
                    ConnectorThickness = int.Parse(se.StringValue);
                    break;
                case "DrawConnector":
                    DrawConnector = (Tbool)se.GetValueEnum(typeof(Tbool));
                    break;
                case "MaximumSize":
                    MaximumSize = se.GetValueSize();
                    break;
                case "MinimumSize":
                    MinimumSize = se.GetValueSize();
                    break;
                case "Offset":
                    Offset = se.GetValuePoint();
                    break;
                case "Rotation":
                    Rotation = float.Parse(se.StringValue);
                    break;
                case "ShowBaseValueLabels":
                    ShowBaseValueLabels = (Tbool)se.GetValueEnum(typeof(Tbool));
                    break;
                case "TextFormat":
                    TextFormat = se.StringValue;
                    break;
                default:
                    base.ProcessValue(se);
                    break;
            }
        }
        #endregion
        #endregion
    }
}