Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/OperatorGraphView.cs @ 2801

Last change on this file since 2801 was 2801, checked in by mkommend, 14 years ago

added first version of OperatorGraphVisualization (ticket #867)

File size: 5.9 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.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.PluginInfrastructure;
31using HeuristicLab.Common;
32using HeuristicLab.MainForm;
33using HeuristicLab.Collections;
34
35namespace HeuristicLab.Core.Views {
36  /// <summary>
37  /// The visual representation of an <see cref="OperatorGraph"/>.
38  /// </summary>
39  [Content(typeof(OperatorGraph), true)]
40  public partial class OperatorGraphView : ItemView {
41    /// <summary>
42    /// Gets or sets the operator graph to represent visually.
43    /// </summary>
44    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
45    /// No own data storage present.</remarks>
46    public new OperatorGraph Content {
47      get { return (OperatorGraph)base.Content; }
48      set { base.Content = value; }
49    }
50
51    /// <summary>
52    /// Initializes a new instance of <see cref="OperatorGraphView"/> with caption "Operator Graph".
53    /// </summary>
54    public OperatorGraphView() {
55      InitializeComponent();
56      Caption = "Operator Graph";
57      this.viewHost.ViewType = typeof(OperatorTreeView);
58    }
59    /// <summary>
60    /// Initializes a new instance of <see cref="OperatorGraphView"/>
61    /// with the given <paramref name="operatorGraph"/>.
62    /// </summary>
63    /// <remarks>Calls <see cref="OperatorGraphView()"/>.</remarks>
64    /// <param name="operatorGraph">The operator graph to represent visually.</param>
65    public OperatorGraphView(OperatorGraph content)
66      : this() {
67      Content = content;
68    }
69
70    /// <summary>
71    /// Removes the eventhandlers from the underlying <see cref="IOperatorGraph"/>.
72    /// </summary>
73    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
74    protected override void DeregisterContentEvents() {
75      Content.InitialOperatorChanged -= new EventHandler(Content_InitialOperatorChanged);
76      base.DeregisterContentEvents();
77    }
78
79    /// <summary>
80    /// Adds eventhandlers to the underlying <see cref="IOperatorGraph"/>.
81    /// </summary>
82    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
83    protected override void RegisterContentEvents() {
84      base.RegisterContentEvents();
85      Content.InitialOperatorChanged += new EventHandler(Content_InitialOperatorChanged);
86    }
87
88    /// <summary>
89    /// Updates all controls with the latest data of the model.
90    /// </summary>
91    /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class <see cref="ViewBase"/>.</remarks>
92    protected override void OnContentChanged() {
93      base.OnContentChanged();
94      Caption = "Operator Graph";
95      operatorsView.Content = null;
96      operatorsView.Enabled = false;
97      viewHost.Content = null;
98      viewHost.Enabled = false;
99
100      if (Content != null) {
101        Caption = Content.ItemName + " (" + Content.GetType().Name + ")";
102        operatorsView.Content = Content.Operators;
103        operatorsView.Enabled = true;
104        MarkInitialOperator();
105        viewHost.Content = Content.InitialOperator;
106        viewHost.Enabled = true;
107      }
108    }
109
110    protected virtual void MarkInitialOperator() {
111      foreach (ListViewItem item in operatorsView.ItemsListView.Items) {
112        if ((Content.InitialOperator != null) && (((IOperator)item.Tag) == Content.InitialOperator))
113          item.Font = new Font(operatorsView.ItemsListView.Font, FontStyle.Bold);
114        else
115          item.Font = operatorsView.ItemsListView.Font;
116      }
117    }
118
119    #region Context Menu Events
120    protected virtual void operatorsView_Load(object sender, EventArgs e) {
121      operatorsView.ItemsListView.ContextMenuStrip = operatorsContextMenuStrip;
122    }
123    protected virtual void operatorsContextMenuStrip_Opening(object sender, CancelEventArgs e) {
124      initialOperatorToolStripMenuItem.Enabled = false;
125      initialOperatorToolStripMenuItem.Checked = false;
126      if (operatorsView.ItemsListView.SelectedItems.Count == 1) {
127        IOperator op = (IOperator)operatorsView.ItemsListView.SelectedItems[0].Tag;
128        initialOperatorToolStripMenuItem.Enabled = true;
129        initialOperatorToolStripMenuItem.Tag = op;
130        if (op == Content.InitialOperator)
131          initialOperatorToolStripMenuItem.Checked = true;
132      }
133    }
134    protected virtual void initialOperatorToolStripMenuItem_Click(object sender, EventArgs e) {
135      if (initialOperatorToolStripMenuItem.Checked)
136        Content.InitialOperator = (IOperator)initialOperatorToolStripMenuItem.Tag;
137      else
138        Content.InitialOperator = null;
139    }
140    #endregion
141
142    #region Content Events
143    protected virtual void Content_InitialOperatorChanged(object sender, EventArgs e) {
144      if (InvokeRequired)
145        Invoke(new EventHandler(Content_InitialOperatorChanged), sender, e);
146      else {
147        MarkInitialOperator();
148        viewHost.Content = Content.InitialOperator;
149      }
150    }
151    #endregion
152  }
153}
Note: See TracBrowser for help on using the repository browser.