Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ContentView.cs @ 4046

Last change on this file since 4046 was 3915, checked in by mkommend, 14 years ago

implemented InteractiveSymbolicRegressionSolutionSimplifierView and fixed lots of minor bugs in the DataAnalysis and DataAnalysis.Views project (ticket #1010)

File size: 4.1 KB
RevLine 
[3437]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Common;
31using System.Reflection;
32
33namespace HeuristicLab.MainForm.WindowsForms {
34  public partial class ContentView : View, IContentView {
[3566]35    public ContentView()
36      : base() {
37      InitializeComponent();
38      this.locked = false;
39    }
40
[3437]41    private IContent content;
42    public IContent Content {
43      get { return content; }
44      set {
[3915]45        //check if the ContentView is tagged with a corresponding ContentAttribute for the type of the Content
46        if ((value != null) && (!MainFormManager.ViewCanViewContent(this, value)) &&
47          ContentAttribute.HasContentAttribute(this.GetType()))
[3437]48          throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name));
49        if (InvokeRequired) {
50          Invoke(new Action<IContent>(delegate(IContent o) { this.Content = o; }), value);
51        } else {
52          if (this.content != value) {
[3727]53            this.SuspendRepaint();
[3437]54            if (this.content != null) this.DeregisterContentEvents();
55            this.content = value;
56            if (this.content != null) this.RegisterContentEvents();
57            this.OnContentChanged();
[3904]58            this.SetEnabledStateOfControls();
[3483]59            this.OnChanged();
[3727]60            this.ResumeRepaint(true);
[3437]61          }
62        }
63      }
64    }
65
66    private bool locked;
67    public virtual bool Locked {
68      get { return this.locked; }
69      set {
70        if (InvokeRequired) {
71          Action<bool> action = delegate(bool b) { this.Locked = b; };
72          Invoke(action, value);
73        } else {
74          if (value != locked) {
[3727]75            this.SuspendRepaint();
[3437]76            locked = value;
[3788]77            OnLockedChanged();
[3904]78            this.SetEnabledStateOfControls();
[3437]79            PropertyInfo prop = typeof(IContentView).GetProperty("Locked");
80            PropagateStateChanges(this, typeof(IContentView), prop);
81            OnChanged();
[3727]82            this.ResumeRepaint(true);
[3437]83          }
84        }
85      }
86    }
87    public event EventHandler LockedChanged;
88    protected virtual void OnLockedChanged() {
89      if (InvokeRequired)
90        Invoke((MethodInvoker)OnLockedChanged);
91      else {
92        EventHandler handler = LockedChanged;
93        if (handler != null)
94          handler(this, EventArgs.Empty);
95      }
96    }
97    /// <summary>
98    /// Adds eventhandlers to the current instance.
99    /// </summary>
100    protected virtual void RegisterContentEvents() {
101    }
102
103    /// <summary>
104    /// Removes the eventhandlers from the current instance.
105    /// </summary>
106    protected virtual void DeregisterContentEvents() {
107    }
108
109    /// <summary>
110    /// Is called when the content property changes.
111    /// </summary>
112    protected virtual void OnContentChanged() {
113    }
[3904]114
115    /// <summary>
116    /// This method is called if the ReadyOnly, Locked or Content property of the ContentView changes to update the controls of the view.
117    /// </summary>
118    protected override void SetEnabledStateOfControls() {
119    }
[3437]120  }
121}
Note: See TracBrowser for help on using the repository browser.