129 lines
3.3 KiB
C#
129 lines
3.3 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.Design;
|
|
using System.Reflection;
|
|
using DevComponents.DotNetBar.Charts;
|
|
|
|
namespace DevComponents.Charts.Design
|
|
{
|
|
public class IndicatorCollectionEditor : BaseCollectionEditor
|
|
{
|
|
#region Private variables
|
|
|
|
private ChartSeries _ChartSeries;
|
|
|
|
#endregion
|
|
|
|
public IndicatorCollectionEditor(Type type)
|
|
: base(type)
|
|
{
|
|
}
|
|
|
|
#region EditValue
|
|
|
|
public override object EditValue(
|
|
ITypeDescriptorContext context, IServiceProvider provider, object value)
|
|
{
|
|
_ChartSeries = context.Instance as ChartSeries;
|
|
|
|
return (base.EditValue(context, provider, value));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CreateInstance
|
|
|
|
protected override object CreateInstance(Type itemType)
|
|
{
|
|
if (itemType == typeof(RegressionLine))
|
|
{
|
|
RegressionLine regLine = (RegressionLine)base.CreateInstance(itemType);
|
|
|
|
if (_ChartSeries != null)
|
|
regLine.Name = _ChartSeries.ChartIndicators.GetUniqueName("RegLine");
|
|
|
|
return (regLine);
|
|
}
|
|
|
|
if (itemType == typeof(TrendLine))
|
|
{
|
|
TrendLine trendLine = (TrendLine)base.CreateInstance(itemType);
|
|
|
|
if (_ChartSeries != null)
|
|
trendLine.Name = _ChartSeries.ChartIndicators.GetUniqueName("TrendLine");
|
|
|
|
return (trendLine);
|
|
}
|
|
|
|
return (base.CreateInstance(itemType));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CopyButton_Click
|
|
|
|
protected override void CopyButton_Click(object sender, EventArgs e)
|
|
{
|
|
ChartIndicator item = ChartItem as ChartIndicator;
|
|
|
|
if (item != null)
|
|
{
|
|
if (AddButton != null)
|
|
{
|
|
ChartControlDesigner ccd = GetDesigner(_ChartSeries.ChartControl);
|
|
ChartIndicatorCollection cic = _ChartSeries.ChartIndicators;
|
|
|
|
ccd.InCopyItem = true;
|
|
|
|
if (item is RegressionLine)
|
|
_ItemTypes[0] = typeof(RegressionLine);
|
|
|
|
try
|
|
{
|
|
AddButton.PerformClick();
|
|
|
|
ChartIndicator clone = (ChartIndicator)cic[cic.Count - 1];
|
|
|
|
string name = clone.Name;
|
|
item.CopyTo(clone);
|
|
clone.Name = name;
|
|
}
|
|
finally
|
|
{
|
|
if (item is RegressionLine)
|
|
_ItemTypes[0] = typeof(TrendLine);
|
|
|
|
ccd.InCopyItem = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CreateCollectionItemType
|
|
|
|
protected override Type CreateCollectionItemType()
|
|
{
|
|
return typeof(ChartIndicator);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region CreateNewItemTypes
|
|
|
|
private Type[] _ItemTypes = new Type[]
|
|
{
|
|
typeof(TrendLine),
|
|
typeof(RegressionLine),
|
|
};
|
|
|
|
protected override Type[] CreateNewItemTypes()
|
|
{
|
|
return (_ItemTypes);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|