Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4418 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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