using System.ComponentModel; using System.Drawing; using System.Drawing.Design; using System.Drawing.Drawing2D; namespace DevComponents.DotNetBar.Charts.Style { /// /// Represents the visual style of a Chart Line /// [ToolboxItem(false), DesignTimeVisible(false)] [TypeConverter(typeof(BlankExpandableObjectConverter))] public class ChartLineVisualStyle : BaseVisualStyle { #region Private variables private Color _LineColor = Color.Empty; private LinePattern _LinePattern = LinePattern.NotSet; private int _LineWidth = -1; #endregion #region Public properties #region LineColor /// /// Gets or sets the Line color. /// [Description("Indicates the Line color.")] public Color LineColor { get { return (_LineColor); } set { if (_LineColor != value) { _LineColor = value; OnPropertyChangedEx("LineColor", VisualChangeType.Render); } } } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] private bool ShouldSerializeLineColor() { return (_LineColor.IsEmpty == false); } /// /// Resets property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] private void ResetLineColor() { LineColor = Color.Empty; } #endregion #region LinePattern /// /// Gets or sets the LinePattern. /// [DefaultValue(LinePattern.NotSet)] [Description("Indicates the LinePattern.")] public LinePattern LinePattern { get { return (_LinePattern); } set { if (_LinePattern != value) { _LinePattern = value; OnPropertyChangedEx("LinePattern", VisualChangeType.Render); } } } #endregion #region LineWidth /// /// Gets or sets the line width. /// [DefaultValue(-1)] [Description("Indicates the line width")] public int LineWidth { get { return (_LineWidth); } set { if (_LineWidth != value) { _LineWidth = value; OnPropertyChangedEx("LineWidth", VisualChangeType.Render); } } } #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 ((_LineColor.IsEmpty) && (_LinePattern == LinePattern.NotSet) && (_LineWidth < 0) && (base.IsEmpty == true)); } } #endregion #endregion #region Internal properties internal bool IsDisplayable { get { return (LineColor.IsEmpty == false && LinePattern != LinePattern.None && LineWidth > 0); } } #endregion #region ApplyStyle /// /// Applies the style to instance of this style. /// /// Style to apply. public void ApplyStyle(ChartLineVisualStyle style) { if (style != null) { base.ApplyStyle(style); if (style.LineColor.IsEmpty == false) LineColor = style.LineColor; if (style.LinePattern != LinePattern.NotSet) LinePattern = style.LinePattern; if (style.LineWidth >= 0) LineWidth = style.LineWidth; } } #endregion #region ApplyDefaults public override void ApplyDefaults() { if (LinePattern == LinePattern.NotSet) LinePattern = LinePattern.Solid; if (LineWidth < 0) LineWidth = 1; base.ApplyDefaults(); } #endregion #region Copy /// /// Returns the copy of the style. /// /// Copy of the style. public new ChartLineVisualStyle Copy() { ChartLineVisualStyle style = new ChartLineVisualStyle(); CopyTo(style); return (style); } #endregion #region CopyTo /// /// Returns the copy of the style. /// /// Copy of the style. public void CopyTo(ChartLineVisualStyle style) { base.CopyTo(style); style.LineColor = _LineColor; style.LinePattern = _LinePattern; style.LineWidth = _LineWidth; } #endregion #region GetSerialData internal override SerialElementCollection GetSerialData(string serialName) { SerialElementCollection sec = new SerialElementCollection(); if (serialName != null) { if (serialName.Equals("") == true) serialName = "ChartLineVisualStyle"; sec.AddStartElement(serialName); } sec.AddValue("LineColor", LineColor, Color.Empty); sec.AddValue("LinePattern", LinePattern, LinePattern.NotSet); sec.AddValue("LineWidth", LineWidth, -1); 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 "LineColor": LineColor = se.GetValueColor(); break; case "LinePattern": LinePattern = (LinePattern)se.GetValueEnum(typeof(LinePattern)); break; case "LineWidth": LineWidth = int.Parse(se.StringValue); break; default: base.ProcessValue(se); break; } } #endregion #endregion #region IDisposable /// /// Dispose /// public override void Dispose() { base.Dispose(); } #endregion } /// /// Represents the visual style of a Chart CapLine /// [ToolboxItem(false), DesignTimeVisible(false)] [TypeConverter(typeof(BlankExpandableObjectConverter))] public class ChartCapLineVisualStyle : ChartLineVisualStyle { #region Private variables private ChartLineCap _EndCap = ChartLineCap.NotSet; private ChartLineCap _StartCap = ChartLineCap.NotSet; #endregion #region Public properties #region EndCap /// /// Gets or sets the line EndCap. /// [DefaultValue(ChartLineCap.NotSet)] [Description("Indicates the line End Cap.")] public ChartLineCap EndCap { get { return (_EndCap); } set { if (_EndCap != value) { _EndCap = value; OnPropertyChangedEx("EndCap", VisualChangeType.Render); } } } #endregion #region StartCap /// /// Gets or sets the line StartCap. /// [DefaultValue(ChartLineCap.NotSet)] [Description("Indicates the line Start Cap.")] public ChartLineCap StartCap { get { return (_StartCap); } set { if (_StartCap != value) { _StartCap = value; OnPropertyChangedEx("StartCap", VisualChangeType.Render); } } } #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 ((_EndCap == ChartLineCap.NotSet) && (_StartCap == ChartLineCap.NotSet) && (base.IsEmpty == true)); } } #endregion #endregion #region ApplyStyle /// /// Applies the style to instance of this style. /// /// Style to apply. public void ApplyStyle(ChartCapLineVisualStyle style) { if (style != null) { base.ApplyStyle(style); if (style.EndCap != ChartLineCap.NotSet) _EndCap = style.EndCap; if (style.StartCap != ChartLineCap.NotSet) _StartCap = style.StartCap; } } #endregion #region ApplyDefaults public override void ApplyDefaults() { if (EndCap == ChartLineCap.NotSet) EndCap = ChartLineCap.NoAnchor; if (StartCap == ChartLineCap.NotSet) StartCap = ChartLineCap.NoAnchor; base.ApplyDefaults(); } #endregion #region Copy /// /// Returns the copy of the style. /// /// Copy of the style. public new ChartCapLineVisualStyle Copy() { ChartCapLineVisualStyle style = new ChartCapLineVisualStyle(); CopyTo(style); return (style); } #endregion #region CopyTo /// /// Returns the copy of the style. /// /// Copy of the style. public void CopyTo(ChartCapLineVisualStyle style) { base.CopyTo(style); style.EndCap = _EndCap; style.StartCap = _StartCap; } #endregion #region GetSerialData internal override SerialElementCollection GetSerialData(string serialName) { SerialElementCollection sec = new SerialElementCollection(); if (serialName != null) { if (serialName.Equals("") == true) serialName = "ChartCapLineVisualStyle"; sec.AddStartElement(serialName); } sec.AddValue("EndCap", EndCap, ChartLineCap.NotSet); sec.AddValue("StartCap", StartCap, ChartLineCap.NotSet); 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 "EndCap": EndCap = (ChartLineCap)se.GetValueEnum(typeof(ChartLineCap)); break; case "StartCap": StartCap = (ChartLineCap)se.GetValueEnum(typeof(ChartLineCap)); break; default: base.ProcessValue(se); break; } } #endregion #endregion #region IDisposable /// /// Dispose /// public override void Dispose() { base.Dispose(); } #endregion } }