Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/04/09 16:52:49 (15 years ago)
Author:
mkommend
Message:

implemented first version of MainFormBase and DockingMainForm (ticket #716)

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm/3.2/ViewBase.cs

    r2229 r2233  
    2929using System.Windows.Forms;
    3030
    31 namespace HeuristicLab.Core {
    32   /// <summary>
    33   /// Base class for all visual representations.
    34   /// </summary>
    35   public partial class ViewBase : UserControl, IView {
    36     private IItem myItem;
    37     /// <summary>
    38     /// Gets or sets the item to represent visually.
    39     /// </summary>
    40     /// <remarks>Calls <see cref="OnItemChanged"/>, <see cref="Refresh"/>,
    41     /// <see cref="RemoveItemEvents"/> (if the current item is not null) and
    42     /// <see cref="AddItemEvents"/> (if the new item is not null) in the setter.</remarks>
    43     public IItem Item {
    44       get { return myItem; }
    45       protected set {
    46         if (value != myItem) {
    47           if (myItem != null)
    48             RemoveItemEvents();
    49           myItem = value;
    50           if (myItem != null)
    51             AddItemEvents();
    52           OnItemChanged();
    53           Refresh();
    54         }
    55       }
     31namespace HeuristicLab.MainForm {
     32  public partial class ViewBase : UserControl {
     33    public ViewBase() {
     34      InitializeComponent();
    5635    }
     36
     37    public ViewBase(IMainForm mainForm)
     38      : this() {
     39      this.mainForm = mainForm;
     40    }
     41
    5742    private string myCaption;
    58     /// <summary>
    59     /// Gets or sets the caption of the current instance.
    60     /// </summary>
    61     /// <remarks>Call <see cref="OnCaptionChanged"/> in the setter if a new item is set.</remarks>
    6243    public string Caption {
    6344      get { return myCaption; }
     
    7051    }
    7152
    72     /// <summary>
    73     /// Initializes a new instance of <see cref="ViewBase"/> with the caption "View".
    74     /// </summary>
    75     public ViewBase() {
    76       InitializeComponent();
    77       Caption = "View";
    78     }
    79 
    80     /// <summary>
    81     /// Removes the eventhandlers from the current instance.
    82     /// </summary>
    83     protected virtual void RemoveItemEvents() { }
    84     /// <summary>
    85     /// Adds eventhandlers to the current instance.
    86     /// </summary>
    87     protected virtual void AddItemEvents() { }
    88 
    89     /// <summary>
    90     /// Refreshes the current view.
    91     /// </summary>
    92     /// <remarks>Creates a new <see cref="MethodInvoker"/> if an invoke is required
    93     /// (see <see cref="Control.InvokeRequired"/>.<br/>
    94     /// Otherwise calls <see cref="UpdateControls"/> and <see cref="Control.Refresh"/> of base class
    95     /// <see cref="System.Windows.Forms.UserControl"/>.</remarks>
    96     public override void Refresh() {
    97       if (InvokeRequired) {
    98         Invoke(new MethodInvoker(Refresh));
    99       } else {
    100         UpdateControls();
    101         base.Refresh();
    102       }
    103     }
    104     /// <summary>
    105     /// Updates the controls with the latest values of the model.
    106     /// </summary>
    107     protected virtual void UpdateControls() {
    108       if (Item == null)
    109         Caption = "View";
    110       else
    111         Caption = "View (" + Item.GetType().Name + ")";
    112      
    113     }
    114 
    115     /// <summary>
    116     /// Occurs when the current item was changed.
    117     /// </summary>
    118     public event EventHandler ItemChanged;
    119     /// <summary>
    120     /// Fires a new <c>ItemChanged</c> event.
    121     /// </summary>
    122     protected virtual void OnItemChanged() {
    123       if (ItemChanged != null)
    124         ItemChanged(this, new EventArgs());
    125     }
    126     /// <summary>
    127     /// Occurs when the current caption was changed.
    128     /// </summary>
    12953    public event EventHandler CaptionChanged;
    130     /// <summary>
    131     /// Fires a new <c>CaptionChanged</c> event.
    132     /// </summary>
    13354    protected virtual void OnCaptionChanged() {
    13455      if (CaptionChanged != null)
     
    13657    }
    13758
    138     /// <summary>
    139     /// Asynchron call of GUI updating.
    140     /// </summary>
    141     /// <param name="method">The delegate to invoke.</param>
    142     protected new void Invoke(Delegate method) {
    143       // enforce context switch to improve GUI response time
    144       System.Threading.Thread.Sleep(0);
     59    private IMainForm mainForm;
     60    public IMainForm MainForm {
     61      get { return this.mainForm; }
     62      set { this.mainForm = value; }
     63    }
    14564
    146       // prevent blocking of worker thread in Invoke, if the control is disposed
    147       IAsyncResult result = BeginInvoke(method);
    148       while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }
    149       if (!IsDisposed) EndInvoke(result);
    150     }
    151     /// <summary>
    152     /// Asynchron call of GUI updating.
    153     /// </summary>
    154     /// <param name="method">The delegate to invoke.</param>
    155     /// <param name="args">The invoke arguments.</param>
    156     protected new void Invoke(Delegate method, params object[] args) {
    157       // enforce context switch to improve GUI response time
    158       System.Threading.Thread.Sleep(0);
    159 
    160       // prevent blocking of worker thread in Invoke, if the control is disposed
    161       IAsyncResult result = BeginInvoke(method, args);
    162       while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }
    163       if (!IsDisposed) EndInvoke(result);
    164     }
    16565  }
    16666}
Note: See TracChangeset for help on using the changeset viewer.