using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar.Charts.Style
{
    ///
    /// ChartAxisVisualStyles
    ///
    [TypeConverter(typeof(VisualStylesConverter))]
    public class ChartAxisVisualStyles : VisualStyles
    {
        #region Copy
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        public ChartAxisVisualStyles Copy()
        {
            ChartAxisVisualStyles styles = new ChartAxisVisualStyles();
            for (int i = 0; i < Styles.Length; i++)
            {
                ChartAxisVisualStyle vstyle = Styles[i];
                if (vstyle != null)
                    styles.Styles[i] = vstyle.Copy();
            }
            return (styles);
        }
        #endregion
    }
    /// 
    /// Represents the visual style of a ChartAxis element.
    /// 
    [TypeConverter(typeof(VisualStylesConverter))]
    public class ChartAxisVisualStyle : BaseVisualStyle
    {
        #region Private variables
        private Color _AxisColor = Color.Empty;
        private Background _AlternateBackground;
        #endregion
        #region Public properties
        #region AlternateBackground
        /// 
        /// Gets or sets the alternate, or interlaced, background.
        /// 
        [Description("Indicates the alternate, or interlaced, background")]
        public Background AlternateBackground
        {
            get
            {
                if (_AlternateBackground == null)
                {
                    _AlternateBackground = Background.Empty;
                    UpdateChangeHandler(null, _AlternateBackground);
                }
                return (_AlternateBackground);
            }
            set
            {
                if (_AlternateBackground != value)
                {
                    UpdateChangeHandler(_AlternateBackground, value);
                    _AlternateBackground = value;
                    OnPropertyChangedEx("AlternateBackground", VisualChangeType.Render);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private bool ShouldSerializeAlternateBackground()
        {
            return (_AlternateBackground != null && _AlternateBackground.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        private void ResetAlternateBackground()
        {
            AlternateBackground = null;
        }
        #endregion
        #region AxisColor
        ///
        /// Gets or sets the Axis line Color.
        ///
        [Category("Appearance")]
        [Description("Indicates the Axis line Color.")]
        public Color AxisColor
        {
            get { return (_AxisColor); }
            set
            {
                if (value != _AxisColor)
                {
                    _AxisColor = value;
                    OnPropertyChangedEx("AxisColor", Style.VisualChangeType.Render);
                }
            }
        }
        /// 
        /// Gets whether property should be serialized.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        public bool ShouldSerializeAxisColor()
        {
            return (_AxisColor.IsEmpty == false);
        }
        /// 
        /// Resets property to its default value.
        /// 
        [EditorBrowsable(EditorBrowsableState.Never)]
        public void ResetAxisColor()
        {
            _AxisColor = Color.Empty;
        }
        #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 ((_AlternateBackground == null || _AlternateBackground.IsEmpty) &&
                    (_AxisColor.IsEmpty == true) &&
                    (base.IsEmpty == true));
            }
        }
        #endregion
        #endregion
        #region ApplyStyle
        /// 
        /// Applies the style to instance of this style.
        /// 
        /// Style to apply.
        public void ApplyStyle(ChartAxisVisualStyle style)
        {
            if (style != null)
            {
                base.ApplyStyle(style);
                if (style._AlternateBackground != null && style.AlternateBackground.IsEmpty == false)
                    AlternateBackground = style.AlternateBackground.Copy();
                if (style.AxisColor.IsEmpty == false)
                    AxisColor = style.AxisColor;
            }
        }
        #endregion
        #region ApplyDefaults
        public override void ApplyDefaults()
        {
            if (AxisColor.IsEmpty == true)
                AxisColor = Color.Black;
            if (AlternateBackground.IsEmpty == true)
                AlternateBackground = new Background(Color.Ivory);
            base.ApplyDefaults();
        }
        #endregion
        #region Copy
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        public new ChartAxisVisualStyle Copy()
        {
            ChartAxisVisualStyle style = new ChartAxisVisualStyle();
            CopyTo(style);
            return (style);
        }
        #endregion
        #region CopyTo
        /// 
        /// Returns the copy of the style.
        /// 
        /// Copy of the style.
        public void CopyTo(ChartAxisVisualStyle style)
        {
            base.CopyTo(style);
            style.AlternateBackground = 
                (_AlternateBackground != null) ? _AlternateBackground.Copy() : null;
            style.AxisColor = _AxisColor;
        }
        #endregion
        #region GetSerialData
        internal override SerialElementCollection GetSerialData(string serialName)
        {
            SerialElementCollection sec = new SerialElementCollection();
            if (serialName != null)
            {
                if (serialName.Equals("") == true)
                    serialName = "ChartAxisVisualStyle";
                sec.AddStartElement(serialName);
            }
            if (_AlternateBackground != null && _AlternateBackground.IsEmpty == false)
                sec.AddElement(_AlternateBackground.GetSerialData("AlternateBackground"));
            sec.AddValue("AxisColor", AxisColor, Color.Empty);
            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 "AxisColor":
                    AxisColor = se.GetValueColor();
                    break;
                default:
                    base.ProcessValue(se);
                    break;
            }
        }
        #endregion
        #region ProcessCollection
        internal override void ProcessCollection(SerialElement se)
        {
            SerialElementCollection sec = se.Sec;
            switch (se.Name)
            {
                case "AlternateBackground":
                    sec.PutSerialData(AlternateBackground);
                    break;
                default:
                    base.ProcessCollection(se);
                    break;
            }
        }
        #endregion
        #endregion
        #region IDisposable
        /// 
        /// Dispose
        /// 
        public override void Dispose()
        {
            AlternateBackground = null;
            base.Dispose();
        }
        #endregion
    }
}