PageRenderTime 17ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Shapes/ViewportShape.cs

#
C# | 82 lines | 61 code | 15 blank | 6 comment | 2 complexity | be305d8ed1bc275935f820894b4f940a MD5 | raw file
Possible License(s): CC-BY-SA-3.0
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Windows;
 6using System.Windows.Shapes;
 7using System.Windows.Media;
 8
 9namespace Microsoft.Research.DynamicDataDisplay.Charts
10{
11	/// <summary>
12	/// Represents a base class for simple shapes with viewport-bound coordinates.
13	/// </summary>
14	public abstract class ViewportShape : Shape, IPlotterElement
15	{
16		static ViewportShape()
17		{
18			Type type = typeof(ViewportShape);
19			Shape.StrokeProperty.AddOwner(type, new FrameworkPropertyMetadata(Brushes.Blue));
20			Shape.StrokeThicknessProperty.AddOwner(type, new FrameworkPropertyMetadata(2.0));
21		}
22
23		/// <summary>
24		/// Initializes a new instance of the <see cref="ViewportShape"/> class.
25		/// </summary>
26		protected ViewportShape() { }
27
28		protected void UpdateUIRepresentation()
29		{
30			if (Plotter == null)
31				return;
32
33			UpdateUIRepresentationCore();
34		}
35		protected virtual void UpdateUIRepresentationCore() { }
36
37		#region IPlotterElement Members
38
39		private Plotter2D plotter;
40		void IPlotterElement.OnPlotterAttached(Plotter plotter)
41		{
42			plotter.CentralGrid.Children.Add(this);
43
44			Plotter2D plotter2d = (Plotter2D)plotter;
45			this.plotter = plotter2d;
46			plotter2d.Viewport.PropertyChanged += Viewport_PropertyChanged;
47
48			UpdateUIRepresentation();
49		}
50
51		private void Viewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e)
52		{
53			OnViewportPropertyChanged(e);
54		}
55
56		protected virtual void OnViewportPropertyChanged(ExtendedPropertyChangedEventArgs e)
57		{
58			UpdateUIRepresentation();
59		}
60
61		void IPlotterElement.OnPlotterDetaching(Plotter plotter)
62		{
63			Plotter2D plotter2d = (Plotter2D)plotter;
64			plotter2d.Viewport.PropertyChanged -= Viewport_PropertyChanged;
65			plotter.CentralGrid.Children.Remove(this);
66
67			this.plotter = null;
68		}
69
70		public Plotter2D Plotter
71		{
72			get { return plotter; }
73		}
74
75		Plotter IPlotterElement.Plotter
76		{
77			get { return plotter; }
78		}
79
80		#endregion
81	}
82}