#region License Information
/* HeuristicLab
* Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
namespace HeuristicLab.Core.Views {
///
/// Base class for all visual representations.
///
[View("Item View")]
[Content(typeof(Item), false)]
[Content(typeof(IItem), false)]
public partial class ItemView : ContentView {
public new IItem Content {
get { return (IItem)base.Content; }
set { base.Content = value; }
}
///
/// Initializes a new instance of with the caption "View".
///
public ItemView() {
InitializeComponent();
Caption = "View";
}
public ItemView(IItem content)
: this() {
Content = content;
}
protected override void OnContentChanged() {
base.OnContentChanged();
if (Content == null) {
Caption = "View";
} else {
Caption = Content.ItemName;
}
}
///
/// Asynchron call of GUI updating.
///
/// The delegate to invoke.
protected new void Invoke(Delegate method) {
// enforce context switch to improve GUI response time
System.Threading.Thread.Sleep(0);
// prevent blocking of worker thread in Invoke, if the control is disposed
IAsyncResult result = BeginInvoke(method);
while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }
if (!IsDisposed) EndInvoke(result);
}
///
/// Asynchron call of GUI updating.
///
/// The delegate to invoke.
/// The invoke arguments.
protected new void Invoke(Delegate method, params object[] args) {
// enforce context switch to improve GUI response time
System.Threading.Thread.Sleep(0);
// prevent blocking of worker thread in Invoke, if the control is disposed
IAsyncResult result = BeginInvoke(method, args);
while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }
if (!IsDisposed) EndInvoke(result);
}
}
}