Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2754 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
RevLine 
[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
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;
[2474]30using HeuristicLab.Common;
[2520]31using HeuristicLab.MainForm;
[2655]32using HeuristicLab.Collections;
[2]33
[2520]34namespace HeuristicLab.Core.Views {
[776]35  /// <summary>
[2655]36  /// The visual representation of an <see cref="OperatorGraph"/>.
[776]37  /// </summary>
[2520]38  [Content(typeof(OperatorGraph), true)]
[2664]39  public partial class OperatorGraphView : ItemView {
[776]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>
[2713]45    public new OperatorGraph Content {
46      get { return (OperatorGraph)base.Content; }
47      set { base.Content = value; }
[2]48    }
49
[776]50    /// <summary>
51    /// Initializes a new instance of <see cref="OperatorGraphView"/> with caption "Operator Graph".
52    /// </summary>
[2]53    public OperatorGraphView() {
54      InitializeComponent();
55      Caption = "Operator Graph";
56    }
[776]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>
[2727]63    public OperatorGraphView(OperatorGraph content)
[2]64      : this() {
[2727]65      Content = content;
[2]66    }
67
[776]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>
[2713]72    protected override void DeregisterContentEvents() {
73      Content.InitialOperatorChanged -= new EventHandler(Content_InitialOperatorChanged);
74      base.DeregisterContentEvents();
[2]75    }
[2655]76
[776]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>
[2713]81    protected override void RegisterContentEvents() {
82      base.RegisterContentEvents();
83      Content.InitialOperatorChanged += new EventHandler(Content_InitialOperatorChanged);
[2]84    }
85
[776]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>
[2713]90    protected override void OnContentChanged() {
91      base.OnContentChanged();
92      operatorsView.Content = null;
[2655]93      operatorsView.Enabled = false;
[2713]94      graphView.Content = null;
[2655]95      graphView.Enabled = false;
[2713]96      if (Content == null) {
[2]97        Caption = "Operator Graph";
[2713]98        operatorsView.Content = null;
[2655]99        operatorsView.Enabled = false;
[2713]100        graphView.Content = null;
[2655]101        graphView.Enabled = false;
[2]102      } else {
[2713]103        Caption = Content.ItemName + " (" + Content.GetType().Name + ")";
104        operatorsView.Content = Content.Operators;
[2655]105        operatorsView.Enabled = true;
106        MarkInitialOperator();
[2713]107        graphView.Content = Content.InitialOperator;
[2655]108        graphView.Enabled = true;
[2]109      }
110    }
111
[2676]112    protected virtual void MarkInitialOperator() {
[2655]113      foreach (ListViewItem item in operatorsView.ItemsListView.Items) {
[2713]114        if ((Content.InitialOperator != null) && (((IOperator)item.Tag) == Content.InitialOperator))
[2655]115          item.Font = new Font(operatorsView.ItemsListView.Font, FontStyle.Bold);
116        else
117          item.Font = operatorsView.ItemsListView.Font;
[2]118      }
119    }
120
121    #region Context Menu Events
[2676]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) {
[2]126      initialOperatorToolStripMenuItem.Enabled = false;
127      initialOperatorToolStripMenuItem.Checked = false;
[2655]128      if (operatorsView.ItemsListView.SelectedItems.Count == 1) {
129        IOperator op = (IOperator)operatorsView.ItemsListView.SelectedItems[0].Tag;
[2]130        initialOperatorToolStripMenuItem.Enabled = true;
131        initialOperatorToolStripMenuItem.Tag = op;
[2713]132        if (op == Content.InitialOperator)
[2]133          initialOperatorToolStripMenuItem.Checked = true;
134      }
135    }
[2676]136    protected virtual void initialOperatorToolStripMenuItem_Click(object sender, EventArgs e) {
[2655]137      if (initialOperatorToolStripMenuItem.Checked)
[2713]138        Content.InitialOperator = (IOperator)initialOperatorToolStripMenuItem.Tag;
[2655]139      else
[2713]140        Content.InitialOperator = null;
[2]141    }
142    #endregion
143
[2713]144    #region Content Events
145    protected virtual void Content_InitialOperatorChanged(object sender, EventArgs e) {
[2655]146      if (InvokeRequired)
[2713]147        Invoke(new EventHandler(Content_InitialOperatorChanged), sender, e);
[2655]148      else {
149        MarkInitialOperator();
[2713]150        graphView.Content = Content.InitialOperator;
[2]151      }
152    }
153    #endregion
154  }
155}
Note: See TracBrowser for help on using the repository browser.