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 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.MainForm;
|
---|
26 |
|
---|
27 | namespace 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 | public LogView(ILog content)
|
---|
52 | : this() {
|
---|
53 | Content = content;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /// <summary>
|
---|
57 | /// Removes the event handlers from the underlying <see cref="IEngine"/>.
|
---|
58 | /// </summary>
|
---|
59 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
60 | protected override void DeregisterContentEvents() {
|
---|
61 | Content.Cleared -= new EventHandler(Content_Cleared);
|
---|
62 | Content.MessageAdded -= new EventHandler<EventArgs<string>>(Content_MessageAdded);
|
---|
63 | base.DeregisterContentEvents();
|
---|
64 | }
|
---|
65 |
|
---|
66 | /// <summary>
|
---|
67 | /// Adds event handlers to the underlying <see cref="IEngine"/>.
|
---|
68 | /// </summary>
|
---|
69 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
70 | protected override void RegisterContentEvents() {
|
---|
71 | base.RegisterContentEvents();
|
---|
72 | Content.Cleared += new EventHandler(Content_Cleared);
|
---|
73 | Content.MessageAdded += new EventHandler<EventArgs<string>>(Content_MessageAdded);
|
---|
74 | }
|
---|
75 |
|
---|
76 | /// <summary>
|
---|
77 | /// Updates all controls with the latest data of the model.
|
---|
78 | /// </summary>
|
---|
79 | /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
80 | protected override void OnContentChanged() {
|
---|
81 | base.OnContentChanged();
|
---|
82 | logTextBox.Clear();
|
---|
83 | if (Content == null) {
|
---|
84 | logTextBox.Enabled = false;
|
---|
85 | } else {
|
---|
86 | logTextBox.Enabled = true;
|
---|
87 | if (Content.Messages.FirstOrDefault() != null)
|
---|
88 | logTextBox.Text = Content.Messages.Aggregate((x, y) => x + Environment.NewLine + y);
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | protected virtual void Content_MessageAdded(object sender, EventArgs<string> e) {
|
---|
93 | if (InvokeRequired)
|
---|
94 | Invoke(new EventHandler<EventArgs<string>>(Content_MessageAdded), sender, e);
|
---|
95 | else
|
---|
96 | logTextBox.Text = Content.Messages.Aggregate((x, y) => x + Environment.NewLine + y);
|
---|
97 | }
|
---|
98 |
|
---|
99 | protected virtual void Content_Cleared(object sender, EventArgs e) {
|
---|
100 | if (InvokeRequired)
|
---|
101 | Invoke(new EventHandler(Content_Cleared), sender, e);
|
---|
102 | else
|
---|
103 | logTextBox.Clear();
|
---|
104 | }
|
---|
105 |
|
---|
106 | protected virtual void clearButton_Click(object sender, EventArgs e) {
|
---|
107 | Content.Clear();
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|