461 lines
12 KiB
C#
461 lines
12 KiB
C#
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Drawing.Design;
|
|
using System.Windows.Forms;
|
|
|
|
namespace DevComponents.DotNetBar.Charts.Style
|
|
{
|
|
/// <summary>
|
|
/// Represents a ReferenceLineVisualStyle.
|
|
/// </summary>
|
|
[TypeConverter(typeof(VisualStylesConverter))]
|
|
public class ReferenceLineVisualStyle : ChartLineVisualStyle
|
|
{
|
|
#region Private variables
|
|
|
|
private Alignment _TextAlignment = Alignment.NotSet;
|
|
private Tbool _AllowWrap = Tbool.NotSet;
|
|
private Color _TextColor = Color.Empty;
|
|
private Padding _TextPadding;
|
|
private Font _Font;
|
|
|
|
#endregion
|
|
|
|
#region Public properties
|
|
|
|
#region AllowWrap
|
|
|
|
/// <summary>
|
|
/// Gets or sets whether text wrapping is permitted
|
|
/// </summary>
|
|
[DefaultValue(Tbool.NotSet), Category("Appearance")]
|
|
[Description("Indicates whether text wrapping is permitted.")]
|
|
public Tbool AllowWrap
|
|
{
|
|
get { return (_AllowWrap); }
|
|
|
|
set
|
|
{
|
|
if (_AllowWrap != value)
|
|
{
|
|
_AllowWrap = value;
|
|
|
|
OnPropertyChangedEx("AllowWrap", VisualChangeType.Render);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Font
|
|
|
|
/// <summary>
|
|
/// Gets or sets the style Font
|
|
/// </summary>
|
|
[DefaultValue(null)]
|
|
[Description("Indicates the style Font")]
|
|
public Font Font
|
|
{
|
|
get { return (_Font); }
|
|
|
|
set
|
|
{
|
|
if (_Font != value)
|
|
{
|
|
_Font = value;
|
|
|
|
OnPropertyChangedEx("Font", VisualChangeType.Layout);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region TextAlignment
|
|
|
|
///<summary>
|
|
/// Gets or sets the Text alignment.
|
|
///</summary>
|
|
[DefaultValue(Alignment.NotSet), Category("Appearance")]
|
|
[Description("Indicates the Text alignment.")]
|
|
public Alignment TextAlignment
|
|
{
|
|
get { return (_TextAlignment); }
|
|
|
|
set
|
|
{
|
|
if (value != _TextAlignment)
|
|
{
|
|
_TextAlignment = value;
|
|
|
|
OnPropertyChangedEx("TextAlignment", VisualChangeType.Render);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region TextColor
|
|
|
|
///<summary>
|
|
/// Gets or sets the Reference Line Text Color.
|
|
///</summary>
|
|
[Category("Appearance")]
|
|
[Description("Indicates the Reference Line Text Color.")]
|
|
public Color TextColor
|
|
{
|
|
get { return (_TextColor); }
|
|
|
|
set
|
|
{
|
|
if (value != _TextColor)
|
|
{
|
|
_TextColor = value;
|
|
|
|
OnPropertyChangedEx("TextColor", Style.VisualChangeType.Render);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets whether property should be serialized.
|
|
/// </summary>
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public bool ShouldSerializeTextColor()
|
|
{
|
|
return (_TextColor.IsEmpty == false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets property to its default value.
|
|
/// </summary>
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public void ResetTextColor()
|
|
{
|
|
_TextColor = Color.Empty;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region TextPadding
|
|
|
|
/// <summary>
|
|
/// Gets or sets spacing between the content and edges of the Text.
|
|
/// </summary>
|
|
[Description("Indicates the spacing between the content and edges of the Text")]
|
|
public Padding TextPadding
|
|
{
|
|
get
|
|
{
|
|
if (_TextPadding == null)
|
|
{
|
|
_TextPadding = Padding.Empty;
|
|
|
|
UpdateChangeHandler(null, _TextPadding);
|
|
}
|
|
|
|
return (_TextPadding);
|
|
}
|
|
|
|
set
|
|
{
|
|
if (_TextPadding != value)
|
|
{
|
|
UpdateChangeHandler(_TextPadding, value);
|
|
|
|
_TextPadding = value;
|
|
|
|
OnPropertyChangedEx("TextPadding", VisualChangeType.Render);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets whether property should be serialized.
|
|
/// </summary>
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
private bool ShouldSerializeTextPadding()
|
|
{
|
|
return (_TextPadding != null && _TextPadding.IsEmpty == false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resets property to its default value.
|
|
/// </summary>
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
private void ResetTextPadding()
|
|
{
|
|
TextPadding = null;
|
|
}
|
|
|
|
#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 ((_AllowWrap == Tbool.NotSet) &&
|
|
(_Font == null) &&
|
|
(_TextAlignment == Alignment.NotSet) &&
|
|
(_TextColor.IsEmpty == true) &&
|
|
(_TextPadding == null || _TextPadding.IsEmpty == true) &&
|
|
(base.IsEmpty == true));
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region GetStringFormatFlags
|
|
|
|
internal void GetStringFormatFlags(StringFormat sf)
|
|
{
|
|
if (AllowWrap == Tbool.False)
|
|
{
|
|
sf.FormatFlags |= StringFormatFlags.NoWrap;
|
|
sf.Trimming = StringTrimming.None;
|
|
}
|
|
|
|
switch (TextAlignment)
|
|
{
|
|
case Alignment.TopLeft:
|
|
sf.Alignment = StringAlignment.Near;
|
|
break;
|
|
|
|
case Alignment.TopCenter:
|
|
sf.Alignment = StringAlignment.Center;
|
|
break;
|
|
|
|
case Alignment.TopRight:
|
|
sf.Alignment = StringAlignment.Far;
|
|
break;
|
|
|
|
case Alignment.MiddleLeft:
|
|
sf.Alignment = StringAlignment.Near;
|
|
break;
|
|
|
|
case Alignment.MiddleCenter:
|
|
sf.Alignment = StringAlignment.Center;
|
|
break;
|
|
|
|
case Alignment.MiddleRight:
|
|
sf.Alignment = StringAlignment.Far;
|
|
break;
|
|
|
|
case Alignment.BottomLeft:
|
|
sf.Alignment = StringAlignment.Near;
|
|
break;
|
|
|
|
case Alignment.BottomCenter:
|
|
sf.Alignment = StringAlignment.Center;
|
|
break;
|
|
|
|
case Alignment.BottomRight:
|
|
sf.Alignment = StringAlignment.Far;
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ApplyStyle
|
|
|
|
/// <summary>
|
|
/// Applies the style to instance of this style.
|
|
/// </summary>
|
|
/// <param name="style">Style to apply.</param>
|
|
public void ApplyStyle(ReferenceLineVisualStyle style)
|
|
{
|
|
if (style != null)
|
|
{
|
|
base.ApplyStyle(style);
|
|
|
|
if (style.AllowWrap != Tbool.NotSet)
|
|
_AllowWrap = style.AllowWrap;
|
|
|
|
if (style.Font != null)
|
|
_Font = (Font)style.Font.Clone();
|
|
|
|
if (style.TextAlignment != Alignment.NotSet)
|
|
_TextAlignment = style.TextAlignment;
|
|
|
|
if (style.TextColor.IsEmpty == false)
|
|
_TextColor = style.TextColor;
|
|
|
|
if (style._TextPadding != null && style._TextPadding.IsEmpty == false)
|
|
TextPadding = style.TextPadding.Copy();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Copy
|
|
|
|
/// <summary>
|
|
/// Returns the copy of the style.
|
|
/// </summary>
|
|
/// <returns>Copy of the style.</returns>
|
|
public new ReferenceLineVisualStyle Copy()
|
|
{
|
|
ReferenceLineVisualStyle style = new ReferenceLineVisualStyle();
|
|
|
|
CopyTo(style);
|
|
|
|
return (style);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CopyTo
|
|
|
|
/// <summary>
|
|
/// Returns the copy of the style.
|
|
/// </summary>
|
|
/// <returns>Copy of the style.</returns>
|
|
public void CopyTo(ReferenceLineVisualStyle style)
|
|
{
|
|
base.CopyTo(style);
|
|
|
|
style.AllowWrap = _AllowWrap;
|
|
|
|
style.Font = (_Font != null) ? (Font)_Font.Clone() : null;
|
|
|
|
style.TextAlignment = _TextAlignment;
|
|
style.TextColor = _TextColor;
|
|
|
|
style.TextPadding = (_TextPadding != null) ? _TextPadding.Copy() : null;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetSerialData
|
|
|
|
internal override SerialElementCollection GetSerialData(string serialName)
|
|
{
|
|
SerialElementCollection sec = new SerialElementCollection();
|
|
|
|
if (serialName != null)
|
|
{
|
|
if (serialName.Equals("") == true)
|
|
serialName = "ReferenceLineVisualStyle";
|
|
|
|
sec.AddStartElement(serialName);
|
|
}
|
|
|
|
sec.AddValue("AllowWrap", AllowWrap, Tbool.NotSet);
|
|
|
|
if (_Font != null)
|
|
sec.AddValue("Font", XmlSerializableFont.ConvertToString(Font));
|
|
|
|
sec.AddValue("TextAlignment", TextAlignment, Alignment.NotSet);
|
|
sec.AddValue("TextColor", TextColor, Color.Empty);
|
|
|
|
if (_TextPadding != null && _TextPadding.IsEmpty == false)
|
|
sec.AddElement(_TextPadding.GetSerialData("TextPadding"));
|
|
|
|
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 "AllowWrap":
|
|
AllowWrap = (Tbool)se.GetValueEnum(typeof(Tbool));
|
|
break;
|
|
|
|
case "Font":
|
|
Font = XmlSerializableFont.ConvertFromString(se.StringValue);
|
|
break;
|
|
|
|
case "TextAlignment":
|
|
TextAlignment = (Alignment)se.GetValueEnum(typeof(Alignment));
|
|
break;
|
|
|
|
case "TextColor":
|
|
TextColor = 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 "TextPadding":
|
|
sec.PutSerialData(TextPadding);
|
|
break;
|
|
|
|
default:
|
|
base.ProcessCollection(se);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region IDisposable
|
|
|
|
/// <summary>
|
|
/// Dispose
|
|
/// </summary>
|
|
public override void Dispose()
|
|
{
|
|
TextPadding = null;
|
|
|
|
base.Dispose();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#region enums
|
|
|
|
#region NearAlignment
|
|
|
|
public enum NearAlignment
|
|
{
|
|
NotSet = -1,
|
|
|
|
Near,
|
|
|
|
Far,
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|