Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/ContentGraph.cs @ 13777

Last change on this file since 13777 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

File size: 2.2 KB
RevLine 
[12503]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Controls;
6using System.Windows;
7using Microsoft.Research.DynamicDataDisplay.Common;
8
9namespace Microsoft.Research.DynamicDataDisplay.Charts
10{
11  public abstract class ContentGraph : ContentControl, IPlotterElement
12  {
13    static ContentGraph()
14    {
15      EventManager.RegisterClassHandler(typeof(ContentGraph), Plotter.PlotterChangedEvent, new PlotterChangedEventHandler(OnPlotterChanged));
16    }
17
18    private static void OnPlotterChanged(object sender, PlotterChangedEventArgs e)
19    {
20      ContentGraph owner = (ContentGraph)sender;
21      owner.OnPlotterChanged(e);
22    }
23
24    private void OnPlotterChanged(PlotterChangedEventArgs e)
25    {
26      if (plotter == null && e.CurrentPlotter != null)
27      {
28        plotter = (Plotter2D)e.CurrentPlotter;
29        plotter.Viewport.PropertyChanged += Viewport_PropertyChanged;
30        OnPlotterAttached();
31      }
32      if (plotter != null && e.PreviousPlotter != null)
33      {
34        OnPlotterDetaching();
35        plotter.Viewport.PropertyChanged -= Viewport_PropertyChanged;
36        plotter = null;
37      }
38    }
39
40    #region IPlotterElement Members
41
42    private void Viewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e)
43    {
44      OnViewportPropertyChanged(e);
45    }
46
47    protected virtual void OnViewportPropertyChanged(ExtendedPropertyChangedEventArgs e) { }
48
49    protected virtual Panel HostPanel
50    {
51      get { return plotter.CentralGrid; }
52    }
53
54    void IPlotterElement.OnPlotterAttached(Plotter plotter)
55    {
56      this.plotter = (Plotter2D)plotter;
57      HostPanel.Children.Add(this);
58      this.plotter.Viewport.PropertyChanged += Viewport_PropertyChanged;
59
60      OnPlotterAttached();
61    }
62
63    protected virtual void OnPlotterAttached() { }
64
65    void IPlotterElement.OnPlotterDetaching(Plotter plotter)
66    {
67      OnPlotterDetaching();
68
69      this.plotter.Viewport.PropertyChanged -= Viewport_PropertyChanged;
70      HostPanel.Children.Remove(this);
71      this.plotter = null;
72    }
73
74    protected virtual void OnPlotterDetaching() { }
75
76    private Plotter2D plotter;
77    protected Plotter2D Plotter2D
78    {
79      get { return plotter; }
80    }
81
82    Plotter IPlotterElement.Plotter
83    {
84      get { return plotter; }
85    }
86
87    #endregion
88  }
89}
Note: See TracBrowser for help on using the repository browser.