326 lines
8.2 KiB
C#

using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar.Charts.Style
{
///<summary>
/// ChartAxisVisualStyles
///</summary>
[TypeConverter(typeof(VisualStylesConverter))]
public class ChartAxisVisualStyles : VisualStyles<ChartAxisVisualStyle>
{
#region Copy
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
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
}
/// <summary>
/// Represents the visual style of a ChartAxis element.
/// </summary>
[TypeConverter(typeof(VisualStylesConverter))]
public class ChartAxisVisualStyle : BaseVisualStyle
{
#region Private variables
private Color _AxisColor = Color.Empty;
private Background _AlternateBackground;
#endregion
#region Public properties
#region AlternateBackground
/// <summary>
/// Gets or sets the alternate, or interlaced, background.
/// </summary>
[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);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeAlternateBackground()
{
return (_AlternateBackground != null && _AlternateBackground.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetAlternateBackground()
{
AlternateBackground = null;
}
#endregion
#region AxisColor
///<summary>
/// Gets or sets the Axis line Color.
///</summary>
[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);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeAxisColor()
{
return (_AxisColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetAxisColor()
{
_AxisColor = Color.Empty;
}
#endregion
#region IsEmpty
/// <summary>
/// Gets whether the style is logically Empty.
/// </summary>
[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
/// <summary>
/// Applies the style to instance of this style.
/// </summary>
/// <param name="style">Style to apply.</param>
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
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public new ChartAxisVisualStyle Copy()
{
ChartAxisVisualStyle style = new ChartAxisVisualStyle();
CopyTo(style);
return (style);
}
#endregion
#region CopyTo
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
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
/// <summary>
/// Dispose
/// </summary>
public override void Dispose()
{
AlternateBackground = null;
base.Dispose();
}
#endregion
}
}