#region License Information
/* HeuristicLab
* Copyright (C) 2002-2014 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 System.Linq;
using HeuristicLab.Common;
using HeuristicLab.MainForm;
namespace HeuristicLab.Core.Views {
///
/// Base class for editors of engines.
///
[View("Log View")]
[Content(typeof(Log), true)]
[Content(typeof(ILog), false)]
public partial class LogView : ItemView {
///
/// Gets or sets the current engine.
///
/// Uses property of base class .
public new ILog Content {
get { return (ILog)base.Content; }
set { base.Content = value; }
}
///
/// Initializes a new instance of .
///
public LogView() {
InitializeComponent();
}
///
/// Removes the event handlers from the underlying .
///
/// Calls of base class .
protected override void DeregisterContentEvents() {
Content.Cleared -= new EventHandler(Content_Cleared);
Content.MessageAdded -= new EventHandler>(Content_MessageAdded);
base.DeregisterContentEvents();
}
///
/// Adds event handlers to the underlying .
///
/// Calls of base class .
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.Cleared += new EventHandler(Content_Cleared);
Content.MessageAdded += new EventHandler>(Content_MessageAdded);
}
///
/// Updates all controls with the latest data of the model.
///
/// Calls of base class .
protected override void OnContentChanged() {
base.OnContentChanged();
logTextBox.Clear();
if (Content == null) {
logTextBox.Enabled = false;
} else {
logTextBox.Enabled = true;
if (Content.Messages.FirstOrDefault() != null)
logTextBox.Text = string.Join(Environment.NewLine, Content.Messages.ToArray());
}
}
protected virtual void Content_MessageAdded(object sender, EventArgs e) {
if (InvokeRequired)
Invoke(new EventHandler>(Content_MessageAdded), sender, e);
else {
logTextBox.Text = string.Join(Environment.NewLine, Content.Messages.ToArray());
logTextBox.SelectionStart = logTextBox.Text.Length;
logTextBox.ScrollToCaret();
}
}
protected virtual void Content_Cleared(object sender, EventArgs e) {
if (InvokeRequired)
Invoke(new EventHandler(Content_Cleared), sender, e);
else
logTextBox.Clear();
}
protected virtual void clearButton_Click(object sender, EventArgs e) {
Content.Clear();
}
}
}