Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DebugEngine/3.3/OperatorTraceView.cs @ 5146

Last change on this file since 5146 was 5146, checked in by epitzer, 13 years ago

(#47)

  • Show a different icon for breakpoints
  • Show an icon for the active operation
File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Drawing;
24using System.Windows.Forms;
25using HeuristicLab.Collections;
26using HeuristicLab.Common.Resources;
27using HeuristicLab.Core;
28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
30using HeuristicLab.Operators;
31
32namespace HeuristicLab.DebugEngine {
33
34  [View("Operator Trace View")]
35  [Content(typeof(OperatorTrace), IsDefaultView = true)]
36  public partial class OperatorTraceView : AsynchronousContentView {
37
38    public new OperatorTrace Content {
39      get { return (OperatorTrace)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public OperatorTraceView() {
44      InitializeComponent();
45    }
46
47    protected override void DeregisterContentEvents() {
48      Content.CollectionReset -= Content_CollectionChanged;
49      Content.ItemsAdded -= Content_CollectionChanged;
50      Content.ItemsMoved -= Content_CollectionChanged;
51      Content.ItemsRemoved -= Content_CollectionChanged;
52      Content.ItemsReplaced -= Content_CollectionChanged;
53      base.DeregisterContentEvents();
54    }
55
56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58      Content.CollectionReset += Content_CollectionChanged;
59      Content.ItemsAdded += Content_CollectionChanged;
60      Content.ItemsMoved += Content_CollectionChanged;
61      Content.ItemsRemoved += Content_CollectionChanged;
62      Content.ItemsReplaced += Content_CollectionChanged;
63    }
64
65    #region Event Handlers (Content)
66    void Content_CollectionChanged(object sender, CollectionItemsChangedEventArgs<Collections.IndexedItem<IOperator>> e) {
67      if (InvokeRequired)
68        Invoke(new EventHandler<CollectionItemsChangedEventArgs<IndexedItem<IOperator>>>(Content_CollectionChanged), sender, e);
69      else
70        UpdateOperatorTrace();
71    }
72    #endregion
73
74    private void UpdateOperatorTrace() {
75      listView.BeginUpdate();
76      listView.Items.Clear();
77      listView.SmallImageList.Images.Clear();
78      listView.SmallImageList.Images.Add(VS2008ImageLibrary.Method);
79      listView.SmallImageList.Images.Add(VS2008ImageLibrary.Module);
80      listView.SmallImageList.Images.Add(VS2008ImageLibrary.BreakpointActive);
81      foreach (var item in Content) {
82        var viewItem = listView.Items.Add(item.Name ?? item.ItemName);
83        viewItem.ToolTipText = string.Format("{0}{1}{1}{2}",
84          Utils.TypeName(item), Environment.NewLine,
85          Utils.Wrap(item.Description, 60));
86        viewItem.Tag = item;
87        if (item.Breakpoint) {
88          viewItem.ForeColor = Color.Red;
89          viewItem.ImageIndex = 2;
90        } else {
91          viewItem.ImageIndex = item is CombinedOperator ? 1 : 0;
92        }
93      }
94      if (listView.Items.Count > 0) {
95        for (int i = 0; i < listView.Columns.Count; i++)
96          listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
97      }
98      listView.EndUpdate();
99    }
100
101    protected override void OnContentChanged() {
102      base.OnContentChanged();
103      if (Content == null) {
104        listView.Items.Clear();
105      } else {
106        UpdateOperatorTrace();
107      }
108    }
109
110    protected override void SetEnabledStateOfControls() {
111      base.SetEnabledStateOfControls();
112      isEnabledCheckbox.Enabled = Content != null;
113    }
114
115    #region Event Handlers (child controls)
116    private void listView_ItemActivate(object sender, EventArgs e) {
117      if (listView.SelectedItems.Count > 0) {
118        IOperator op = listView.SelectedItems[0].Tag as IOperator;
119        if (op != null) {
120          MainFormManager.MainForm.ShowContent(op);
121        }
122      }
123    }
124    #endregion
125
126    private void isEnabledCheckbox_CheckedChanged(object sender, EventArgs e) {
127      Content.IsEnabled = isEnabledCheckbox.Checked;
128    }
129  }
130
131}
Note: See TracBrowser for help on using the repository browser.