[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++) {
|
---|
[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 | }
|
---|