Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/ItemView.cs @ 2949

Last change on this file since 2949 was 2917, checked in by swagner, 14 years ago

Operator architecture refactoring (#95)

  • implemented reviewers' comments
File size: 3.0 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 HeuristicLab.MainForm;
24using HeuristicLab.MainForm.WindowsForms;
25
26namespace HeuristicLab.Core.Views {
27  /// <summary>
28  /// Base class for all visual representations.
29  /// </summary>
30  [View("Item View")]
31  [Content(typeof(Item), false)]
32  [Content(typeof(IItem), false)]
33  public partial class ItemView : ContentView {
34    public new IItem Content {
35      get { return (IItem)base.Content; }
36      set { base.Content = value; }
37    }
38
39    /// <summary>
40    /// Initializes a new instance of <see cref="ViewBase"/> with the caption "View".
41    /// </summary>
42    public ItemView() {
43      InitializeComponent();
44      Caption = "View";
45    }
46    public ItemView(IItem content)
47      : this() {
48      Content = content;
49    }
50
51    protected override void OnContentChanged() {
52      base.OnContentChanged();
53      if (Content == null) {
54        Caption = "View";
55      } else {
56        Caption = Content.ItemName;
57      }
58    }
59
60    /// <summary>
61    /// Asynchron call of GUI updating.
62    /// </summary>
63    /// <param name="method">The delegate to invoke.</param>
64    protected new void Invoke(Delegate method) {
65      // enforce context switch to improve GUI response time
66      System.Threading.Thread.Sleep(0);
67
68      // prevent blocking of worker thread in Invoke, if the control is disposed
69      IAsyncResult result = BeginInvoke(method);
70      while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }
71      if (!IsDisposed) EndInvoke(result);
72    }
73    /// <summary>
74    /// Asynchron call of GUI updating.
75    /// </summary>
76    /// <param name="method">The delegate to invoke.</param>
77    /// <param name="args">The invoke arguments.</param>
78    protected new void Invoke(Delegate method, params object[] args) {
79      // enforce context switch to improve GUI response time
80      System.Threading.Thread.Sleep(0);
81
82      // prevent blocking of worker thread in Invoke, if the control is disposed
83      IAsyncResult result = BeginInvoke(method, args);
84      while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }
85      if (!IsDisposed) EndInvoke(result);
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.