Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Logging/3.2/LogView.cs @ 1530

Last change on this file since 1530 was 1530, checked in by gkronber, 15 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 5.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31
32namespace HeuristicLab.Logging {
33  /// <summary>
34  /// Visual representation of the <see cref="Log"/> class.
35  /// </summary>
36  public partial class LogView : ViewBase {
37    /// <summary>
38    /// Gets or sets the Log item to represent visually.
39    /// </summary>
40    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
41    /// No own data storage present.</remarks>
42    public Log Log {
43      get { return (Log)base.Item; }
44      set { base.Item = value; }
45    }
46
47    /// <summary>
48    /// Initializes a new instance of <see cref="LogView"/>.
49    /// </summary>
50    public LogView() {
51      InitializeComponent();
52      Caption = "Log View";
53    }
54    /// <summary>
55    /// Initializes a new instance of <see cref="LogView"/> with the given <paramref name="log"/>.
56    /// </summary>
57    /// <param name="log">The log object to represent visually.</param>
58    public LogView(Log log)
59      : this() {
60      Log = log;
61    }
62
63    /// <summary>
64    /// Removes the event handlers from the underlying <see cref="Log"/>.
65    /// </summary>
66    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
67    protected override void RemoveItemEvents() {
68      if (Log != null) {
69        Log.Items.ItemAdded -= new EventHandler<ItemIndexEventArgs>(Items_ItemAdded);
70        Log.Items.ItemRemoved -= new EventHandler<ItemIndexEventArgs>(Items_ItemRemoved);
71      }
72      base.RemoveItemEvents();
73    }
74    /// <summary>
75    /// Adds event handlers to the underlying <see cref="Log"/>.
76    /// </summary>
77    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
78    protected override void AddItemEvents() {
79      base.AddItemEvents();
80      if (Log != null) {
81        Log.Items.ItemAdded += new EventHandler<ItemIndexEventArgs>(Items_ItemAdded);
82        Log.Items.ItemRemoved += new EventHandler<ItemIndexEventArgs>(Items_ItemRemoved);
83      }
84    }
85
86    /// <summary>
87    /// Updates all controls with the latest data of the model.
88    /// </summary>
89    /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class
90    /// <see cref="UpdateControls"/>.</remarks>
91    protected override void UpdateControls() {
92      base.UpdateControls();
93      qualityLogTextBox.Clear();
94      if (Log == null) {
95        qualityLogTextBox.Enabled = false;
96      } else {
97        string[] lines = new string[Log.Items.Count];
98        for (int i = 0; i < Log.Items.Count; i++) {
99          lines[i] = Log.Items[i].ToString().Replace(';','\t');
100        }
101        qualityLogTextBox.Lines = lines;
102        qualityLogTextBox.Enabled = true;
103      }
104    }
105
106    #region ItemList Events
107    private delegate void IndexDelegate(int index);
108    private void Items_ItemRemoved(object sender, ItemIndexEventArgs e) {
109      RemoveItem(e.Index);
110    }
111    private void RemoveItem(int index) {
112      if (InvokeRequired)
113        Invoke(new IndexDelegate(RemoveItem), index);
114      else {
115        string[] lines = new string[qualityLogTextBox.Lines.Length - 1];
116        Array.Copy(qualityLogTextBox.Lines, 0, lines, 0, index);
117        Array.Copy(qualityLogTextBox.Lines, index + 1, lines, index, lines.Length - index);
118        qualityLogTextBox.Lines = lines;
119      }
120    }
121    private void Items_ItemAdded(object sender, ItemIndexEventArgs e) {
122      AddItem(e.Index);
123    }
124    private void AddItem(int index) {
125      if (InvokeRequired)
126        Invoke(new IndexDelegate(AddItem), index);
127      else {
128        string[] lines = new string[qualityLogTextBox.Lines.Length + 1];
129        Array.Copy(qualityLogTextBox.Lines, 0, lines, 0, index);
130        Array.Copy(qualityLogTextBox.Lines, index, lines, index + 1, qualityLogTextBox.Lines.Length - index);
131        lines[index] = Log.Items[index].ToString().Replace(';', '\t');
132        qualityLogTextBox.Lines = lines;
133      }
134    }
135    #endregion
136  }
137}
Note: See TracBrowser for help on using the repository browser.