Free cookie consent management tool by TermsFeed Policy Generator

source: branches/histogram/HeuristicLab.Analysis.Views/3.3/HistogramView.cs @ 5970

Last change on this file since 5970 was 5970, checked in by abeham, 13 years ago

#1465

  • Separated HistogramView into a view and a control
  • Added the HistogramControl to ChartControlsExtensions (not yet userfriendly)
File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Windows.Forms;
23using HeuristicLab.Collections;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Analysis.Views {
29  [View("Histogram View")]
30  [Content(typeof(Histogram), IsDefaultView = true)]
31  public sealed partial class HistogramView : NamedItemView {
32
33    public new Histogram Content {
34      get { return (Histogram)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public HistogramView() {
39      InitializeComponent();
40    }
41
42    protected override void DeregisterContentEvents() {
43      Content.Values.ItemsAdded -= new CollectionItemsChangedEventHandler<double>(Content_Values_ItemsAdded);
44      Content.Values.ItemsRemoved -= new CollectionItemsChangedEventHandler<double>(Content_Values_ItemsRemoved);
45      Content.Values.CollectionReset -= new CollectionItemsChangedEventHandler<double>(Content_Values_CollectionReset);
46      base.DeregisterContentEvents();
47    }
48
49    protected override void RegisterContentEvents() {
50      base.RegisterContentEvents();
51      Content.Values.ItemsAdded += new CollectionItemsChangedEventHandler<double>(Content_Values_ItemsAdded);
52      Content.Values.ItemsRemoved += new CollectionItemsChangedEventHandler<double>(Content_Values_ItemsRemoved);
53      Content.Values.CollectionReset += new CollectionItemsChangedEventHandler<double>(Content_Values_CollectionReset);
54    }
55
56    #region Event Handlers (Content)
57    private void Content_Values_ItemsAdded(object sender, CollectionItemsChangedEventArgs<double> e) {
58      histogramControl.AddPoints(e.Items);
59    }
60    private void Content_Values_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<double> e) {
61      histogramControl.ClearPoints();
62      histogramControl.AddPoints(Content.Values);
63    }
64    private void Content_Values_CollectionReset(object sender, CollectionItemsChangedEventArgs<double> e) {
65      histogramControl.ClearPoints();
66      histogramControl.AddPoints(Content.Values);
67    }
68    #endregion
69
70    protected override void OnContentChanged() {
71      base.OnContentChanged();
72      if (Content == null) {
73        histogramControl.ClearPoints();
74      } else {
75        histogramControl.AddPoints(Content.Values);
76      }
77    }
78
79    protected override void SetEnabledStateOfControls() {
80      base.SetEnabledStateOfControls();
81      histogramControl.Enabled = Content != null;
82    }
83
84    #region Event Handlers (child controls)
85    #endregion
86  }
87}
Note: See TracBrowser for help on using the repository browser.