using System.Windows;
using System;
using System.ComponentModel;
namespace Microsoft.Research.DynamicDataDisplay
{
///
/// Main interface of DynamicDataDisplay - each item that is going to be added to Plotter should implement it.
/// Contains methods that are called by parent plotter when item is added to it or removed from it.
///
public interface IPlotterElement
{
///
/// Called when parent plotter is attached.
/// Allows to, for example, add custom UI parts to ChartPlotter's visual tree or subscribe to ChartPlotter's events.
///
/// The parent plotter.
void OnPlotterAttached(Plotter plotter);
///
/// Called when item is being detached from parent plotter.
/// Allows to remove added in OnPlotterAttached method UI parts or unsubscribe from events.
/// This should be done as each chart can be added only one Plotter at one moment of time.
///
/// The plotter.
void OnPlotterDetaching(Plotter plotter);
///
/// Gets the parent plotter of chart.
/// Should be equal to null if item is not connected to any plotter.
///
/// The plotter.
Plotter Plotter { get; }
}
///
/// One of the simplest implementations of IPlotterElement interface.
/// Derives from FrameworkElement.
///
public abstract class PlotterElement : FrameworkElement, IPlotterElement
{
///
/// Initializes a new instance of the class.
///
protected PlotterElement() { }
private Plotter plotter;
///
/// Gets the parent plotter of chart.
/// Should be equal to null if item is not connected to any plotter.
///
/// The plotter.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Plotter Plotter
{
get { return plotter; }
}
/// This method is invoked when element is attached to plotter. It is the place
/// to put additional controls to Plotter
/// Plotter for this element
protected virtual void OnPlotterAttached(Plotter plotter)
{
this.plotter = plotter;
}
/// This method is invoked when element is being detached from plotter. If additional
/// controls were put on plotter in OnPlotterAttached method, they should be removed here
/// This method is always called in pair with OnPlotterAttached
protected virtual void OnPlotterDetaching(Plotter plotter)
{
this.plotter = null;
}
#region IPlotterElement Members
void IPlotterElement.OnPlotterAttached(Plotter plotter)
{
OnPlotterAttached(plotter);
}
void IPlotterElement.OnPlotterDetaching(Plotter plotter)
{
OnPlotterDetaching(plotter);
}
#endregion
}
}