[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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.Common;
|
---|
| 31 | using System.Reflection;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.MainForm.WindowsForms {
|
---|
| 34 | public partial class ContentView : View, IContentView {
|
---|
| 35 | private IContent content;
|
---|
| 36 | public IContent Content {
|
---|
| 37 | get { return content; }
|
---|
| 38 | set {
|
---|
[3557] | 39 | if ((value != null) && (!MainFormManager.ViewCanViewContent(this, value)))
|
---|
[3437] | 40 | throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name));
|
---|
| 41 | if (InvokeRequired) {
|
---|
| 42 | Invoke(new Action<IContent>(delegate(IContent o) { this.Content = o; }), value);
|
---|
| 43 | } else {
|
---|
| 44 | if (this.content != value) {
|
---|
| 45 | if (this.content != null) this.DeregisterContentEvents();
|
---|
| 46 | this.content = value;
|
---|
| 47 | if (this.content != null) this.RegisterContentEvents();
|
---|
| 48 | this.OnContentChanged();
|
---|
[3483] | 49 | this.OnChanged();
|
---|
[3437] | 50 | }
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public ContentView()
|
---|
| 56 | : base() {
|
---|
| 57 | InitializeComponent();
|
---|
| 58 | this.locked = false;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | private bool locked;
|
---|
| 62 | public virtual bool Locked {
|
---|
| 63 | get { return this.locked; }
|
---|
| 64 | set {
|
---|
| 65 | if (InvokeRequired) {
|
---|
| 66 | Action<bool> action = delegate(bool b) { this.Locked = b; };
|
---|
| 67 | Invoke(action, value);
|
---|
| 68 | } else {
|
---|
| 69 | if (value != locked) {
|
---|
| 70 | locked = value;
|
---|
| 71 | PropertyInfo prop = typeof(IContentView).GetProperty("Locked");
|
---|
| 72 | PropagateStateChanges(this, typeof(IContentView), prop);
|
---|
| 73 | OnLockedChanged();
|
---|
| 74 | OnChanged();
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | public event EventHandler LockedChanged;
|
---|
| 80 | protected virtual void OnLockedChanged() {
|
---|
| 81 | if (InvokeRequired)
|
---|
| 82 | Invoke((MethodInvoker)OnLockedChanged);
|
---|
| 83 | else {
|
---|
| 84 | EventHandler handler = LockedChanged;
|
---|
| 85 | if (handler != null)
|
---|
| 86 | handler(this, EventArgs.Empty);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | /// <summary>
|
---|
| 91 | /// Adds eventhandlers to the current instance.
|
---|
| 92 | /// </summary>
|
---|
| 93 | protected virtual void RegisterContentEvents() {
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | /// <summary>
|
---|
| 97 | /// Removes the eventhandlers from the current instance.
|
---|
| 98 | /// </summary>
|
---|
| 99 | protected virtual void DeregisterContentEvents() {
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | /// <summary>
|
---|
| 103 | /// Is called when the content property changes.
|
---|
| 104 | /// </summary>
|
---|
| 105 | protected virtual void OnContentChanged() {
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | }
|
---|