Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/LogView.cs @ 3566

Last change on this file since 3566 was 3566, checked in by mkommend, 14 years ago

removed ctors with contents in all views (ticket #972)

File size: 3.8 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 System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.MainForm;
26
27namespace HeuristicLab.Core.Views {
28  /// <summary>
29  /// Base class for editors of engines.
30  /// </summary>
31  [View("Log View")]
32  [Content(typeof(Log), true)]
33  [Content(typeof(ILog), false)]
34  public partial class LogView : ItemView {
35    /// <summary>
36    /// Gets or sets the current engine.
37    /// </summary>
38    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>.</remarks>
39    public new ILog Content {
40      get { return (ILog)base.Content; }
41      set { base.Content = value; }
42    }
43
44    /// <summary>
45    /// Initializes a new instance of <see cref="EngineBaseEditor"/>.
46    /// </summary>
47    public LogView() {
48      InitializeComponent();
49      Caption = "LogView";
50    }
51
52    /// <summary>
53    /// Removes the event handlers from the underlying <see cref="IEngine"/>.
54    /// </summary>
55    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
56    protected override void DeregisterContentEvents() {
57      Content.Cleared -= new EventHandler(Content_Cleared);
58      Content.MessageAdded -= new EventHandler<EventArgs<string>>(Content_MessageAdded);
59      base.DeregisterContentEvents();
60    }
61
62    /// <summary>
63    /// Adds event handlers to the underlying <see cref="IEngine"/>.
64    /// </summary>
65    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
66    protected override void RegisterContentEvents() {
67      base.RegisterContentEvents();
68      Content.Cleared += new EventHandler(Content_Cleared);
69      Content.MessageAdded += new EventHandler<EventArgs<string>>(Content_MessageAdded);
70    }
71
72    /// <summary>
73    /// Updates all controls with the latest data of the model.
74    /// </summary>
75    /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
76    protected override void OnContentChanged() {
77      base.OnContentChanged();
78      logTextBox.Clear();
79      if (Content == null) {
80        logTextBox.Enabled = false;
81      } else {
82        logTextBox.Enabled = true;
83        if (Content.Messages.FirstOrDefault() != null)
84          logTextBox.Text = Content.Messages.Aggregate((x, y) => x + Environment.NewLine + y);
85      }
86    }
87
88    protected virtual void Content_MessageAdded(object sender, EventArgs<string> e) {
89      if (InvokeRequired)
90        Invoke(new EventHandler<EventArgs<string>>(Content_MessageAdded), sender, e);
91      else
92        logTextBox.Text = Content.Messages.Aggregate((x, y) => x + Environment.NewLine + y);
93    }
94
95    protected virtual void Content_Cleared(object sender, EventArgs e) {
96      if (InvokeRequired)
97        Invoke(new EventHandler(Content_Cleared), sender, e);
98      else
99        logTextBox.Clear();
100    }
101
102    protected virtual void clearButton_Click(object sender, EventArgs e) {
103      Content.Clear();
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.