[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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Data;
|
---|
| 26 | using System.Drawing;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
| 31 |
|
---|
| 32 | namespace 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 | }
|
---|