1 | using System.Windows;
|
---|
2 | using System;
|
---|
3 | using System.ComponentModel;
|
---|
4 |
|
---|
5 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
6 | {
|
---|
7 | /// <summary>
|
---|
8 | /// Main interface of DynamicDataDisplay - each item that is going to be added to Plotter should implement it.
|
---|
9 | /// Contains methods that are called by parent plotter when item is added to it or removed from it.
|
---|
10 | /// </summary>
|
---|
11 | public interface IPlotterElement
|
---|
12 | {
|
---|
13 | /// <summary>
|
---|
14 | /// Called when parent plotter is attached.
|
---|
15 | /// Allows to, for example, add custom UI parts to ChartPlotter's visual tree or subscribe to ChartPlotter's events.
|
---|
16 | /// </summary>
|
---|
17 | /// <param name="plotter">The parent plotter.</param>
|
---|
18 | void OnPlotterAttached(Plotter plotter);
|
---|
19 | /// <summary>
|
---|
20 | /// Called when item is being detached from parent plotter.
|
---|
21 | /// Allows to remove added in OnPlotterAttached method UI parts or unsubscribe from events.
|
---|
22 | /// This should be done as each chart can be added only one Plotter at one moment of time.
|
---|
23 | /// </summary>
|
---|
24 | /// <param name="plotter">The plotter.</param>
|
---|
25 | void OnPlotterDetaching(Plotter plotter);
|
---|
26 | /// <summary>
|
---|
27 | /// Gets the parent plotter of chart.
|
---|
28 | /// Should be equal to null if item is not connected to any plotter.
|
---|
29 | /// </summary>
|
---|
30 | /// <value>The plotter.</value>
|
---|
31 | Plotter Plotter { get; }
|
---|
32 | }
|
---|
33 |
|
---|
34 | /// <summary>
|
---|
35 | /// One of the simplest implementations of IPlotterElement interface.
|
---|
36 | /// Derives from FrameworkElement.
|
---|
37 | /// </summary>
|
---|
38 | public abstract class PlotterElement : FrameworkElement, IPlotterElement
|
---|
39 | {
|
---|
40 | /// <summary>
|
---|
41 | /// Initializes a new instance of the <see cref="PlotterElement"/> class.
|
---|
42 | /// </summary>
|
---|
43 | protected PlotterElement() { }
|
---|
44 |
|
---|
45 | private Plotter plotter;
|
---|
46 | /// <summary>
|
---|
47 | /// Gets the parent plotter of chart.
|
---|
48 | /// Should be equal to null if item is not connected to any plotter.
|
---|
49 | /// </summary>
|
---|
50 | /// <value>The plotter.</value>
|
---|
51 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
---|
52 | public Plotter Plotter
|
---|
53 | {
|
---|
54 | get { return plotter; }
|
---|
55 | }
|
---|
56 |
|
---|
57 | /// <summary>This method is invoked when element is attached to plotter. It is the place
|
---|
58 | /// to put additional controls to Plotter</summary>
|
---|
59 | /// <param name="plotter">Plotter for this element</param>
|
---|
60 | protected virtual void OnPlotterAttached(Plotter plotter)
|
---|
61 | {
|
---|
62 | this.plotter = plotter;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /// <summary>This method is invoked when element is being detached from plotter. If additional
|
---|
66 | /// controls were put on plotter in OnPlotterAttached method, they should be removed here</summary>
|
---|
67 | /// <remarks>This method is always called in pair with OnPlotterAttached</remarks>
|
---|
68 | protected virtual void OnPlotterDetaching(Plotter plotter)
|
---|
69 | {
|
---|
70 | this.plotter = null;
|
---|
71 | }
|
---|
72 |
|
---|
73 | #region IPlotterElement Members
|
---|
74 |
|
---|
75 | void IPlotterElement.OnPlotterAttached(Plotter plotter)
|
---|
76 | {
|
---|
77 | OnPlotterAttached(plotter);
|
---|
78 | }
|
---|
79 |
|
---|
80 | void IPlotterElement.OnPlotterDetaching(Plotter plotter)
|
---|
81 | {
|
---|
82 | OnPlotterDetaching(plotter);
|
---|
83 | }
|
---|
84 |
|
---|
85 | #endregion
|
---|
86 | }
|
---|
87 | } |
---|