Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Core.Views/3.3/LogView.cs @ 11299

Last change on this file since 11299 was 11170, checked in by ascheibe, 10 years ago

#2115 updated copyright year in stable branch

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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    }
50
51    /// <summary>
52    /// Removes the event handlers from the underlying <see cref="IEngine"/>.
53    /// </summary>
54    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
55    protected override void DeregisterContentEvents() {
56      Content.Cleared -= new EventHandler(Content_Cleared);
57      Content.MessageAdded -= new EventHandler<EventArgs<string>>(Content_MessageAdded);
58      base.DeregisterContentEvents();
59    }
60
61    /// <summary>
62    /// Adds event handlers to the underlying <see cref="IEngine"/>.
63    /// </summary>
64    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
65    protected override void RegisterContentEvents() {
66      base.RegisterContentEvents();
67      Content.Cleared += new EventHandler(Content_Cleared);
68      Content.MessageAdded += new EventHandler<EventArgs<string>>(Content_MessageAdded);
69    }
70
71    /// <summary>
72    /// Updates all controls with the latest data of the model.
73    /// </summary>
74    /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
75    protected override void OnContentChanged() {
76      base.OnContentChanged();
77      logTextBox.Clear();
78      if (Content == null) {
79        logTextBox.Enabled = false;
80      } else {
81        logTextBox.Enabled = true;
82        if (Content.Messages.FirstOrDefault() != null)
83          logTextBox.Text = string.Join(Environment.NewLine, Content.Messages.ToArray());
84      }
85    }
86
87    protected virtual void Content_MessageAdded(object sender, EventArgs<string> e) {
88      if (InvokeRequired)
89        Invoke(new EventHandler<EventArgs<string>>(Content_MessageAdded), sender, e);
90      else {
91        logTextBox.Text = string.Join(Environment.NewLine, Content.Messages.ToArray());
92        logTextBox.SelectionStart = logTextBox.Text.Length;
93        logTextBox.ScrollToCaret();
94      }
95    }
96
97    protected virtual void Content_Cleared(object sender, EventArgs e) {
98      if (InvokeRequired)
99        Invoke(new EventHandler(Content_Cleared), sender, e);
100      else
101        logTextBox.Clear();
102    }
103
104    protected virtual void clearButton_Click(object sender, EventArgs e) {
105      Content.Clear();
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.