[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[2790] | 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2] | 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;
|
---|
[2727] | 23 | using HeuristicLab.MainForm;
|
---|
[2546] | 24 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[2] | 25 |
|
---|
[2520] | 26 | namespace HeuristicLab.Core.Views {
|
---|
[776] | 27 | /// <summary>
|
---|
| 28 | /// Base class for all visual representations.
|
---|
| 29 | /// </summary>
|
---|
[2917] | 30 | [View("Item View")]
|
---|
[2727] | 31 | [Content(typeof(Item), false)]
|
---|
| 32 | [Content(typeof(IItem), false)]
|
---|
[2713] | 33 | public partial class ItemView : ContentView {
|
---|
| 34 | public new IItem Content {
|
---|
| 35 | get { return (IItem)base.Content; }
|
---|
| 36 | set { base.Content = value; }
|
---|
[2] | 37 | }
|
---|
| 38 |
|
---|
[776] | 39 | /// <summary>
|
---|
| 40 | /// Initializes a new instance of <see cref="ViewBase"/> with the caption "View".
|
---|
| 41 | /// </summary>
|
---|
[2664] | 42 | public ItemView() {
|
---|
[2] | 43 | InitializeComponent();
|
---|
| 44 | Caption = "View";
|
---|
| 45 | }
|
---|
[2727] | 46 | public ItemView(IItem content)
|
---|
| 47 | : this() {
|
---|
| 48 | Content = content;
|
---|
| 49 | }
|
---|
[2] | 50 |
|
---|
[2713] | 51 | protected override void OnContentChanged() {
|
---|
| 52 | base.OnContentChanged();
|
---|
| 53 | if (Content == null) {
|
---|
[2655] | 54 | Caption = "View";
|
---|
[2] | 55 | } else {
|
---|
[2713] | 56 | Caption = Content.ItemName;
|
---|
[2] | 57 | }
|
---|
| 58 | }
|
---|
[2713] | 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 | }
|
---|
[2] | 87 | }
|
---|
| 88 | }
|
---|