Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 51 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 4.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  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++) {
71          double[] values = ((DoubleArrayData)Log.Items[i]).Data;
72          lines[i] = values[0].ToString() + "     " +
73                     values[1].ToString() + "     " +
74                     values[2].ToString();
75        }
76        qualityLogTextBox.Lines = lines;
77        qualityLogTextBox.Enabled = true;
78      }
79    }
80
81    #region ItemList Events
82    private delegate void IndexDelegate(int index);
83    private void Items_ItemRemoved(object sender, ItemIndexEventArgs e) {
84      RemoveItem(e.Index);
85    }
86    private void RemoveItem(int index) {
87      if (InvokeRequired)
88        Invoke(new IndexDelegate(RemoveItem), index);
89      else {
90        string[] lines = new string[qualityLogTextBox.Lines.Length - 1];
91        Array.Copy(qualityLogTextBox.Lines, 0, lines, 0, index);
92        Array.Copy(qualityLogTextBox.Lines, index + 1, lines, index, lines.Length - index);
93        qualityLogTextBox.Lines = lines;
94      }
95    }
96    private void Items_ItemAdded(object sender, ItemIndexEventArgs e) {
97      AddItem(e.Index);
98    }
99    private void AddItem(int index) {
100      if (InvokeRequired)
101        Invoke(new IndexDelegate(AddItem), index);
102      else {
103        string[] lines = new string[qualityLogTextBox.Lines.Length + 1];
104        Array.Copy(qualityLogTextBox.Lines, 0, lines, 0, index);
105        Array.Copy(qualityLogTextBox.Lines, index, lines, index + 1, qualityLogTextBox.Lines.Length - index);
106        double[] values = ((DoubleArrayData)Log.Items[index]).Data;
107        lines[index] = values[0].ToString() + "     " +
108                       values[1].ToString() + "     " +
109                       values[2].ToString();
110        qualityLogTextBox.Lines = lines;
111      }
112    }
113    #endregion
114  }
115}
Note: See TracBrowser for help on using the repository browser.