Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Logging/LogView.cs @ 831

Last change on this file since 831 was 283, checked in by gkronber, 17 years ago
  • added a more generic logging operator that allows to specify which variable to read from the sub-scopes and log.
  • changed LogView to display entries by calling .ToString() instead of the hard-coded cast to DoubleArrayData.
File size: 3.7 KB
RevLine 
[2]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  public partial class LogView : ViewBase {
34    public Log Log {
35      get { return (Log)base.Item; }
36      set { base.Item = value; }
37    }
38
39    public LogView() {
40      InitializeComponent();
41      Caption = "Log View";
42    }
43    public LogView(Log log)
44      : this() {
45      Log = log;
46    }
47
48    protected override void RemoveItemEvents() {
49      if (Log != null) {
50        Log.Items.ItemAdded -= new EventHandler<ItemIndexEventArgs>(Items_ItemAdded);
51        Log.Items.ItemRemoved -= new EventHandler<ItemIndexEventArgs>(Items_ItemRemoved);
52      }
53      base.RemoveItemEvents();
54    }
55    protected override void AddItemEvents() {
56      base.AddItemEvents();
57      if (Log != null) {
58        Log.Items.ItemAdded += new EventHandler<ItemIndexEventArgs>(Items_ItemAdded);
59        Log.Items.ItemRemoved += new EventHandler<ItemIndexEventArgs>(Items_ItemRemoved);
60      }
61    }
62
63    protected override void UpdateControls() {
64      base.UpdateControls();
65      qualityLogTextBox.Clear();
66      if (Log == null) {
67        qualityLogTextBox.Enabled = false;
68      } else {
69        string[] lines = new string[Log.Items.Count];
70        for (int i = 0; i < Log.Items.Count; i++) {
[283]71          lines[i] = Log.Items[i].ToString().Replace(';','\t');
[2]72        }
73        qualityLogTextBox.Lines = lines;
74        qualityLogTextBox.Enabled = true;
75      }
76    }
77
78    #region ItemList Events
79    private delegate void IndexDelegate(int index);
80    private void Items_ItemRemoved(object sender, ItemIndexEventArgs e) {
81      RemoveItem(e.Index);
82    }
83    private void RemoveItem(int index) {
84      if (InvokeRequired)
85        Invoke(new IndexDelegate(RemoveItem), index);
86      else {
87        string[] lines = new string[qualityLogTextBox.Lines.Length - 1];
88        Array.Copy(qualityLogTextBox.Lines, 0, lines, 0, index);
89        Array.Copy(qualityLogTextBox.Lines, index + 1, lines, index, lines.Length - index);
90        qualityLogTextBox.Lines = lines;
91      }
92    }
93    private void Items_ItemAdded(object sender, ItemIndexEventArgs e) {
94      AddItem(e.Index);
95    }
96    private void AddItem(int index) {
97      if (InvokeRequired)
98        Invoke(new IndexDelegate(AddItem), index);
99      else {
100        string[] lines = new string[qualityLogTextBox.Lines.Length + 1];
101        Array.Copy(qualityLogTextBox.Lines, 0, lines, 0, index);
102        Array.Copy(qualityLogTextBox.Lines, index, lines, index + 1, qualityLogTextBox.Lines.Length - index);
[283]103        lines[index] = Log.Items[index].ToString().Replace(';', '\t');
[2]104        qualityLogTextBox.Lines = lines;
105      }
106    }
107    #endregion
108  }
109}
Note: See TracBrowser for help on using the repository browser.