Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2727 was 2727, checked in by swagner, 14 years ago

Operator architecture refactoring (#95)

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