603 lines
17 KiB
C#

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
{
/// <summary>
/// Represents a SeriesLabelVisualStyle.
/// </summary>
[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
/// <summary>
/// Gets or sets the style border color.
/// </summary>
[Description("Indicates the style Border Color")]
public Color ConnectorColor
{
get { return (_ConnectorColor); }
set
{
if (value != _ConnectorColor)
{
_ConnectorColor = value;
OnPropertyChangedEx("ConnectorColor", VisualChangeType.Render);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeConnectorColor()
{
return (_ConnectorColor.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetConnectorColor()
{
_ConnectorColor = Color.Empty;
}
#endregion
#region ConnectorLength
/// <summary>
/// Gets or sets the length of the line connecting the slice
/// and the slice label.
/// </summary>
[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
/// <summary>
/// Gets or sets the style border pattern (Solid, Dash, ...)
/// </summary>
[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
/// <summary>
/// Gets or sets the style border thickness.
/// </summary>
[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
///<summary>
/// Gets or sets whether a connecting line is drawn to the data point.
///</summary>
[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
/// <summary>
/// Gets or sets the maximum size of the label.
/// </summary>
[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);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeCMaximumSize()
{
return (_MaximumSize.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetMaximumSize()
{
MaximumSize = Size.Empty;
}
#endregion
#region MinimumSize
/// <summary>
/// Gets or sets the minimum size of the label.
/// </summary>
[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);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeMinimumSize()
{
return (_MinimumSize.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetMinimumSize()
{
MinimumSize = Size.Empty;
}
#endregion
#region Offset
///<summary>
/// Gets or sets the offset of the label relative to the data point.
///</summary>
[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);
}
}
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private bool ShouldSerializeOffset()
{
return (_Offset.IsEmpty == false);
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
private void ResetOffset()
{
Offset = Point.Empty;
}
#endregion
#region Rotation
///<summary>
/// Gets or sets the amount to rotate the label body.
///</summary>
[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
///<summary>
/// Gets or sets whether Labels are shown for Base Values.
///</summary>
[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
///<summary>
/// Gets or sets the format specifier for the label text.
///</summary>
[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
/// <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 ((_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
/// <summary>
/// Applies the style to instance of this style.
/// </summary>
/// <param name="style">Style to apply.</param>
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
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public new SeriesLabelVisualStyle Copy()
{
SeriesLabelVisualStyle style = new SeriesLabelVisualStyle();
CopyTo(style);
return (style);
}
#endregion
#region CopyTo
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
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
}
}